Skip to content

PostgreSQL Testing Replication

Dave Allie edited this page Apr 13, 2016 · 4 revisions

Check if replication is working

You can easily check the replication status by running this command:

psql -U postgres -h 192.168.1.1 -p 5432 -x -c "select * from pg_stat_replication"

As usual, replace the IP for your Master server's IP (and port, if not default). The -x option simply makes psql's output more readable for this particular command. -c tells psql to run a single query and exit.

You should have one Slave in sync_state = sync and all others in sync_state = potential. This means that the Master server only confirms a write query to the client after replicating the change to the sync Slave, to make sure the database always has a backup ready. All other slaves are in asynchronous mode, they'll also get all the changes but the client doesn't have to wait for them.

You can also run psql -U postgres -h 192.168.1.1 -p 5432 -x -c "show transaction_read_only" for each machine. All the slaves should return on, the master returns off, since it can also execute write queries.

You can also try whatever SQL queries you like to make sure the data is indeed being replicated to all machines.

Clone this wiki locally