Commit a7e5457d authored by Peter Eisentraut's avatar Peter Eisentraut

pg_upgrade: Upgrade sequence data via pg_dump

Previously, pg_upgrade migrated sequence data like tables by copying the
on-disk file.  This does not allow any changes in the on-disk format for
sequences.  It's simpler to just have pg_dump set the new sequence
values as it normally does.  To do that, create a hidden submode in
pg_dump that dumps sequence data even when a schema-only dump is
requested, and trigger that submode in binary upgrade mode.  (This new
submode could easily be exposed as a command-line option, but it has
limited use outside of pg_dump and would probably cause some confusion,
so we don't do that at this time.)
Reviewed-by: default avatarAnastasia Lubennikova <a.lubennikova@postgrespro.ru>
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
parent 27d2c123
...@@ -118,6 +118,7 @@ typedef struct _restoreOptions ...@@ -118,6 +118,7 @@ typedef struct _restoreOptions
bool *idWanted; /* array showing which dump IDs to emit */ bool *idWanted; /* array showing which dump IDs to emit */
int enable_row_security; int enable_row_security;
int sequence_data; /* dump sequence data even in schema-only mode */
} RestoreOptions; } RestoreOptions;
typedef struct _dumpOptions typedef struct _dumpOptions
...@@ -160,6 +161,8 @@ typedef struct _dumpOptions ...@@ -160,6 +161,8 @@ typedef struct _dumpOptions
bool outputBlobs; bool outputBlobs;
int outputNoOwner; int outputNoOwner;
char *outputSuperuser; char *outputSuperuser;
int sequence_data; /* dump sequence data even in schema-only mode */
} DumpOptions; } DumpOptions;
/* /*
......
...@@ -171,6 +171,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt) ...@@ -171,6 +171,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
dopt->lockWaitTimeout = ropt->lockWaitTimeout; dopt->lockWaitTimeout = ropt->lockWaitTimeout;
dopt->include_everything = ropt->include_everything; dopt->include_everything = ropt->include_everything;
dopt->enable_row_security = ropt->enable_row_security; dopt->enable_row_security = ropt->enable_row_security;
dopt->sequence_data = ropt->sequence_data;
return dopt; return dopt;
} }
...@@ -2855,7 +2856,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt) ...@@ -2855,7 +2856,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
/* Mask it if we only want schema */ /* Mask it if we only want schema */
if (ropt->schemaOnly) if (ropt->schemaOnly)
res = res & REQ_SCHEMA; {
if (!(ropt->sequence_data && strcmp(te->desc, "SEQUENCE SET") == 0))
res = res & REQ_SCHEMA;
}
/* Mask it if we only want data */ /* Mask it if we only want data */
if (ropt->dataOnly) if (ropt->dataOnly)
......
...@@ -216,7 +216,7 @@ static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs, ...@@ -216,7 +216,7 @@ static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
DumpableObject *boundaryObjs); DumpableObject *boundaryObjs);
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo); static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo);
static void getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids); static void getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids, char relkind);
static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids); static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids);
static void buildMatViewRefreshDependencies(Archive *fout); static void buildMatViewRefreshDependencies(Archive *fout);
static void getTableDataFKConstraints(void); static void getTableDataFKConstraints(void);
...@@ -546,6 +546,12 @@ main(int argc, char **argv) ...@@ -546,6 +546,12 @@ main(int argc, char **argv)
if (dopt.column_inserts) if (dopt.column_inserts)
dopt.dump_inserts = 1; dopt.dump_inserts = 1;
/* Binary upgrade mode implies dumping sequence data even in schema-only
* mode. This is not exposed as a separate option, but kept separate
* internally for clarity. */
if (dopt.binary_upgrade)
dopt.sequence_data = 1;
if (dopt.dataOnly && dopt.schemaOnly) if (dopt.dataOnly && dopt.schemaOnly)
{ {
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n"); write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
...@@ -722,12 +728,15 @@ main(int argc, char **argv) ...@@ -722,12 +728,15 @@ main(int argc, char **argv)
if (!dopt.schemaOnly) if (!dopt.schemaOnly)
{ {
getTableData(&dopt, tblinfo, numTables, dopt.oids); getTableData(&dopt, tblinfo, numTables, dopt.oids, 0);
buildMatViewRefreshDependencies(fout); buildMatViewRefreshDependencies(fout);
if (dopt.dataOnly) if (dopt.dataOnly)
getTableDataFKConstraints(); getTableDataFKConstraints();
} }
if (dopt.schemaOnly && dopt.sequence_data)
getTableData(&dopt, tblinfo, numTables, dopt.oids, RELKIND_SEQUENCE);
if (dopt.outputBlobs) if (dopt.outputBlobs)
getBlobs(fout); getBlobs(fout);
...@@ -806,6 +815,7 @@ main(int argc, char **argv) ...@@ -806,6 +815,7 @@ main(int argc, char **argv)
ropt->lockWaitTimeout = dopt.lockWaitTimeout; ropt->lockWaitTimeout = dopt.lockWaitTimeout;
ropt->include_everything = dopt.include_everything; ropt->include_everything = dopt.include_everything;
ropt->enable_row_security = dopt.enable_row_security; ropt->enable_row_security = dopt.enable_row_security;
ropt->sequence_data = dopt.sequence_data;
if (compressLevel == -1) if (compressLevel == -1)
ropt->compression = 0; ropt->compression = 0;
...@@ -2039,13 +2049,14 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo) ...@@ -2039,13 +2049,14 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo)
* set up dumpable objects representing the contents of tables * set up dumpable objects representing the contents of tables
*/ */
static void static void
getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids) getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids, char relkind)
{ {
int i; int i;
for (i = 0; i < numTables; i++) for (i = 0; i < numTables; i++)
{ {
if (tblinfo[i].dobj.dump & DUMP_COMPONENT_DATA) if (tblinfo[i].dobj.dump & DUMP_COMPONENT_DATA &&
(!relkind || tblinfo[i].relkind == relkind))
makeTableDataInfo(dopt, &(tblinfo[i]), oids); makeTableDataInfo(dopt, &(tblinfo[i]), oids);
} }
} }
......
...@@ -444,7 +444,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo) ...@@ -444,7 +444,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
" SELECT c.oid, 0::oid, 0::oid " " SELECT c.oid, 0::oid, 0::oid "
" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n " " FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
" ON c.relnamespace = n.oid " " ON c.relnamespace = n.oid "
" WHERE relkind IN ('r', 'm', 'S') AND " " WHERE relkind IN ('r', 'm') AND "
/* exclude possible orphaned temp tables */ /* exclude possible orphaned temp tables */
" ((n.nspname !~ '^pg_temp_' AND " " ((n.nspname !~ '^pg_temp_' AND "
" n.nspname !~ '^pg_toast_temp_' AND " " n.nspname !~ '^pg_toast_temp_' AND "
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment