========================PostgreSQL configuration========================Adjust pg_hba.conf------------------The connection to a PostgreSQL server can be established either through alocal Unix-domain socket or a TCP/IP socket. The :file:`pg_hba.conf` filedefines which users/groups are allowed to connect from which clients andhow they have to authenticate.The :file:`pg_hba.conf` file is mostly stored in the database cluster's datadirectory. The data directory is often :file:`/usr/local/pgsql/data` or:file:`/var/lib/pgsql/data.` On Debian GNU/Linux systems the:file:`pg_hba.conf` is located in :file:`/etc/postgresql/{VERSION}/{CLUSTER}`(for example: :file:`/etc/postgresql/9.1/main`).Some information about the :file:`pg_hba.conf` is available in the PostgreSQLWiki/`Client Authentication`_, even more detailed in the pg_hba.conf_documentation.For TCP/IP connections^^^^^^^^^^^^^^^^^^^^^^Add a line like the following to your :file:`pg_hba.conf` if you want toconnect via a TCP/IP connection to the PostgreSQL server.Make sure to adjust the CIDR address if PostgreSQL is running on adifferent system:..code-block:: text:emphasize-lines: 2 # IPv4 local connections: host mailsys +mailsys 127.0.0.1/32 md5For Unix-domain socket connections^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^If you want to use PostgreSQL's local Unix domain socket for databaseconnections add a line like the second one to your :file:`pg_hba.conf`:..code-block:: text:emphasize-lines: 2 # "local" is for Unix domain socket connections only local mailsys +mailsys md5 local all all ident sameuser..note::`ident sameuser` will not work, because `dovecot-auth` will be executed by the unprivileged user `doveauth` (see :ref:`System Preparation <doveauth>`), not by the `dovecot` user.Create database users and the database--------------------------------------You should create some database users for vmm, Dovecot and Postfix as wellas their group.Each of them will get different privileges granted.Finally create a new database.Create a database superuser, which will be able to create users and databases,if necessary. If you have sudo privileges run:..code-block::consoleuser@host:~$ sudosu-postgres[sudo] password for user:postgres@host:~$ createuser-s-d-r-E-e-P$USERNAMEIf you are root, omit the :command:`sudo` command. Just execute:command:`su - postgres` and create the database superuser.Start :command:`psql` as superuser and connect to the database `template1`:..code-block::consoleuser@host:~$ psqltemplate1Then create users, their group and the empty database:..code-block::postgresql-consoletemplate1=#CREATEROLEvmmLOGINENCRYPTEDPASSWORD'DB PASSWORD for vmm';template1=#CREATEROLEdovecotLOGINENCRYPTEDpassword'DB PASSWORD for Dovecot';template1=#CREATEROLEpostfixLOGINENCRYPTEDpassword'DB PASSWORD for Postfix';template1=#CREATEROLEmailsysWITHUSERpostfix,dovecot,vmm;template1=#CREATEDATABASEmailsysWITHOWNERvmmENCODING'UTF8';template1=#\qImport tables and functions---------------------------Now start :command:`psql` and connect as your `vmm` user to the database`mailsys`:..code-block::consoleuser@host:~$ psqlmailsysvmm-W-hlocalhostIn PostgreSQL's terminal-based front-end import the database layout/tablesand functions into your database.Dovecot v1.2.x/v2.0.x/v2.1.x^^^^^^^^^^^^^^^^^^^^^^^^^^^^..code-block::postgresql-consolemailsys=>\i/path/to/vmm-0.6.2/pgsql/create_tables-dovecot-1.2.x.pgsqlmailsys=>\qDovecot v1.0.x/v1.1.x^^^^^^^^^^^^^^^^^^^^^..code-block::postgresql-consolemailsys=>\i/path/to/vmm-0.6.2/pgsql/create_tables.pgsqlmailsys=>\qSet database permissions------------------------..include:: ../pgsql_set_permissionspermissions.rst..include:: ../ext_references.rst