Make pg_dump exclude unlogged table data on hot standby slaves
authorMagnus Hagander <[email protected]>
Fri, 25 Jan 2013 08:44:14 +0000 (09:44 +0100)
committerMagnus Hagander <[email protected]>
Fri, 25 Jan 2013 08:46:07 +0000 (09:46 +0100)
Noted by Joe Van Dyk

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

index d936cf185dfc9fd53f615b95b9dfa1cd11ffd389..152edcbe6ed810966175089b1fa715ad36ced696 100644 (file)
@@ -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>
index 6295b5bf2cc77edc8e2c5fbff362cf633b46b6f0..9f1ef32b15867b5006b3f8132ab8a38fd1dfbc9a 100644 (file)
@@ -605,6 +605,24 @@ main(int argc, char **argv)
        if (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.
         */