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

Commit209a8d6

Browse files
committed
pg_dump and pg_restore -r had managed to diverge on the ordering of
different object types. Fix, and centralize logic to try to preventthe same mistake in future.
1 parent80bc61c commit209a8d6

File tree

4 files changed

+59
-47
lines changed

4 files changed

+59
-47
lines changed

‎src/bin/pg_dump/pg_backup.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.24 2002/09/04 20:31:34momjian Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.25 2003/08/28 20:21:34tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -166,8 +166,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
166166
externRestoreOptions*NewRestoreOptions(void);
167167

168168
/* Rearrange TOC entries */
169-
externvoidMoveToStart(Archive*AH,char*oType);
170-
externvoidMoveToEnd(Archive*AH,char*oType);
169+
externvoidMoveToStart(Archive*AH,constchar*oType);
170+
externvoidMoveToEnd(Archive*AH,constchar*oType);
171+
externvoidSortTocByObjectType(Archive*AH);
171172
externvoidSortTocByOID(Archive*AH);
172173
externvoidSortTocByID(Archive*AH);
173174
externvoidSortTocFromFile(Archive*AH,RestoreOptions*ropt);

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.74 2003/08/04 00:43:27 momjian Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.75 2003/08/28 20:21:34 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -845,11 +845,12 @@ EndRestoreBlob(ArchiveHandle *AH, Oid oid)
845845

846846
/*
847847
* Move TOC entries of the specified type to the START of the TOC.
848+
*
849+
* This is public, but if you use it anywhere but SortTocByObjectType,
850+
* you are risking breaking things.
848851
*/
849-
850-
/* Public */
851852
void
852-
MoveToStart(Archive*AHX,char*oType)
853+
MoveToStart(Archive*AHX,constchar*oType)
853854
{
854855
ArchiveHandle*AH= (ArchiveHandle*)AHX;
855856
TocEntry*te=AH->toc->next;
@@ -874,10 +875,12 @@ MoveToStart(Archive *AHX, char *oType)
874875

875876
/*
876877
* Move TOC entries of the specified type to the end of the TOC.
878+
*
879+
* This is public, but if you use it anywhere but SortTocByObjectType,
880+
* you are risking breaking things.
877881
*/
878-
/* Public */
879882
void
880-
MoveToEnd(Archive*AHX,char*oType)
883+
MoveToEnd(Archive*AHX,constchar*oType)
881884
{
882885
ArchiveHandle*AH= (ArchiveHandle*)AHX;
883886
TocEntry*te=AH->toc->next;
@@ -899,6 +902,44 @@ MoveToEnd(Archive *AHX, char *oType)
899902
}
900903
}
901904

905+
/*
906+
* Sort TOC by object type (items of same type keep same relative order)
907+
*
908+
* This is factored out to ensure that pg_dump and pg_restore stay in sync
909+
* about the standard ordering.
910+
*/
911+
void
912+
SortTocByObjectType(Archive*AH)
913+
{
914+
/*
915+
* Procedural languages have to be declared just after database and
916+
* schema creation, before they are used.
917+
*/
918+
MoveToStart(AH,"ACL LANGUAGE");
919+
MoveToStart(AH,"PROCEDURAL LANGUAGE");
920+
MoveToStart(AH,"FUNC PROCEDURAL LANGUAGE");
921+
MoveToStart(AH,"SCHEMA");
922+
MoveToStart(AH,"<Init>");
923+
/* Database entries *must* be at front (see also pg_restore.c) */
924+
MoveToStart(AH,"DATABASE");
925+
926+
MoveToEnd(AH,"TABLE DATA");
927+
MoveToEnd(AH,"BLOBS");
928+
MoveToEnd(AH,"INDEX");
929+
MoveToEnd(AH,"CONSTRAINT");
930+
MoveToEnd(AH,"FK CONSTRAINT");
931+
MoveToEnd(AH,"TRIGGER");
932+
MoveToEnd(AH,"RULE");
933+
MoveToEnd(AH,"SEQUENCE SET");
934+
935+
/*
936+
* Moving all comments to end is annoying, but must do it for comments
937+
* on stuff we just moved, and we don't seem to have quite enough
938+
* dependency structure to get it really right...
939+
*/
940+
MoveToEnd(AH,"COMMENT");
941+
}
942+
902943
/*
903944
* Sort TOC by OID
904945
*/

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.345 2003/08/2818:59:06 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.346 2003/08/2820:21:34 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -572,33 +572,9 @@ main(int argc, char **argv)
572572
dumpRules(g_fout,tblinfo,numTables);
573573
}
574574

575-
/* Now sort the output nicely */
575+
/* Now sort the output nicely: by OID within object types */
576576
SortTocByOID(g_fout);
577-
578-
/*
579-
* Procedural languages have to be declared just after database and
580-
* schema creation, before they are used.
581-
*/
582-
MoveToStart(g_fout,"ACL LANGUAGE");
583-
MoveToStart(g_fout,"PROCEDURAL LANGUAGE");
584-
MoveToStart(g_fout,"FUNC PROCEDURAL LANGUAGE");
585-
MoveToStart(g_fout,"SCHEMA");
586-
MoveToStart(g_fout,"DATABASE");
587-
MoveToEnd(g_fout,"TABLE DATA");
588-
MoveToEnd(g_fout,"BLOBS");
589-
MoveToEnd(g_fout,"INDEX");
590-
MoveToEnd(g_fout,"CONSTRAINT");
591-
MoveToEnd(g_fout,"FK CONSTRAINT");
592-
MoveToEnd(g_fout,"TRIGGER");
593-
MoveToEnd(g_fout,"RULE");
594-
MoveToEnd(g_fout,"SEQUENCE SET");
595-
596-
/*
597-
* Moving all comments to end is annoying, but must do it for comments
598-
* on stuff we just moved, and we don't seem to have quite enough
599-
* dependency structure to get it really right...
600-
*/
601-
MoveToEnd(g_fout,"COMMENT");
577+
SortTocByObjectType(g_fout);
602578

603579
if (plainText)
604580
{

‎src/bin/pg_dump/pg_restore.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.50 2003/08/0721:11:58 tgl Exp $
37+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.51 2003/08/28 20:21:34 tgl Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -335,19 +335,13 @@ main(int argc, char **argv)
335335
SortTocByID(AH);
336336

337337
if (opts->rearrange)
338+
SortTocByObjectType(AH);
339+
else
338340
{
339-
MoveToStart(AH,"<Init>");
340-
MoveToEnd(AH,"TABLE DATA");
341-
MoveToEnd(AH,"BLOBS");
342-
MoveToEnd(AH,"INDEX");
343-
MoveToEnd(AH,"TRIGGER");
344-
MoveToEnd(AH,"RULE");
345-
MoveToEnd(AH,"SEQUENCE SET");
341+
/* Database MUST be at start (see also SortTocByObjectType) */
342+
MoveToStart(AH,"DATABASE");
346343
}
347344

348-
/* Database MUST be at start */
349-
MoveToStart(AH,"DATABASE");
350-
351345
if (opts->tocSummary)
352346
PrintTOCSummary(AH,opts);
353347
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp