mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03: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:
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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);
|
extern RestoreOptions *NewRestoreOptions(void);
|
||||||
|
|
||||||
/* Rearrange TOC entries */
|
/* Rearrange TOC entries */
|
||||||
extern void MoveToStart(Archive *AH, char *oType);
|
extern void MoveToStart(Archive *AH, const char *oType);
|
||||||
extern void MoveToEnd(Archive *AH, char *oType);
|
extern void MoveToEnd(Archive *AH, const char *oType);
|
||||||
|
extern void SortTocByObjectType(Archive *AH);
|
||||||
extern void SortTocByOID(Archive *AH);
|
extern void SortTocByOID(Archive *AH);
|
||||||
extern void SortTocByID(Archive *AH);
|
extern void SortTocByID(Archive *AH);
|
||||||
extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
|
extern void SortTocFromFile(Archive *AH, RestoreOptions *ropt);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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.
|
* 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
|
void
|
||||||
MoveToStart(Archive *AHX, char *oType)
|
MoveToStart(Archive *AHX, const char *oType)
|
||||||
{
|
{
|
||||||
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
||||||
TocEntry *te = AH->toc->next;
|
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.
|
* 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
|
void
|
||||||
MoveToEnd(Archive *AHX, char *oType)
|
MoveToEnd(Archive *AHX, const char *oType)
|
||||||
{
|
{
|
||||||
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
ArchiveHandle *AH = (ArchiveHandle *) AHX;
|
||||||
TocEntry *te = AH->toc->next;
|
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
|
* Sort TOC by OID
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
* by PostgreSQL
|
* by PostgreSQL
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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);
|
dumpRules(g_fout, tblinfo, numTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now sort the output nicely */
|
/* Now sort the output nicely: by OID within object types */
|
||||||
SortTocByOID(g_fout);
|
SortTocByOID(g_fout);
|
||||||
|
SortTocByObjectType(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");
|
|
||||||
|
|
||||||
if (plainText)
|
if (plainText)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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,18 +335,12 @@ main(int argc, char **argv)
|
|||||||
SortTocByID(AH);
|
SortTocByID(AH);
|
||||||
|
|
||||||
if (opts->rearrange)
|
if (opts->rearrange)
|
||||||
|
SortTocByObjectType(AH);
|
||||||
|
else
|
||||||
{
|
{
|
||||||
MoveToStart(AH, "<Init>");
|
/* Database MUST be at start (see also SortTocByObjectType) */
|
||||||
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 */
|
|
||||||
MoveToStart(AH, "DATABASE");
|
MoveToStart(AH, "DATABASE");
|
||||||
|
}
|
||||||
|
|
||||||
if (opts->tocSummary)
|
if (opts->tocSummary)
|
||||||
PrintTOCSummary(AH, opts);
|
PrintTOCSummary(AH, opts);
|
||||||
|
Reference in New Issue
Block a user