Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita7e5457

Browse files
committed
pg_upgrade: Upgrade sequence data via pg_dump
Previously, pg_upgrade migrated sequence data like tables by copying theon-disk file. This does not allow any changes in the on-disk format forsequences. It's simpler to just have pg_dump set the new sequencevalues as it normally does. To do that, create a hidden submode inpg_dump that dumps sequence data even when a schema-only dump isrequested, and trigger that submode in binary upgrade mode. (This newsubmode could easily be exposed as a command-line option, but it haslimited use outside of pg_dump and would probably cause some confusion,so we don't do that at this time.)Reviewed-by: Anastasia Lubennikova <a.lubennikova@postgrespro.ru>Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent27d2c12 commita7e5457

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

‎src/bin/pg_dump/pg_backup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ typedef struct _restoreOptions
118118

119119
bool*idWanted;/* array showing which dump IDs to emit */
120120
intenable_row_security;
121+
intsequence_data;/* dump sequence data even in schema-only mode */
121122
}RestoreOptions;
122123

123124
typedefstruct_dumpOptions
@@ -160,6 +161,8 @@ typedef struct _dumpOptions
160161
booloutputBlobs;
161162
intoutputNoOwner;
162163
char*outputSuperuser;
164+
165+
intsequence_data;/* dump sequence data even in schema-only mode */
163166
}DumpOptions;
164167

165168
/*

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
171171
dopt->lockWaitTimeout=ropt->lockWaitTimeout;
172172
dopt->include_everything=ropt->include_everything;
173173
dopt->enable_row_security=ropt->enable_row_security;
174+
dopt->sequence_data=ropt->sequence_data;
174175

175176
returndopt;
176177
}
@@ -2855,7 +2856,10 @@ _tocEntryRequired(TocEntry *te, teSection curSection, RestoreOptions *ropt)
28552856

28562857
/* Mask it if we only want schema */
28572858
if (ropt->schemaOnly)
2858-
res=res&REQ_SCHEMA;
2859+
{
2860+
if (!(ropt->sequence_data&&strcmp(te->desc,"SEQUENCE SET")==0))
2861+
res=res&REQ_SCHEMA;
2862+
}
28592863

28602864
/* Mask it if we only want data */
28612865
if (ropt->dataOnly)

‎src/bin/pg_dump/pg_dump.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
216216
DumpableObject*boundaryObjs);
217217

218218
staticvoidgetDomainConstraints(Archive*fout,TypeInfo*tyinfo);
219-
staticvoidgetTableData(DumpOptions*dopt,TableInfo*tblinfo,intnumTables,booloids);
219+
staticvoidgetTableData(DumpOptions*dopt,TableInfo*tblinfo,intnumTables,booloids,charrelkind);
220220
staticvoidmakeTableDataInfo(DumpOptions*dopt,TableInfo*tbinfo,booloids);
221221
staticvoidbuildMatViewRefreshDependencies(Archive*fout);
222222
staticvoidgetTableDataFKConstraints(void);
@@ -546,6 +546,12 @@ main(int argc, char **argv)
546546
if (dopt.column_inserts)
547547
dopt.dump_inserts=1;
548548

549+
/* Binary upgrade mode implies dumping sequence data even in schema-only
550+
* mode. This is not exposed as a separate option, but kept separate
551+
* internally for clarity. */
552+
if (dopt.binary_upgrade)
553+
dopt.sequence_data=1;
554+
549555
if (dopt.dataOnly&&dopt.schemaOnly)
550556
{
551557
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)
722728

723729
if (!dopt.schemaOnly)
724730
{
725-
getTableData(&dopt,tblinfo,numTables,dopt.oids);
731+
getTableData(&dopt,tblinfo,numTables,dopt.oids,0);
726732
buildMatViewRefreshDependencies(fout);
727733
if (dopt.dataOnly)
728734
getTableDataFKConstraints();
729735
}
730736

737+
if (dopt.schemaOnly&&dopt.sequence_data)
738+
getTableData(&dopt,tblinfo,numTables,dopt.oids,RELKIND_SEQUENCE);
739+
731740
if (dopt.outputBlobs)
732741
getBlobs(fout);
733742

@@ -806,6 +815,7 @@ main(int argc, char **argv)
806815
ropt->lockWaitTimeout=dopt.lockWaitTimeout;
807816
ropt->include_everything=dopt.include_everything;
808817
ropt->enable_row_security=dopt.enable_row_security;
818+
ropt->sequence_data=dopt.sequence_data;
809819

810820
if (compressLevel==-1)
811821
ropt->compression=0;
@@ -2039,13 +2049,14 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo)
20392049
* set up dumpable objects representing the contents of tables
20402050
*/
20412051
staticvoid
2042-
getTableData(DumpOptions*dopt,TableInfo*tblinfo,intnumTables,booloids)
2052+
getTableData(DumpOptions*dopt,TableInfo*tblinfo,intnumTables,booloids,charrelkind)
20432053
{
20442054
inti;
20452055

20462056
for (i=0;i<numTables;i++)
20472057
{
2048-
if (tblinfo[i].dobj.dump&DUMP_COMPONENT_DATA)
2058+
if (tblinfo[i].dobj.dump&DUMP_COMPONENT_DATA&&
2059+
(!relkind||tblinfo[i].relkind==relkind))
20492060
makeTableDataInfo(dopt,&(tblinfo[i]),oids);
20502061
}
20512062
}

‎src/bin/pg_upgrade/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
444444
" SELECT c.oid, 0::oid, 0::oid "
445445
" FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
446446
" ON c.relnamespace = n.oid "
447-
" WHERE relkind IN ('r', 'm', 'S') AND "
447+
" WHERE relkind IN ('r', 'm') AND "
448448
/* exclude possible orphaned temp tables */
449449
" ((n.nspname !~ '^pg_temp_' AND "
450450
" n.nspname !~ '^pg_toast_temp_' AND "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp