aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2013-01-25 09:44:14 +0100
committerMagnus Hagander <magnus@hagander.net>2013-01-25 09:46:54 +0100
commit65fc0ab5599c61cea92e1e2a5002b62e6b52f283 (patch)
tree1569ae76e428bd3fc0551746104f3b71e74e41b7
parentab2d907a25e8c59326dc4d4194578e95eeceae89 (diff)
downloadpostgresql-65fc0ab5599c61cea92e1e2a5002b62e6b52f283.tar.gz
postgresql-65fc0ab5599c61cea92e1e2a5002b62e6b52f283.zip
Make pg_dump exclude unlogged table data on hot standby slaves
Noted by Joe Van Dyk
-rw-r--r--doc/src/sgml/ref/pg_dump.sgml3
-rw-r--r--src/bin/pg_dump/pg_dump.c18
2 files changed, 20 insertions, 1 deletions
diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
index 0d26f15c98f..a275eae5c6a 100644
--- a/doc/src/sgml/ref/pg_dump.sgml
+++ b/doc/src/sgml/ref/pg_dump.sgml
@@ -713,7 +713,8 @@ PostgreSQL documentation
<para>
Do not dump the contents of unlogged tables. This option has no
effect on whether or not the table definitions (schema) are dumped;
- it only suppresses dumping the table data.
+ it only suppresses dumping the table data. Data in unlogged tables
+ is always excluded when dumping from a standby server.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index f432579449f..1fe9d75b15a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -604,6 +604,24 @@ main(int argc, char **argv)
no_security_labels = 1;
/*
+ * When running against 9.0 or later, check if we are in recovery mode,
+ * which means we are on a hot standby.
+ */
+ if (fout->remoteVersion >= 90000)
+ {
+ PGresult *res = ExecuteSqlQueryForSingleRow(fout, "SELECT pg_catalog.pg_is_in_recovery()");
+ if (strcmp(PQgetvalue(res, 0, 0), "t") == 0)
+ {
+ /*
+ * On hot standby slaves, never try to dump unlogged table data,
+ * since it will just throw an error.
+ */
+ no_unlogged_table_data = true;
+ }
+ PQclear(res);
+ }
+
+ /*
* Start transaction-snapshot mode transaction to dump consistent data.
*/
ExecuteSqlStatement(fout, "BEGIN");