| | 1 | ---------------------------------- |
| | 2 | installing and setting up a new db |
| | 3 | ---------------------------------- |
| | 4 | You will need sudo on that machine. |
| | 5 | |
| | 6 | - install postgres: |
| | 7 | sudo yum install postgresql |
| | 8 | sudo yum install postgresql-server |
| | 9 | |
| | 10 | postgres tends to install its files under the username postgres. You should therefore create and use this user for the steps below. Specifically you need access to /var/run/postgresql/ |
| | 11 | |
| | 12 | - make a directory for posgres data: |
| | 13 | mkdir -p /usr/local/pgsql/data |
| | 14 | |
| | 15 | - Create a database cluster (file structure) |
| | 16 | initdb -D /usr/local/pgsql/data |
| | 17 | |
| | 18 | - Initialise the server (I think I only need to do the second of these things) |
| | 19 | postmaster -D /usr/local/pgsql/data >logfile 2>&1 & |
| | 20 | postgres -D /usr/local/pgsql/data & |
| | 21 | |
| | 22 | - create database: |
| | 23 | createdb <db_name> |
| | 24 | |
| | 25 | - To restart the server (after shutting down for example) |
| | 26 | su - postgres |
| | 27 | pg_ctl start -D /usr/local/pgsql/data |
| | 28 | ----------------------------------- |
| | 29 | |
| | 30 | Configuring |
| | 31 | |
| | 32 | The config files will be inside the database cluster directory you created above (so /usr/local/pgsql/data/ in the example). |
| | 33 | |
| | 34 | There are two main config files, both in the above dir. |
| | 35 | |
| | 36 | pg_hba.conf (the client authentication configuration file) |
| | 37 | postgresql.conf (all sorts of things) |
| | 38 | |
| | 39 | You need to explicity allow for external hosts to connect to the database: |
| | 40 | |
| | 41 | pg_hba.conf: |
| | 42 | # IPv4 local connections: |
| | 43 | host all all 192.171.161.1/24 trust |
| | 44 | |
| | 45 | postgresql.conf |
| | 46 | listen_addresses = '*' |
| | 47 | |
| | 48 | pg_ctl is a utility for monitoring and controlling a posgreSQL server |
| | 49 | Check server status: |
| | 50 | pg_ctl status -D /usr/local/pgsql/data |
| | 51 | pg_ctl: server is running (PID: 29763) |