Page 292 - Asterisk™: The Future of Telephony
P. 292

Then start the database, which will take a few seconds to initialize for the first time:
                   # service postgresql start
               Next, create a user called asterisk, which we will use to connect to and manage the
               database. Run the following commands:

                   # su - postgres
                   $ createuser -P
                   Enter name of user to add: asterisk
                   Enter password for new user:
                   Enter it again:
                   Shall the new role be a superuser? (y/n) n
                   Shall the new user be allowed to create databases? (y/n) y
                   Shall the new user be allowed to create more new users? (y/n) n
                   CREATE USER
               By default, PostgreSQL does not listen on the TCP/IP connection, which Asterisk will
               be using. We need to modify the /var/lib/pgsql/data/postgresql.conf file in order to allow
               Asterisk to make IP connections to the database. To do this, simply remove the com-
               ment from the beginning of the tcpip_socket and port parameters. Be sure to change
               the tcpip_socket option from false to true.

                   tcpip_socket = true max_connections = 100
                           # note: increasing max_connections costs about 500 bytes of shared
                           # memory per connection slot, in addition to costs from shared_buffers
                           # and max_locks_per_transaction.
                   #superuser_reserved_connections = 2
                   port = 5432
               Now, edit the /var/lib/pgsql/data/pg_hba.conf file in order to allow the asterisk user we
               just created to connect to the PostgreSQL server over the TCP/IP socket. At the end of
               the file, replace everything below # Put your actual configuration here with the fol-
               lowing:

                   host    all     asterisk        127.0.0.1       255.255.255.255         md5
                   local   all     asterisk                                                trust
               Now we can create the database that we will use throughout this chapter. We’re going
               to create a database called asterisk and set the owner to our asterisk user.
                   $ createdb --owner=asterisk asterisk
                   CREATE DATABASE
               Restart the PostgreSQL server after exiting from the postgres user back to root:
                   $ exit
                   # service postgresql restart
               We can verify our connection to the PostgreSQL server via TCP/IP like so:
                   # psql -h 127.0.0.1 -U asterisk Password:
                   Welcome to psql 7.4.16, the PostgreSQL interactive terminal.

                   Type:  \copyright for distribution terms
                          \h for help with SQL commands


               264 | Chapter 12: Relational Database Integration
   287   288   289   290   291   292   293   294   295   296   297