PostgreSQL hot_standby pg_dump on slave

backuppg-dumppostgresqlreplication

I have master-slave (hot_standby) pgsql configuration and I want to make backups from one of my slaves. I don't want PITR, just good old database dump.

I switched to postgres from MySQL. With MySQL replication I made backups from slave with these steps:

  1. stop slave;
  2. perform mysqldump
  3. start slave

Can I do something similar with postgres?


I tried pg_dump on slave, but it returned errors:

pg_dump: Dumping the contents of table "news_event" failed:   PQgetResult() failed.
pg_dump: Error message from server: ERROR:  canceling statement due to conflict with recovery
DETAIL:  User query might have needed to see row versions that must be removed.

Also, pg_dump works good on master so I can do backups on master server, but I prefer to make it on slave.

Best Answer

Just run pg_dump. The documentation says:

pg_dump is a utility for backing up a PostgreSQL database. It makes consistent backups even if the database is being used concurrently. pg_dump does not block other users accessing the database (readers or writers).

In turn, the state of the database that you see on the slave is also consistent. If there is a considerable delay in replication, the result may be slightly different than a dump from the master.