]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Make pg_dump exclude unlogged table data on hot standby slaves
authorMagnus Hagander <magnus@hagander.net>
Fri, 25 Jan 2013 08:44:14 +0000 (09:44 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 25 Jan 2013 08:47:22 +0000 (09:47 +0100)
Noted by Joe Van Dyk

doc/src/sgml/ref/pg_dump.sgml
src/bin/pg_dump/pg_dump.c

index f6f33de7e7e0a41f64265ef376af19be8397704b..f5733b10c325c38d02e54024c0f43c0bbb35beff 100644 (file)
@@ -678,7 +678,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>
index d6e4220ad5a8594edc2936deec6d2a25f4627fc6..bef2b430fe7f50c75a453571703840bd2d8fa0f1 100644 (file)
@@ -652,6 +652,24 @@ main(int argc, char **argv)
        if (g_fout->remoteVersion < 90100)
                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.
         */