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

Commit9e733ea

Browse files
committed
Modify pg_dump so that the preferred dump order is by name within
object types, rather than by OID. This should help ensure consistentdump output from databases that are logically the same but have differenthistories, per recent discussion about 'diffing' databases. The patchis bulky because of renaming of fields, but not very complicated.Also, do some tweaking to cause BLOB restoration to be done in a betterorder, and clean up pg_restore's textual output to exactly match pg_dump.
1 parent6819787 commit9e733ea

File tree

10 files changed

+589
-426
lines changed

10 files changed

+589
-426
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.80 2003/12/08 16:39:05 tgl Exp $
14+
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.81 2004/03/03 21:28:54 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -368,9 +368,9 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
368368
pconstr=&(parent->checkexprs[l]);
369369
if (strcmp(pconstr->condef,constr->condef)!=0)
370370
continue;
371-
if (strcmp(pconstr->conname,constr->conname)==0||
372-
(pconstr->conname[0]=='$'&&
373-
constr->conname[0]=='$'))
371+
if (strcmp(pconstr->dobj.name,constr->dobj.name)==0||
372+
(pconstr->dobj.name[0]=='$'&&
373+
constr->dobj.name[0]=='$'))
374374
{
375375
constr->coninherited= true;
376376
break;
@@ -395,6 +395,8 @@ void
395395
AssignDumpId(DumpableObject*dobj)
396396
{
397397
dobj->dumpId=++lastDumpId;
398+
dobj->name=NULL;/* must be set later */
399+
dobj->namespace=NULL;/* may be set later */
398400
dobj->dependencies=NULL;
399401
dobj->nDeps=0;
400402
dobj->allocDeps=0;
@@ -725,7 +727,7 @@ findParentsByOid(TableInfo *self,
725727
{
726728
write_msg(NULL,"failed sanity check, parent OID %u of table \"%s\" (OID %u) not found\n",
727729
inhinfo[i].inhparent,
728-
self->relname,
730+
self->dobj.name,
729731
oid);
730732
exit_nicely();
731733
}

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.83 2004/02/24 03:35:19 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.84 2004/03/03 21:28:54 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -49,6 +49,8 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
4949
constintcompression,ArchiveModemode);
5050
staticint_printTocEntry(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt,boolisData);
5151

52+
staticvoidfixPriorBlobRefs(ArchiveHandle*AH,TocEntry*blobte,
53+
RestoreOptions*ropt);
5254
staticvoid_doSetFixedOutputState(ArchiveHandle*AH);
5355
staticvoid_doSetSessionAuth(ArchiveHandle*AH,constchar*user);
5456
staticvoid_reconnectToDB(ArchiveHandle*AH,constchar*dbname,constchar*user);
@@ -279,7 +281,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
279281
/*
280282
* If we can output the data, then restore it.
281283
*/
282-
if (AH->PrintTocDataPtr!=NULL&& (reqs&REQ_DATA)!=0)
284+
if (AH->PrintTocDataPtr!=NULL&& (reqs&REQ_DATA)!=0)
283285
{
284286
#ifndefHAVE_LIBZ
285287
if (AH->compression!=0)
@@ -331,6 +333,24 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
331333

332334
(*AH->PrintTocDataPtr) (AH,te,ropt);
333335

336+
/*
337+
* If we just restored blobs, fix references in
338+
* previously-loaded tables; otherwise, if we
339+
* previously restored blobs, fix references in
340+
* this table. Note that in standard cases the BLOBS
341+
* entry comes after all TABLE DATA entries, but
342+
* we should cope with other orders in case the
343+
* user demands reordering.
344+
*/
345+
if (strcmp(te->desc,"BLOBS")==0)
346+
fixPriorBlobRefs(AH,te,ropt);
347+
elseif (AH->createdBlobXref&&
348+
strcmp(te->desc,"TABLE DATA")==0)
349+
{
350+
ahlog(AH,1,"fixing up large-object cross-reference for \"%s\"\n",te->tag);
351+
FixupBlobRefs(AH,te);
352+
}
353+
334354
_enableTriggersIfNecessary(AH,te,ropt);
335355
}
336356
}
@@ -346,22 +366,44 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
346366
}/* end loop over TOC entries */
347367

348368
/*
349-
* Now use blobs_xref (if used) to fixup any refs for tables that we
350-
* loaded
369+
* Clean up & we're done.
351370
*/
352-
if (_canRestoreBlobs(AH)&&AH->createdBlobXref)
371+
if (ropt->filename||ropt->compression)
372+
ResetOutput(AH,sav);
373+
374+
if (ropt->useDB)
375+
{
376+
PQfinish(AH->connection);
377+
AH->connection=NULL;
378+
379+
if (AH->blobConnection)
380+
{
381+
PQfinish(AH->blobConnection);
382+
AH->blobConnection=NULL;
383+
}
384+
}
385+
}
386+
387+
/*
388+
* After restoring BLOBS, fix all blob references in previously-restored
389+
* tables. (Normally, the BLOBS entry should appear after all TABLE DATA
390+
* entries, so this will in fact handle all blob references.)
391+
*/
392+
staticvoid
393+
fixPriorBlobRefs(ArchiveHandle*AH,TocEntry*blobte,RestoreOptions*ropt)
394+
{
395+
TocEntry*te;
396+
teReqsreqs;
397+
398+
if (AH->createdBlobXref)
353399
{
354400
/* NULL parameter means disable ALL user triggers */
355401
_disableTriggersIfNecessary(AH,NULL,ropt);
356402

357-
te=AH->toc->next;
358-
while (te!=AH->toc)
403+
for (te=AH->toc->next;te!=blobte;te=te->next)
359404
{
360-
/* Is it table data? */
361405
if (strcmp(te->desc,"TABLE DATA")==0)
362406
{
363-
ahlog(AH,2,"checking whether we loaded \"%s\"\n",te->tag);
364-
365407
reqs=_tocEntryRequired(te,ropt);
366408

367409
if ((reqs&REQ_DATA)!=0)/* We loaded the data */
@@ -370,33 +412,11 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
370412
FixupBlobRefs(AH,te);
371413
}
372414
}
373-
else
374-
ahlog(AH,2,"ignoring large-object cross-references for %s %s\n",te->desc,te->tag);
375-
376-
te=te->next;
377415
}
378416

379417
/* NULL parameter means enable ALL user triggers */
380418
_enableTriggersIfNecessary(AH,NULL,ropt);
381419
}
382-
383-
/*
384-
* Clean up & we're done.
385-
*/
386-
if (ropt->filename||ropt->compression)
387-
ResetOutput(AH,sav);
388-
389-
if (ropt->useDB)
390-
{
391-
PQfinish(AH->connection);
392-
AH->connection=NULL;
393-
394-
if (AH->blobConnection)
395-
{
396-
PQfinish(AH->blobConnection);
397-
AH->blobConnection=NULL;
398-
}
399-
}
400420
}
401421

402422
/*
@@ -703,6 +723,9 @@ EndRestoreBlobs(ArchiveHandle *AH)
703723
if (AH->blobTxActive)
704724
CommitTransactionXref(AH);
705725

726+
if (AH->createdBlobXref)
727+
CreateBlobXrefIndex(AH);
728+
706729
ahlog(AH,1,"restored %d large objects\n",AH->blobCount);
707730
}
708731

@@ -2148,7 +2171,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
21482171
pfx,te->tag,te->desc,
21492172
te->namespace ?te->namespace :"-",
21502173
te->owner);
2151-
if (AH->PrintExtraTocPtr!=NULL)
2174+
if (AH->PrintExtraTocPtr!=NULL)
21522175
(*AH->PrintExtraTocPtr) (AH,te);
21532176
ahprintf(AH,"--\n\n");
21542177

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*
2121
* IDENTIFICATION
22-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.28 2003/12/06 03:00:11 tgl Exp $
22+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.29 2004/03/03 21:28:54 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -279,8 +279,9 @@ _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
279279
{
280280
lclTocEntry*ctx= (lclTocEntry*)te->formatData;
281281

282-
ahprintf(AH,"-- Data Pos: "INT64_FORMAT"\n",
283-
(int64)ctx->dataPos);
282+
if (AH->public.verbose)
283+
ahprintf(AH,"-- Data Pos: "INT64_FORMAT"\n",
284+
(int64)ctx->dataPos);
284285
}
285286

286287
/*
@@ -417,8 +418,8 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
417418
}
418419

419420
/*
420-
* Print data for agievn TOC entry
421-
*/
421+
* Print data for agiven TOC entry
422+
*/
422423
staticvoid
423424
_PrintTocData(ArchiveHandle*AH,TocEntry*te,RestoreOptions*ropt)
424425
{
@@ -497,8 +498,6 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
497498
blkType);
498499
break;
499500
}
500-
501-
ahprintf(AH,"\n\n");
502501
}
503502

504503
/*

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.51 2003/11/29 19:52:05 pgsql Exp $
8+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.52 2004/03/03 21:28:54 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -674,13 +674,21 @@ CreateBlobXrefTable(ArchiveHandle *AH)
674674

675675
ahlog(AH,1,"creating table for large object cross-references\n");
676676

677-
appendPQExpBuffer(qry,"Create Temporary Table %s(oldOid pg_catalog.oid, newOid pg_catalog.oid);",BLOB_XREF_TABLE);
678-
677+
appendPQExpBuffer(qry,"CREATE TEMPORARY TABLE %s(oldOid pg_catalog.oid, newOid pg_catalog.oid) WITHOUT OIDS",BLOB_XREF_TABLE);
679678
ExecuteSqlCommand(AH,qry,"could not create large object cross-reference table", true);
680679

681-
resetPQExpBuffer(qry);
680+
destroyPQExpBuffer(qry);
681+
}
682682

683-
appendPQExpBuffer(qry,"Create Unique Index %s_ix on %s(oldOid)",BLOB_XREF_TABLE,BLOB_XREF_TABLE);
683+
void
684+
CreateBlobXrefIndex(ArchiveHandle*AH)
685+
{
686+
PQExpBufferqry=createPQExpBuffer();
687+
688+
ahlog(AH,1,"creating index for large object cross-references\n");
689+
690+
appendPQExpBuffer(qry,"CREATE UNIQUE INDEX %s_ix ON %s(oldOid)",
691+
BLOB_XREF_TABLE,BLOB_XREF_TABLE);
684692
ExecuteSqlCommand(AH,qry,"could not create index on large object cross-reference table", true);
685693

686694
destroyPQExpBuffer(qry);
@@ -692,9 +700,8 @@ InsertBlobXref(ArchiveHandle *AH, Oid old, Oid new)
692700
PQExpBufferqry=createPQExpBuffer();
693701

694702
appendPQExpBuffer(qry,
695-
"Insert Into %s(oldOid, newOid)Values ('%u', '%u');",
703+
"INSERT INTO %s(oldOid, newOid)VALUES ('%u', '%u')",
696704
BLOB_XREF_TABLE,old,new);
697-
698705
ExecuteSqlCommand(AH,qry,"could not create large object cross-reference entry", true);
699706

700707
destroyPQExpBuffer(qry);
@@ -705,7 +712,7 @@ StartTransaction(ArchiveHandle *AH)
705712
{
706713
PQExpBufferqry=createPQExpBuffer();
707714

708-
appendPQExpBuffer(qry,"Begin;");
715+
appendPQExpBuffer(qry,"BEGIN");
709716

710717
ExecuteSqlCommand(AH,qry,"could not start database transaction", false);
711718
AH->txActive= true;
@@ -718,7 +725,7 @@ StartTransactionXref(ArchiveHandle *AH)
718725
{
719726
PQExpBufferqry=createPQExpBuffer();
720727

721-
appendPQExpBuffer(qry,"Begin;");
728+
appendPQExpBuffer(qry,"BEGIN");
722729

723730
ExecuteSqlCommand(AH,qry,
724731
"could not start transaction for large object cross-references", true);
@@ -732,7 +739,7 @@ CommitTransaction(ArchiveHandle *AH)
732739
{
733740
PQExpBufferqry=createPQExpBuffer();
734741

735-
appendPQExpBuffer(qry,"Commit;");
742+
appendPQExpBuffer(qry,"COMMIT");
736743

737744
ExecuteSqlCommand(AH,qry,"could not commit database transaction", false);
738745
AH->txActive= false;
@@ -745,7 +752,7 @@ CommitTransactionXref(ArchiveHandle *AH)
745752
{
746753
PQExpBufferqry=createPQExpBuffer();
747754

748-
appendPQExpBuffer(qry,"Commit;");
755+
appendPQExpBuffer(qry,"COMMIT");
749756

750757
ExecuteSqlCommand(AH,qry,"could not commit transaction for large object cross-references", true);
751758
AH->blobTxActive= false;

‎src/bin/pg_dump/pg_backup_db.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*Definitions for pg_backup_db.c
33
*
44
*IDENTIFICATION
5-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.9 2003/11/29 19:52:05 pgsql Exp $
5+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.10 2004/03/03 21:28:54 tgl Exp $
66
*/
77

88
#defineBLOB_XREF_TABLE "pg_dump_blob_xref"/* MUST be lower case */
@@ -12,6 +12,7 @@ extern intExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc, boo
1212
externintExecuteSqlCommandBuf(ArchiveHandle*AH,void*qry,size_tbufLen);
1313

1414
externvoidCreateBlobXrefTable(ArchiveHandle*AH);
15+
externvoidCreateBlobXrefIndex(ArchiveHandle*AH);
1516
externvoidInsertBlobXref(ArchiveHandle*AH,Oidold,Oidnew);
1617
externvoidStartTransaction(ArchiveHandle*AH);
1718
externvoidStartTransactionXref(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_files.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.24 2003/12/06 03:00:11 tgl Exp $
23+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.25 2004/03/03 21:28:54 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -224,7 +224,8 @@ _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
224224
{
225225
lclTocEntry*ctx= (lclTocEntry*)te->formatData;
226226

227-
ahprintf(AH,"-- File: %s\n",ctx->filename);
227+
if (AH->public.verbose)
228+
ahprintf(AH,"-- File: %s\n",ctx->filename);
228229
}
229230

230231
staticvoid

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.41 2003/12/08 16:39:05 tgl Exp $
19+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.42 2004/03/03 21:28:54 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -309,7 +309,7 @@ _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
309309
{
310310
lclTocEntry*ctx= (lclTocEntry*)te->formatData;
311311

312-
if (ctx->filename!=NULL)
312+
if (AH->public.verbose&&ctx->filename!=NULL)
313313
ahprintf(AH,"-- File: %s\n",ctx->filename);
314314
}
315315

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp