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

Commit49bf04b

Browse files
committed
Fix some more not-schema-aware queries in pg_dump. Also fix some places
that would do the wrong thing with BLOB OIDs exceeding 2G.
1 parentdc20063 commit49bf04b

File tree

6 files changed

+62
-82
lines changed

6 files changed

+62
-82
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c‎

Lines changed: 28 additions & 24 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.47 2002/05/28 22:26:56 tgl Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.48 2002/05/29 01:38:56 tgl Exp $
1919
*
2020
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2121
*
@@ -525,14 +525,15 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
525525
ahprintf(AH,"-- Disable triggers\n");
526526

527527
/*
528-
* Just update the AFFECTED table, if known.
528+
* Just update the AFFECTED table, if known. Otherwise update all
529+
* non-system tables.
529530
*/
530531
if (te&&te->name&&strlen(te->name)>0)
531-
ahprintf(AH,"UPDATE pg_class SET reltriggers = 0 "
532-
"WHERE oid = '%s'::regclass;\n\n",
532+
ahprintf(AH,"UPDATEpg_catalog.pg_class SET reltriggers = 0 "
533+
"WHERE oid = '%s'::pg_catalog.regclass;\n\n",
533534
fmtId(te->name, false));
534535
else
535-
ahprintf(AH,"UPDATE pg_class SET reltriggers = 0 FROM pg_namespace "
536+
ahprintf(AH,"UPDATEpg_catalog.pg_class SET reltriggers = 0 FROMpg_catalog.pg_namespace "
536537
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
537538

538539
/*
@@ -591,17 +592,18 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
591592
ahprintf(AH,"-- Enable triggers\n");
592593

593594
/*
594-
* Just update the AFFECTED table, if known.
595+
* Just update the AFFECTED table, if known. Otherwise update all
596+
* non-system tables.
595597
*/
596598
if (te&&te->name&&strlen(te->name)>0)
597-
ahprintf(AH,"UPDATE pg_class SET reltriggers = "
598-
"(SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) "
599-
"WHERE oid = '%s'::regclass;\n\n",
599+
ahprintf(AH,"UPDATEpg_catalog.pg_class SET reltriggers = "
600+
"(SELECT count(*) FROMpg_catalog.pg_trigger where pg_class.oid = tgrelid) "
601+
"WHERE oid = '%s'::pg_catalog.regclass;\n\n",
600602
fmtId(te->name, false));
601603
else
602-
ahprintf(AH,"UPDATE pg_class SET reltriggers = "
603-
"(SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) "
604-
"FROM pg_namespace "
604+
ahprintf(AH,"UPDATEpg_catalog.pg_class SET reltriggers = "
605+
"(SELECT count(*) FROMpg_catalog.pg_trigger where pg_class.oid = tgrelid) "
606+
"FROMpg_catalog.pg_namespace "
605607
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
606608

607609
/*
@@ -856,18 +858,20 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
856858
void
857859
EndRestoreBlob(ArchiveHandle*AH,Oidoid)
858860
{
859-
if(AH->lo_buf_used>0) {
860-
/* Write remaining bytes from the LO buffer */
861-
intres;
862-
res=lo_write(AH->connection,AH->loFd, (void*)AH->lo_buf,AH->lo_buf_used);
861+
if (AH->lo_buf_used>0)
862+
{
863+
/* Write remaining bytes from the LO buffer */
864+
intres;
865+
866+
res=lo_write(AH->connection,AH->loFd, (void*)AH->lo_buf,AH->lo_buf_used);
863867

864-
ahlog(AH,5,"wrote remaining %d bytes of large object data (result = %d)\n",
865-
(int)AH->lo_buf_used,res);
866-
if (res!=AH->lo_buf_used)
867-
die_horribly(AH,modulename,"could not write to large object (result: %d, expected: %d)\n",
868-
res,AH->lo_buf_used);
869-
AH->lo_buf_used=0;
870-
}
868+
ahlog(AH,5,"wrote remaining %d bytes of large object data (result = %d)\n",
869+
(int)AH->lo_buf_used,res);
870+
if (res!=AH->lo_buf_used)
871+
die_horribly(AH,modulename,"could not write to large object (result: %d, expected: %d)\n",
872+
res,AH->lo_buf_used);
873+
AH->lo_buf_used=0;
874+
}
871875

872876
lo_close(AH->connection,AH->loFd);
873877
AH->writingBlob=0;
@@ -1444,7 +1448,7 @@ WriteInt(ArchiveHandle *AH, int i)
14441448
for (b=0;b<AH->intSize;b++)
14451449
{
14461450
(*AH->WriteBytePtr) (AH,i&0xFF);
1447-
i=i /256;
1451+
i>>=8;
14481452
}
14491453

14501454
returnAH->intSize+1;

‎src/bin/pg_dump/pg_backup_custom.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*
2121
* IDENTIFICATION
22-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.18 2002/04/24 02:21:04 momjian Exp $
22+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.19 2002/05/29 01:38:56 tgl Exp $
2323
*
2424
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2525
*
@@ -638,7 +638,7 @@ _PrintData(ArchiveHandle *AH)
638638
staticvoid
639639
_LoadBlobs(ArchiveHandle*AH)
640640
{
641-
intoid;
641+
Oidoid;
642642

643643
StartRestoreBlobs(AH);
644644

@@ -664,7 +664,7 @@ _LoadBlobs(ArchiveHandle *AH)
664664
staticvoid
665665
_skipBlobs(ArchiveHandle*AH)
666666
{
667-
intoid;
667+
Oidoid;
668668

669669
oid=ReadInt(AH);
670670
while (oid!=0)

‎src/bin/pg_dump/pg_backup_db.c‎

Lines changed: 7 additions & 5 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-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.32 2002/05/10 22:36:26 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.33 2002/05/29 01:38:56 tgl Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -729,7 +729,7 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
729729
appendPQExpBuffer(tblQry,
730730
"SELECT a.attname FROM "
731731
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
732-
"WHERE a.attnum > 0 AND a.attrelid = '%s'::regclass "
732+
"WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass "
733733
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
734734
tblName->data);
735735

@@ -799,7 +799,7 @@ CreateBlobXrefTable(ArchiveHandle *AH)
799799

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

802-
appendPQExpBuffer(qry,"Create Temporary Table %s(oldOid oid, newOid oid);",BLOB_XREF_TABLE);
802+
appendPQExpBuffer(qry,"Create Temporary Table %s(oldOidpg_catalog.oid, newOidpg_catalog.oid);",BLOB_XREF_TABLE);
803803

804804
ExecuteSqlCommand(AH,qry,"could not create large object cross-reference table", true);
805805

@@ -812,11 +812,13 @@ CreateBlobXrefTable(ArchiveHandle *AH)
812812
}
813813

814814
void
815-
InsertBlobXref(ArchiveHandle*AH,intold,intnew)
815+
InsertBlobXref(ArchiveHandle*AH,Oidold,Oidnew)
816816
{
817817
PQExpBufferqry=createPQExpBuffer();
818818

819-
appendPQExpBuffer(qry,"Insert Into %s(oldOid, newOid) Values (%d, %d);",BLOB_XREF_TABLE,old,new);
819+
appendPQExpBuffer(qry,
820+
"Insert Into %s(oldOid, newOid) Values ('%u', '%u');",
821+
BLOB_XREF_TABLE,old,new);
820822

821823
ExecuteSqlCommand(AH,qry,"could not create large object cross-reference entry", true);
822824

‎src/bin/pg_dump/pg_backup_db.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*Definitions for pg_backup_db.c
33
*
44
*IDENTIFICATION
5-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.6 2002/05/10 22:36:26 tgl Exp $
5+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.7 2002/05/29 01:38:56 tgl Exp $
66
*/
77

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

1414
externvoidCreateBlobXrefTable(ArchiveHandle*AH);
15-
externvoidInsertBlobXref(ArchiveHandle*AH,intold,intnew);
15+
externvoidInsertBlobXref(ArchiveHandle*AH,Oidold,Oidnew);
1616
externvoidStartTransaction(ArchiveHandle*AH);
1717
externvoidStartTransactionXref(ArchiveHandle*AH);
1818
externvoidCommitTransaction(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_files.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.15 2002/04/24 02:21:04 momjian Exp $
23+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.16 2002/05/29 01:38:56 tgl Exp $
2424
*
2525
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2626
*
@@ -76,7 +76,7 @@ typedef struct
7676

7777
staticchar*modulename=gettext_noop("file archiver");
7878
staticvoid_LoadBlobs(ArchiveHandle*AH,RestoreOptions*ropt);
79-
staticvoid_getBlobTocEntry(ArchiveHandle*AH,int*oid,char*fname);
79+
staticvoid_getBlobTocEntry(ArchiveHandle*AH,Oid*oid,char*fname);
8080

8181
/*
8282
*Initializer
@@ -328,7 +328,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
328328
}
329329

330330
staticvoid
331-
_getBlobTocEntry(ArchiveHandle*AH,int*oid,charfname[K_STD_BUF_SIZE])
331+
_getBlobTocEntry(ArchiveHandle*AH,Oid*oid,charfname[K_STD_BUF_SIZE])
332332
{
333333
lclContext*ctx= (lclContext*)AH->formatData;
334334
charblobTe[K_STD_BUF_SIZE];
@@ -337,7 +337,7 @@ _getBlobTocEntry(ArchiveHandle *AH, int *oid, char fname[K_STD_BUF_SIZE])
337337

338338
if (fgets(&blobTe[0],K_STD_BUF_SIZE-1,ctx->blobToc)!=NULL)
339339
{
340-
*oid=atoi(blobTe);
340+
*oid=atooid(blobTe);
341341

342342
fpos=strcspn(blobTe," ");
343343

@@ -360,7 +360,7 @@ _getBlobTocEntry(ArchiveHandle *AH, int *oid, char fname[K_STD_BUF_SIZE])
360360
staticvoid
361361
_LoadBlobs(ArchiveHandle*AH,RestoreOptions*ropt)
362362
{
363-
intoid;
363+
Oidoid;
364364
lclContext*ctx= (lclContext*)AH->formatData;
365365
charfname[K_STD_BUF_SIZE];
366366

@@ -509,9 +509,9 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
509509
sfx="";
510510

511511
sprintf(fmode,"wb%d",AH->compression);
512-
sprintf(fname,"blob_%d.dat%s",oid,sfx);
512+
sprintf(fname,"blob_%u.dat%s",oid,sfx);
513513

514-
fprintf(ctx->blobToc,"%d %s\n",oid,fname);
514+
fprintf(ctx->blobToc,"%u %s\n",oid,fname);
515515

516516
#ifdefHAVE_LIBZ
517517
tctx->FH=gzopen(fname,fmode);

‎src/bin/pg_dump/pg_backup_tar.c‎

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.22 2002/05/10 22:36:26 tgl Exp $
19+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.23 2002/05/29 01:38:56 tgl Exp $
2020
*
2121
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
2222
*
@@ -666,34 +666,6 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
666666
_PrintFileData(AH,tctx->filename,ropt);
667667
}
668668

669-
/* static void _getBlobTocEntry(ArchiveHandle* AH, int *oid, char fname[K_STD_BUF_SIZE])
670-
* {
671-
*lclContext*ctx = (lclContext*)AH->formatData;
672-
*charblobTe[K_STD_BUF_SIZE];
673-
*intfpos;
674-
*inteos;
675-
*
676-
*if (tarGets(&blobTe[0], K_STD_BUF_SIZE - 1, ctx->blobToc) != NULL)
677-
*{
678-
**oid = atoi(blobTe);
679-
*
680-
*fpos = strcspn(blobTe, " ");
681-
*
682-
*strncpy(fname, &blobTe[fpos+1], K_STD_BUF_SIZE - 1);
683-
*
684-
*eos = strlen(fname)-1;
685-
*
686-
*if (fname[eos] == '\n')
687-
*fname[eos] = '\0';
688-
*
689-
*} else {
690-
*
691-
**oid = 0;
692-
*fname[0] = '\0';
693-
*}
694-
*}
695-
*/
696-
697669
staticvoid
698670
_LoadBlobs(ArchiveHandle*AH,RestoreOptions*ropt)
699671
{
@@ -710,20 +682,22 @@ _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
710682
{
711683
ctx->FH=th;
712684

713-
oid= (Oid)strtoul(&th->targetFile[5],NULL,10);
714-
715-
if (strncmp(th->targetFile,"blob_",5)==0&&oid!=0)
685+
if (strncmp(th->targetFile,"blob_",5)==0)
716686
{
717-
ahlog(AH,1,"restoring large object OID %u\n",oid);
687+
oid=atooid(&th->targetFile[5]);
688+
if (oid!=0)
689+
{
690+
ahlog(AH,1,"restoring large object OID %u\n",oid);
718691

719-
StartRestoreBlob(AH,oid);
692+
StartRestoreBlob(AH,oid);
720693

721-
while ((cnt=tarRead(buf,4095,th))>0)
722-
{
723-
buf[cnt]='\0';
724-
ahwrite(buf,1,cnt,AH);
694+
while ((cnt=tarRead(buf,4095,th))>0)
695+
{
696+
buf[cnt]='\0';
697+
ahwrite(buf,1,cnt,AH);
698+
}
699+
EndRestoreBlob(AH,oid);
725700
}
726-
EndRestoreBlob(AH,oid);
727701
}
728702

729703
tarClose(AH,th);
@@ -916,9 +890,9 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
916890
else
917891
sfx="";
918892

919-
sprintf(fname,"blob_%d.dat%s",oid,sfx);
893+
sprintf(fname,"blob_%u.dat%s",oid,sfx);
920894

921-
tarPrintf(AH,ctx->blobToc,"%d %s\n",oid,fname);
895+
tarPrintf(AH,ctx->blobToc,"%u %s\n",oid,fname);
922896

923897
tctx->TH=tarOpen(AH,fname,'w');
924898

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp