From 3ab2f7889f6b20a1cd21c5609861e1af841060c0 Mon Sep 17 00:00:00 2001 From: Craig Ringer Date: Tue, 26 May 2015 10:24:20 +0800 Subject: [PATCH] Don't dump setval(...) for 'bdr' sequences BDR sequence state is stored in the BDR extension data. It is neither necessary nor - currently - supported to setval(...) a 'bdr' sequence. Attempting to do so in dumps meant we had to ignore errors on restore. Note that this fix isn't perfect. We CREATE SEQUENCE ... USING 'bdr', which will start sequence voting immediately unless --single-transaction is used. If pg_restore or a dump script executed by 'psql' concurrently creates extension data this may result in unique violations. The sequence should only be created after we've restored bdr.bdr_sequence_values but pg_dump doesn't offer a way for a sequence (which is considered schema) to depend on table data. This issue is not addressed in this commit, but will only arise if you are restoring a dump to an empty but active BDR system, rather then to a standalone node before promotion to a BDR master. (A possible workaround would be to CREATE the sequence as local, then ALTER SEQUENCE ... USING 'bdr' in dumpSequenceData, but this means that schema-only dumps will lose knowledge of the sequence access method.) --- src/bin/pg_dump/pg_dump.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 01154754e1..f4e7f06688 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -14473,13 +14473,31 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) { TableInfo *tbinfo = tdinfo->tdtable; PGresult *res; - char *last; + char *last, *amname; bool called; PQExpBuffer query = createPQExpBuffer(); /* Make sure we are in proper schema */ selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); + amname = find_sequence_seqam(fout, tbinfo->dobj.catId.oid); + + if (amname != NULL && strcmp(amname, "bdr") == 0) + { + /* + * BDR global sequences don't need the sequence data dumped. + * It's actually part of the BDR extension's catalogs and not + * easily separated. We don't support setval(...) on a bdr + * global sequence. + * + * There's no need to generate an empty archive entry so + * just return. + */ + free(amname); + destroyPQExpBuffer(query); + return; + } + appendPQExpBuffer(query, "SELECT last_value, is_called FROM %s", fmtId(tbinfo->dobj.name)); @@ -14516,6 +14534,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) PQclear(res); + free(amname); destroyPQExpBuffer(query); } -- 2.39.5