Skip to content

Commit 44954fa

Browse files
committed
Added long-standing transaction when restoring BLOBS (uses commit every BLOB_BATCH_SIZE)
Prevent dumping of languages from template1.
1 parent 0babf31 commit 44954fa

File tree

8 files changed

+109
-21
lines changed

8 files changed

+109
-21
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
* Modifications - 31-Jul-2000 - pjw@rhyme.com.au (1.46, 1.47)
2424
* Fixed version number initialization in _allocAH (pg_backup_archiver.c)
2525
*
26+
*
27+
* Modifications - 30-Oct-2000 - pjw@rhyme.com.au
28+
* Added {Start,End}RestoreBlobs to allow extended TX during BLOB restore.
29+
*
2630
*-------------------------------------------------------------------------
2731
*/
2832

@@ -590,13 +594,43 @@ int EndBlob(Archive* AHX, int oid)
590594
* BLOB Restoration
591595
**********/
592596

597+
/*
598+
* Called by a format handler before any blobs are restored
599+
*/
600+
void StartRestoreBlobs(ArchiveHandle* AH)
601+
{
602+
AH->blobCount = 0;
603+
}
604+
605+
/*
606+
* Called by a format handler after all blobs are restored
607+
*/
608+
void EndRestoreBlobs(ArchiveHandle* AH)
609+
{
610+
if (AH->txActive)
611+
{
612+
ahlog(AH, 2, "Committing BLOB transactions\n");
613+
CommitTransaction(AH);
614+
}
615+
616+
if (AH->blobTxActive)
617+
{
618+
CommitTransactionXref(AH);
619+
}
620+
621+
ahlog(AH, 1, "Restored %d BLOBs\n", AH->blobCount);
622+
}
623+
624+
593625
/*
594626
* Called by a format handler to initiate restoration of a blob
595627
*/
596628
void StartRestoreBlob(ArchiveHandle* AH, int oid)
597629
{
598630
int loOid;
599631

632+
AH->blobCount++;
633+
600634
if (!AH->createdBlobXref)
601635
{
602636
if (!AH->connection)
@@ -606,7 +640,18 @@ void StartRestoreBlob(ArchiveHandle* AH, int oid)
606640
AH->createdBlobXref = 1;
607641
}
608642

609-
StartTransaction(AH);
643+
/*
644+
* Start long-running TXs if necessary
645+
*/
646+
if (!AH->txActive)
647+
{
648+
ahlog(AH, 2, "Starting BLOB transactions\n");
649+
StartTransaction(AH);
650+
}
651+
if (!AH->blobTxActive)
652+
{
653+
StartTransactionXref(AH);
654+
}
610655

611656
loOid = lo_creat(AH->connection, INV_READ | INV_WRITE);
612657
if (loOid == 0)
@@ -628,7 +673,15 @@ void EndRestoreBlob(ArchiveHandle* AH, int oid)
628673
lo_close(AH->connection, AH->loFd);
629674
AH->writingBlob = 0;
630675

631-
CommitTransaction(AH);
676+
/*
677+
* Commit every BLOB_BATCH_SIZE blobs...
678+
*/
679+
if ( ((AH->blobCount / BLOB_BATCH_SIZE) * BLOB_BATCH_SIZE) == AH->blobCount)
680+
{
681+
ahlog(AH, 2, "Committing BLOB transactions\n");
682+
CommitTransaction(AH);
683+
CommitTransactionXref(AH);
684+
}
632685
}
633686

634687
/***********

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#define K_VERS_MAJOR 1
6464
#define K_VERS_MINOR 4
65-
#define K_VERS_REV 21
65+
#define K_VERS_REV 22
6666

6767
/* Data block types */
6868
#define BLK_DATA 1
@@ -76,6 +76,9 @@ typedef z_stream *z_streamp;
7676
#define K_VERS_1_4 (( (1 * 256 + 4) * 256 + 0) * 256 + 0) /* Date & name in header */
7777
#define K_VERS_MAX (( (1 * 256 + 4) * 256 + 255) * 256 + 0)
7878

79+
/* No of BLOBs to restore in 1 TX */
80+
#define BLOB_BATCH_SIZE 100
81+
7982
struct _archiveHandle;
8083
struct _tocEntry;
8184
struct _restoreList;
@@ -186,13 +189,16 @@ typedef struct _archiveHandle {
186189
char *pgport;
187190
PGconn *connection;
188191
PGconn *blobConnection; /* Connection for BLOB xref */
192+
int txActive; /* Flag set if TX active on connection */
193+
int blobTxActive; /* Flag set if TX active on blobConnection */
189194
int connectToDB; /* Flag to indicate if direct DB connection is required */
190195
int pgCopyIn; /* Currently in libpq 'COPY IN' mode. */
191196
PQExpBuffer pgCopyBuf; /* Left-over data from incomplete lines in COPY IN */
192197

193198
int loFd; /* BLOB fd */
194199
int writingBlob; /* Flag */
195200
int createdBlobXref; /* Flag */
201+
int blobCount; /* # of blobs restored */
196202

197203
int lastID; /* Last internal ID for a TOC entry */
198204
char* fSpec; /* Archive File Spec */
@@ -256,8 +262,10 @@ extern int ReadInt(ArchiveHandle* AH);
256262
extern char* ReadStr(ArchiveHandle* AH);
257263
extern int WriteStr(ArchiveHandle* AH, char* s);
258264

265+
extern void StartRestoreBlobs(ArchiveHandle* AH);
259266
extern void StartRestoreBlob(ArchiveHandle* AH, int oid);
260267
extern void EndRestoreBlob(ArchiveHandle* AH, int oid);
268+
extern void EndRestoreBlobs(ArchiveHandle* AH);
261269

262270
extern void InitArchiveFmt_Custom(ArchiveHandle* AH);
263271
extern void InitArchiveFmt_Files(ArchiveHandle* AH);

src/bin/pg_dump/pg_backup_custom.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,8 @@ static void _LoadBlobs(ArchiveHandle* AH)
585585
{
586586
int oid;
587587

588+
StartRestoreBlobs(AH);
589+
588590
oid = ReadInt(AH);
589591
while(oid != 0)
590592
{
@@ -593,6 +595,9 @@ static void _LoadBlobs(ArchiveHandle* AH)
593595
EndRestoreBlob(AH, oid);
594596
oid = ReadInt(AH);
595597
}
598+
599+
EndRestoreBlobs(AH);
600+
596601
}
597602

598603
/*
@@ -608,8 +613,8 @@ static void _skipBlobs(ArchiveHandle* AH)
608613
oid = ReadInt(AH);
609614
while(oid != 0)
610615
{
611-
_skipData(AH);
612-
oid = ReadInt(AH);
616+
_skipData(AH);
617+
oid = ReadInt(AH);
613618
}
614619
}
615620

src/bin/pg_dump/pg_backup_db.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,17 @@ void StartTransaction(ArchiveHandle* AH)
675675
appendPQExpBuffer(qry, "Begin;");
676676

677677
ExecuteSqlCommand(AH, qry, "can not start database transaction");
678+
AH->txActive = true;
679+
}
680+
681+
void StartTransactionXref(ArchiveHandle* AH)
682+
{
683+
PQExpBuffer qry = createPQExpBuffer();
684+
685+
appendPQExpBuffer(qry, "Begin;");
686+
687+
_executeSqlCommand(AH, AH->blobConnection, qry, "can not start BLOB xref transaction");
688+
AH->blobTxActive = true;
678689
}
679690

680691
void CommitTransaction(ArchiveHandle* AH)
@@ -684,6 +695,15 @@ void CommitTransaction(ArchiveHandle* AH)
684695
appendPQExpBuffer(qry, "Commit;");
685696

686697
ExecuteSqlCommand(AH, qry, "can not commit database transaction");
698+
AH->txActive = false;
687699
}
688700

701+
void CommitTransactionXref(ArchiveHandle* AH)
702+
{
703+
PQExpBuffer qry = createPQExpBuffer();
689704

705+
appendPQExpBuffer(qry, "Commit;");
706+
707+
_executeSqlCommand(AH, AH->blobConnection, qry, "can not commit BLOB xref transaction");
708+
AH->blobTxActive = false;
709+
}

src/bin/pg_dump/pg_backup_db.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ extern int ExecuteSqlCommandBuf(ArchiveHandle* AH, void *qry, int bufLen);
1212
extern void CreateBlobXrefTable(ArchiveHandle* AH);
1313
extern void InsertBlobXref(ArchiveHandle* AH, int old, int new);
1414
extern void StartTransaction(ArchiveHandle* AH);
15+
extern void StartTransactionXref(ArchiveHandle* AH);
1516
extern void CommitTransaction(ArchiveHandle* AH);
17+
extern void CommitTransactionXref(ArchiveHandle* AH);
1618

src/bin/pg_dump/pg_backup_files.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ static void _LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
318318
lclContext* ctx = (lclContext*)AH->formatData;
319319
char fname[K_STD_BUF_SIZE];
320320

321+
StartRestoreBlobs(AH);
322+
321323
ctx->blobToc = fopen("blobs.toc", PG_BINARY_R);
322324

323325
_getBlobTocEntry(AH, &oid, fname);
@@ -331,6 +333,8 @@ static void _LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
331333
}
332334

333335
fclose(ctx->blobToc);
336+
337+
EndRestoreBlobs(AH);
334338
}
335339

336340

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ static void _LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
627627
int cnt;
628628
char buf[4096];
629629

630+
StartRestoreBlobs(AH);
631+
630632
th = tarOpen(AH, NULL, 'r'); /* Open next file */
631633
while (th != NULL)
632634
{
@@ -652,21 +654,8 @@ static void _LoadBlobs(ArchiveHandle* AH, RestoreOptions *ropt)
652654
th = tarOpen(AH, NULL, 'r');
653655
}
654656

655-
/*
656-
* ctx->blobToc = tarOpen(AH, "blobs.toc", 'r');
657-
*
658-
* _getBlobTocEntry(AH, &oid, fname);
659-
*
660-
* while(oid != 0)
661-
* {
662-
* StartRestoreBlob(AH, oid);
663-
* _PrintFileData(AH, fname, ropt);
664-
* EndRestoreBlob(AH, oid);
665-
* _getBlobTocEntry(AH, &oid, fname);
666-
* }
667-
*
668-
* tarClose(AH, ctx->blobToc);
669-
*/
657+
EndRestoreBlobs(AH);
658+
670659
}
671660

672661

src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.176 2000/10/24 13:24:30 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.177 2000/10/31 14:20:30 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -2872,6 +2872,7 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
28722872
int i_lanpltrusted;
28732873
int i_lanplcallfoid;
28742874
int i_lancompiler;
2875+
Oid lanoid;
28752876
char *lanname;
28762877
char *lancompiler;
28772878
const char *lanplcallfoid;
@@ -2898,7 +2899,13 @@ dumpProcLangs(Archive *fout, FuncInfo *finfo, int numFuncs,
28982899

28992900
for (i = 0; i < ntups; i++)
29002901
{
2902+
lanoid = atoi(PQgetvalue(res, i, i_oid));
2903+
if (lanoid <= g_last_builtin_oid)
2904+
continue;
2905+
29012906
lanplcallfoid = PQgetvalue(res, i, i_lanplcallfoid);
2907+
2908+
29022909
for (fidx = 0; fidx < numFuncs; fidx++)
29032910
{
29042911
if (!strcmp(finfo[fidx].oid, lanplcallfoid))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy