mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
pg_dump and pg_restore -r had managed to diverge on the ordering of
different object types. Fix, and centralize logic to try to prevent the same mistake in future.
This commit is contained in:
parent
80bc61c849
commit
209a8d63df
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.24 2002/09/04 20:31:34 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.25 2003/08/28 20:21:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -166,8 +166,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
|
||||
extern RestoreOptions *NewRestoreOptions(void);
|
||||
|
||||
/* Rearrange TOC entries */
|
||||
extern void MoveToStart(Archive *AH, char *oType);
|
||||
extern void MoveToEnd(Archive *AH, char *oType);
|
||||
extern void MoveToStart(Archive *AH, const char *oType);
|
||||
extern void MoveToEnd(Archive *AH, const char *oType);
|
||||
extern void SortTocByObjectType(Archive *AH);
|
||||
extern void SortTocByOID(Archive *AH);
|
||||
extern void SortTocByID(Archive *AH);
|
||||
extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
|
||||
|
@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.74 2003/08/04 00:43:27 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.75 2003/08/28 20:21:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -845,11 +845,12 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid)
|
||||
|
||||
/*
|
||||
* Move TOC entries of the specified type to the START of the TOC.
|
||||
*
|
||||
* This is public, but if you use it anywhere but SortTocByObjectType,
|
||||
* you are risking breaking things.
|
||||
*/
|
||||
|
||||
/* Public */
|
||||
void
|
||||
MoveToStart(Archive *AHX, char *oType)
|
||||
MoveToStart(Archive *AHX, const char *oType)
|
||||
{
|
||||
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
||||
TocEntry *te = AH->toc->next;
|
||||
@ -874,10 +875,12 @@ MoveToStart(Archive *AHX, char *oType)
|
||||
|
||||
/*
|
||||
* Move TOC entries of the specified type to the end of the TOC.
|
||||
*
|
||||
* This is public, but if you use it anywhere but SortTocByObjectType,
|
||||
* you are risking breaking things.
|
||||
*/
|
||||
/* Public */
|
||||
void
|
||||
MoveToEnd(Archive *AHX, char *oType)
|
||||
MoveToEnd(Archive *AHX, const char *oType)
|
||||
{
|
||||
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
||||
TocEntry *te = AH->toc->next;
|
||||
@ -899,6 +902,44 @@ MoveToEnd(Archive *AHX, char *oType)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sort TOC by object type (items of same type keep same relative order)
|
||||
*
|
||||
* This is factored out to ensure that pg_dump and pg_restore stay in sync
|
||||
* about the standard ordering.
|
||||
*/
|
||||
void
|
||||
SortTocByObjectType(Archive *AH)
|
||||
{
|
||||
/*
|
||||
* Procedural languages have to be declared just after database and
|
||||
* schema creation, before they are used.
|
||||
*/
|
||||
MoveToStart(AH, "ACL LANGUAGE");
|
||||
MoveToStart(AH, "PROCEDURAL LANGUAGE");
|
||||
MoveToStart(AH, "FUNC PROCEDURAL LANGUAGE");
|
||||
MoveToStart(AH, "SCHEMA");
|
||||
MoveToStart(AH, "<Init>");
|
||||
/* Database entries *must* be at front (see also pg_restore.c) */
|
||||
MoveToStart(AH, "DATABASE");
|
||||
|
||||
MoveToEnd(AH, "TABLE DATA");
|
||||
MoveToEnd(AH, "BLOBS");
|
||||
MoveToEnd(AH, "INDEX");
|
||||
MoveToEnd(AH, "CONSTRAINT");
|
||||
MoveToEnd(AH, "FK CONSTRAINT");
|
||||
MoveToEnd(AH, "TRIGGER");
|
||||
MoveToEnd(AH, "RULE");
|
||||
MoveToEnd(AH, "SEQUENCE SET");
|
||||
|
||||
/*
|
||||
* Moving all comments to end is annoying, but must do it for comments
|
||||
* on stuff we just moved, and we don't seem to have quite enough
|
||||
* dependency structure to get it really right...
|
||||
*/
|
||||
MoveToEnd(AH, "COMMENT");
|
||||
}
|
||||
|
||||
/*
|
||||
* Sort TOC by OID
|
||||
*/
|
||||
|
@ -12,7 +12,7 @@
|
||||
* by PostgreSQL
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.345 2003/08/28 18:59:06 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.346 2003/08/28 20:21:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -572,33 +572,9 @@ main(int argc, char **argv)
|
||||
dumpRules(g_fout, tblinfo, numTables);
|
||||
}
|
||||
|
||||
/* Now sort the output nicely */
|
||||
/* Now sort the output nicely: by OID within object types */
|
||||
SortTocByOID(g_fout);
|
||||
|
||||
/*
|
||||
* Procedural languages have to be declared just after database and
|
||||
* schema creation, before they are used.
|
||||
*/
|
||||
MoveToStart(g_fout, "ACL LANGUAGE");
|
||||
MoveToStart(g_fout, "PROCEDURAL LANGUAGE");
|
||||
MoveToStart(g_fout, "FUNC PROCEDURAL LANGUAGE");
|
||||
MoveToStart(g_fout, "SCHEMA");
|
||||
MoveToStart(g_fout, "DATABASE");
|
||||
MoveToEnd(g_fout, "TABLE DATA");
|
||||
MoveToEnd(g_fout, "BLOBS");
|
||||
MoveToEnd(g_fout, "INDEX");
|
||||
MoveToEnd(g_fout, "CONSTRAINT");
|
||||
MoveToEnd(g_fout, "FK CONSTRAINT");
|
||||
MoveToEnd(g_fout, "TRIGGER");
|
||||
MoveToEnd(g_fout, "RULE");
|
||||
MoveToEnd(g_fout, "SEQUENCE SET");
|
||||
|
||||
/*
|
||||
* Moving all comments to end is annoying, but must do it for comments
|
||||
* on stuff we just moved, and we don't seem to have quite enough
|
||||
* dependency structure to get it really right...
|
||||
*/
|
||||
MoveToEnd(g_fout, "COMMENT");
|
||||
SortTocByObjectType(g_fout);
|
||||
|
||||
if (plainText)
|
||||
{
|
||||
|
@ -34,7 +34,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.50 2003/08/07 21:11:58 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.51 2003/08/28 20:21:34 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -335,19 +335,13 @@ main(int argc, char **argv)
|
||||
SortTocByID(AH);
|
||||
|
||||
if (opts->rearrange)
|
||||
SortTocByObjectType(AH);
|
||||
else
|
||||
{
|
||||
MoveToStart(AH, "<Init>");
|
||||
MoveToEnd(AH, "TABLE DATA");
|
||||
MoveToEnd(AH, "BLOBS");
|
||||
MoveToEnd(AH, "INDEX");
|
||||
MoveToEnd(AH, "TRIGGER");
|
||||
MoveToEnd(AH, "RULE");
|
||||
MoveToEnd(AH, "SEQUENCE SET");
|
||||
/* Database MUST be at start (see also SortTocByObjectType) */
|
||||
MoveToStart(AH, "DATABASE");
|
||||
}
|
||||
|
||||
/* Database MUST be at start */
|
||||
MoveToStart(AH, "DATABASE");
|
||||
|
||||
if (opts->tocSummary)
|
||||
PrintTOCSummary(AH, opts);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user