pg_dump -j against a standby server returns a pretty bad error message when pointed at a standby node:
pg_dump: [archiver (db)] query failed: ERROR: cannot assign TransactionIds during recovery pg_dump: [archiver (db)] query was: SELECT pg_export_snapshot() That looks quite scary to the user, and also throws errors in the server log which monitoring tools or DBAs will react to. PFA a patch that changes this to: pg_dump: Synchronized snapshots are not supported on standby servers. Run with --no-synchronized-snapshots instead if you do not need synchronized snapshots. which is a message similar (the hint identical) the one you get if you point it at a version older than 9.2 which doesn't have sync snapshots. I think the cleanest way to do it is to just track if it's a standby in the AH struct as written. Comments? -- Magnus Hagander Me: http://www.hagander.net/ Work: http://www.redpill-linpro.com/
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h index 83f6029..f94caa3 100644 --- a/src/bin/pg_dump/pg_backup.h +++ b/src/bin/pg_dump/pg_backup.h @@ -173,6 +173,7 @@ typedef struct Archive int verbose; char *remoteVersionStr; /* server's version string */ int remoteVersion; /* same in numeric form */ + bool isStandby; /* is server a standby node */ int minRemoteVersion; /* allowable range */ int maxRemoteVersion; diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 35ce945..dc073a6 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -37,6 +37,7 @@ _check_database_version(ArchiveHandle *AH) { const char *remoteversion_str; int remoteversion; + PGresult *res; remoteversion_str = PQparameterStatus(AH->connection, "server_version"); remoteversion = PQserverVersion(AH->connection); @@ -56,6 +57,12 @@ _check_database_version(ArchiveHandle *AH) remoteversion_str, progname, PG_VERSION); exit_horribly(NULL, "aborting because of server version mismatch\n"); } + + /* Identify if this is a standby node */ + res = ExecuteSqlQuery((Archive *) AH, "SELECT pg_catalog.pg_is_in_recovery()", PGRES_TUPLES_OK); + + AH->public.isStandby = (strcmp(PQgetvalue(res, 0, 0), "t") == 0); + PQclear(res); } /* diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 1267afb..e0c64cf 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -651,19 +651,13 @@ main(int argc, char **argv) * 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) + if (fout->remoteVersion >= 90000 && fout->isStandby) { - 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. - */ - dopt.no_unlogged_table_data = true; - } - PQclear(res); + /* + * On hot standby slaves, never try to dump unlogged table data, since + * it will just throw an error. + */ + dopt.no_unlogged_table_data = true; } /* Select the appropriate subquery to convert user IDs to names */ @@ -1096,7 +1090,16 @@ setup_connection(Archive *AH, const char *dumpencoding, else if (AH->numWorkers > 1 && AH->remoteVersion >= 90200 && !dopt->no_synchronized_snapshots) + { + if (!dopt->no_synchronized_snapshots && AH->isStandby) + exit_horribly(NULL, + "Synchronized snapshots are not supported on standby servers.\n" + "Run with --no-synchronized-snapshots instead if you do not need\n" + "synchronized snapshots.\n"); + + AH->sync_snapshot_id = get_synchronized_snapshot(AH); + } } static void
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers