doc/book/admin/config.rst
changeset 11338 dde85a5d47fc
parent 10491 c67bcee93248
child 12352 1a0159426def
equal deleted inserted replaced
11337:60369010c49e 11338:dde85a5d47fc
     6 ==================================
     6 ==================================
     7 
     7 
     8 You can `configure the database`_ system of your choice:
     8 You can `configure the database`_ system of your choice:
     9 
     9 
    10   - `PostgreSQL configuration`_
    10   - `PostgreSQL configuration`_
    11   - `MySql configuration`_
       
    12   - `SQLServer configuration`_
    11   - `SQLServer configuration`_
    13   - `SQLite configuration`_
    12   - `SQLite configuration`_
    14 
    13 
    15 For advanced features, have a look to:
    14 For advanced features, have a look to:
    16 
    15 
    17   - `Cubicweb resources configuration`_
    16   - `Cubicweb resources configuration`_
    18 
    17 
    19 .. _`configure the database`: DatabaseInstallation_
    18 .. _`configure the database`: DatabaseInstallation_
    20 .. _`PostgreSQL configuration`: PostgresqlConfiguration_
    19 .. _`PostgreSQL configuration`: PostgresqlConfiguration_
    21 .. _`MySql configuration`: MySqlConfiguration_
       
    22 .. _`SQLServer configuration`: SQLServerConfiguration_
    20 .. _`SQLServer configuration`: SQLServerConfiguration_
    23 .. _`SQLite configuration`: SQLiteConfiguration_
    21 .. _`SQLite configuration`: SQLiteConfiguration_
    24 .. _`Cubicweb resources configuration`: RessourcesConfiguration_
    22 .. _`Cubicweb resources configuration`: RessourcesConfiguration_
    25 
    23 
    26 
    24 
    39 -----------------------
    37 -----------------------
    40 
    38 
    41 Each instance can be configured with its own database connection information,
    39 Each instance can be configured with its own database connection information,
    42 that will be stored in the instance's :file:`sources` file. The database to use
    40 that will be stored in the instance's :file:`sources` file. The database to use
    43 will be chosen when creating the instance. CubicWeb is known to run with
    41 will be chosen when creating the instance. CubicWeb is known to run with
    44 Postgresql (recommended), SQLServer and SQLite, and may run with MySQL.
    42 Postgresql (recommended), SQLServer and SQLite.
    45 
    43 
    46 Other possible sources of data include CubicWeb, Subversion, LDAP and Mercurial,
    44 Other possible sources of data include CubicWeb, Subversion, LDAP and Mercurial,
    47 but at least one relational database is required for CubicWeb to work. You do
    45 but at least one relational database is required for CubicWeb to work. You do
    48 not need to install a backend that you do not intend to use for one of your
    46 not need to install a backend that you do not intend to use for one of your
    49 instances. SQLite is not fit for production use, but it works well for testing
    47 instances. SQLite is not fit for production use, but it works well for testing
    87 
    85 
    88 To initialize a PostgreSQL cluster, use the command ``initdb``::
    86 To initialize a PostgreSQL cluster, use the command ``initdb``::
    89 
    87 
    90     $ initdb -E UTF8 -D /path/to/pgsql
    88     $ initdb -E UTF8 -D /path/to/pgsql
    91 
    89 
       
    90 Note: ``initdb`` might not be in the PATH, so you may have to use its
       
    91 absolute path instead (usually something like
       
    92 ``/usr/lib/postgresql/9.4/bin/initdb``).
       
    93 
    92 Notice the encoding specification. This is necessary since |cubicweb| usually
    94 Notice the encoding specification. This is necessary since |cubicweb| usually
    93 want UTF8 encoded database. If you use a cluster with the wrong encoding, you'll
    95 want UTF8 encoded database. If you use a cluster with the wrong encoding, you'll
    94 get error like::
    96 get error like::
    95 
    97 
    96   new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
    98   new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
   102 
   104 
   103 If you cannot execute this command due to permission issues, please make sure
   105 If you cannot execute this command due to permission issues, please make sure
   104 that your username has write access on the database.  ::
   106 that your username has write access on the database.  ::
   105 
   107 
   106   $ chown username /path/to/pgsql
   108   $ chown username /path/to/pgsql
       
   109 
   107 
   110 
   108 Database authentication
   111 Database authentication
   109 +++++++++++++++++++++++
   112 +++++++++++++++++++++++
   110 
   113 
   111 The database authentication is configured in `pg_hba.conf`. It can be either set
   114 The database authentication is configured in `pg_hba.conf`. It can be either set
   114 operating system user name has a matching user in the database. If not, please
   117 operating system user name has a matching user in the database. If not, please
   115 do as follow to create a user::
   118 do as follow to create a user::
   116 
   119 
   117   $ su
   120   $ su
   118   $ su - postgres
   121   $ su - postgres
   119   $ createuser -s -P username
   122   $ createuser -s -P <dbuser>
   120 
   123 
   121 The option `-P` (for password prompt), will encrypt the password with the
   124 The option `-P` (for password prompt), will encrypt the password with the
   122 method set in the configuration file :file:`pg_hba.conf`.  If you do not use this
   125 method set in the configuration file :file:`pg_hba.conf`.  If you do not use this
   123 option `-P`, then the default value will be null and you will need to set it
   126 option `-P`, then the default value will be null and you will need to set it
   124 with::
   127 with::
   125 
   128 
   126   $ su postgres -c "echo ALTER USER username WITH PASSWORD 'userpasswd' | psql"
   129   $ su postgres -c "echo ALTER USER <dbuser> WITH PASSWORD '<dbpassword>' | psql"
   127 
   130 
   128 The above login/password will be requested when you will create an instance with
   131 The above login/password will be requested when you will create an instance with
   129 `cubicweb-ctl create` to initialize the database of your instance.
   132 `cubicweb-ctl create` to initialize the database of your instance.
       
   133 
       
   134 
       
   135 Database creation
       
   136 +++++++++++++++++
       
   137 
       
   138 If you create the database by hand (instead of using the `cubicweb-ctl
       
   139 db-create` tool), you may want to make sure that the local settings are
       
   140 properly set. For example, if you need to handle french accents
       
   141 properly for indexing and sorting, you may need to create the database
       
   142 with something like::
       
   143 
       
   144   $ createdb --encoding=UTF-8 --locale=fr_FR.UTF-8 -t template0 -O <owner> <dbname>
   130 
   145 
   131 Notice that the `cubicweb-ctl db-create` does database initialization that
   146 Notice that the `cubicweb-ctl db-create` does database initialization that
   132 may requires a postgres superuser. That's why a login/password is explicitly asked
   147 may requires a postgres superuser. That's why a login/password is explicitly asked
   133 at this step, so you can use there a superuser without using this user when running
   148 at this step, so you can use there a superuser without using this user when running
   134 the instance. Things that require special privileges at this step:
   149 the instance. Things that require special privileges at this step:
   135 
   150 
   136 * database creation, require the 'create database' permission
   151 * database creation, require the 'create database' permission
   137 * install the plpython extension language (require superuser)
   152 * install the `plpython` extension language (require superuser)
   138 * install the tsearch extension for postgres version prior to 8.3 (require superuser)
       
   139 
   153 
   140 To avoid using a super user each time you create an install, a nice trick is to
   154 To avoid using a super user each time you create an install, a nice trick is to
   141 install plpython (and tsearch when needed) on the special `template1` database,
   155 install plpython (and tsearch when needed) on the special `template1` database,
   142 so they will be installed automatically when cubicweb databases are created
   156 so they will be installed automatically when cubicweb databases are created
   143 without even with needs for special access rights. To do so, run ::
   157 without needs for special access rights. To do so, run ::
   144 
   158 
   145   # Installation of plpythonu language by default ::
   159   # Installation of plpythonu language by default ::
   146   $ createlang -U pgadmin plpythonu template1
   160   $ createlang -U pgadmin plpythonu template1
   147   $ psql -U pgadmin template1
   161   $ psql -U pgadmin template1
   148   template1=# update pg_language set lanpltrusted=TRUE where lanname='plpythonu';
   162   template1=# update pg_language set lanpltrusted=TRUE where lanname='plpythonu';
   149 
   163 
   150 Where `pgadmin` is a postgres superuser. The last command is necessary since by
   164 Where `pgadmin` is a postgres superuser. The last command is necessary since by
   151 default plpython is an 'untrusted' language and as such can't be used by non
   165 default plpython is an 'untrusted' language and as such can't be used by non
   152 superuser. This update fix that problem by making it trusted.
   166 superuser. This update fix that problem by making it trusted.
   153 
       
   154 To install the tsearch plain-text index extension on postgres prior to 8.3, run::
       
   155 
       
   156     cat /usr/share/postgresql/8.X/contrib/tsearch2.sql | psql -U username template1
       
   157 
       
   158 
       
   159 .. _MySqlConfiguration:
       
   160 
       
   161 MySql
       
   162 ~~~~~
       
   163 .. warning::
       
   164     CubicWeb's MySQL support is not commonly used, so things may or may not work properly.
       
   165 
       
   166 You must add the following lines in ``/etc/mysql/my.cnf`` file::
       
   167 
       
   168     transaction-isolation=READ-COMMITTED
       
   169     default-storage-engine=INNODB
       
   170     default-character-set=utf8
       
   171     max_allowed_packet = 128M
       
   172 
       
   173 .. Note::
       
   174     It is unclear whether mysql supports indexed string of arbitrary length or
       
   175     not.
       
   176 
   167 
   177 
   168 
   178 .. _SQLServerConfiguration:
   169 .. _SQLServerConfiguration:
   179 
   170 
   180 SQLServer
   171 SQLServer
   224 anything for db-user and db-password, they will be ignore anyway.
   215 anything for db-user and db-password, they will be ignore anyway.
   225 
   216 
   226 .. Note::
   217 .. Note::
   227   SQLite is great for testing and to play with cubicweb but is not suited for
   218   SQLite is great for testing and to play with cubicweb but is not suited for
   228   production environments.
   219   production environments.
   229