-
Notifications
You must be signed in to change notification settings - Fork 10
PostgreSQL Master Configuration
-
CentOS 6:
sudo service postgresql-94 initdbCentOS 7:
sudo /usr/pgsql-9.4/bin/postgresql-94-setup initdb -
CentOS 6:
sudo service postgresql-94 startCentOS 7:
sudo systemctl start postgresql-94
The server is now running but before we can issue some SQL queries we need to change the pg_hba.conf file, which has the rules about how to accept connections. You can check here for the documentation about the file but for now you just have to change a single line. It's located on /var/lib/pgsql/9.4/data/pg_hba.conf.
- Find the line
host all all 127.0.0.1/32 identand replace ident with trust
Note: I use trust here to make it simpler to setup a test system, you should use a more secure option if security is a concern (i.e. production server)
-
On a terminal run
sudo service reload postgresql-94to reload the config file -
Run
pgsql -U postgres -h localhost -p 5432(check here for more information about the PostgreSQL client)
You can now issue SQL queries. Don't forget to end them with a ;. Exit with \q.
Open /var/lib/pgsql/9.4/data/postgresql.conf with a text editor then find and change the following lines:
wal_level = hot_standby-
max_wal_senders = 4(or however many slaves you plan to use) synchronous_standby_names = '*'wal_keep_segments = 100hot_standby = on
To allow replication from other machines open /var/lib/pgsql/9.4/data/pg_hba.conf add however many lines like these you need (one for each slave) :
host replication replicador 192.168.1.1/32 trust
Note: I use trust here to make it simpler to setup a test system, you should use a more secure option if security is a concern (i.e. production server)
Of course you'll need to change the IP address of each machine. You can also use the subnet mask to add a whole bunch of IP's with a single line, for example host replication replicador 192.168.1.1/24 trust includes all IP's that start with 192.168.1
Then open a terminal and run the following commands:
-
sudo su postgres -
psql -
create user replicador replication;(don't forget the semicolon) -
\du+(check if the user was indeed created) -
\qto quit psql -
exitto go back to your user -
sudo service postgresql-9.4 restart
And we're done with the Master server for now :)
- Home
- Overview
- Requirements
- Setup
- Summary and Quick Start
- Database (PostgreSQL) 1. PostgreSQL Installation 2. Configuring the Master 3. Configuring the Slaves 4. Testing Replication 5. Manual Failover
- Load Balancing (PgPool II) 1. PgPool II Installation 2. Configuration 3. Managing and Testing
- Automatic Failover 1. Setting it up 2. Testing
- Troubleshooting
- References
