mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-28 01:21:49 +02:00
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.
This commit is contained in:
parent
dc20063e43
commit
49bf04ba8c
@ -15,7 +15,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.47 2002/05/28 22:26:56 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.48 2002/05/29 01:38:56 tgl Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
||||||
*
|
*
|
||||||
@ -525,14 +525,15 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
|
|||||||
ahprintf(AH, "-- Disable triggers\n");
|
ahprintf(AH, "-- Disable triggers\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Just update the AFFECTED table, if known.
|
* Just update the AFFECTED table, if known. Otherwise update all
|
||||||
|
* non-system tables.
|
||||||
*/
|
*/
|
||||||
if (te && te->name && strlen(te->name) > 0)
|
if (te && te->name && strlen(te->name) > 0)
|
||||||
ahprintf(AH, "UPDATE pg_class SET reltriggers = 0 "
|
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 "
|
||||||
"WHERE oid = '%s'::regclass;\n\n",
|
"WHERE oid = '%s'::pg_catalog.regclass;\n\n",
|
||||||
fmtId(te->name, false));
|
fmtId(te->name, false));
|
||||||
else
|
else
|
||||||
ahprintf(AH, "UPDATE pg_class SET reltriggers = 0 FROM pg_namespace "
|
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 FROM pg_catalog.pg_namespace "
|
||||||
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
|
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -591,17 +592,18 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
|
|||||||
ahprintf(AH, "-- Enable triggers\n");
|
ahprintf(AH, "-- Enable triggers\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Just update the AFFECTED table, if known.
|
* Just update the AFFECTED table, if known. Otherwise update all
|
||||||
|
* non-system tables.
|
||||||
*/
|
*/
|
||||||
if (te && te->name && strlen(te->name) > 0)
|
if (te && te->name && strlen(te->name) > 0)
|
||||||
ahprintf(AH, "UPDATE pg_class SET reltriggers = "
|
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = "
|
||||||
"(SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) "
|
"(SELECT count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) "
|
||||||
"WHERE oid = '%s'::regclass;\n\n",
|
"WHERE oid = '%s'::pg_catalog.regclass;\n\n",
|
||||||
fmtId(te->name, false));
|
fmtId(te->name, false));
|
||||||
else
|
else
|
||||||
ahprintf(AH, "UPDATE pg_class SET reltriggers = "
|
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = "
|
||||||
"(SELECT count(*) FROM pg_trigger where pg_class.oid = tgrelid) "
|
"(SELECT count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) "
|
||||||
"FROM pg_namespace "
|
"FROM pg_catalog.pg_namespace "
|
||||||
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
|
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -856,18 +858,20 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
|
|||||||
void
|
void
|
||||||
EndRestoreBlob(ArchiveHandle *AH, Oid oid)
|
EndRestoreBlob(ArchiveHandle *AH, Oid oid)
|
||||||
{
|
{
|
||||||
if(AH->lo_buf_used > 0) {
|
if (AH->lo_buf_used > 0)
|
||||||
/* Write remaining bytes from the LO buffer */
|
{
|
||||||
int res;
|
/* Write remaining bytes from the LO buffer */
|
||||||
res = lo_write(AH->connection, AH->loFd, (void *) AH->lo_buf, AH->lo_buf_used);
|
int res;
|
||||||
|
|
||||||
ahlog(AH, 5, "wrote remaining %d bytes of large object data (result = %d)\n",
|
res = lo_write(AH->connection, AH->loFd, (void *) AH->lo_buf, AH->lo_buf_used);
|
||||||
(int)AH->lo_buf_used, res);
|
|
||||||
if (res != AH->lo_buf_used)
|
ahlog(AH, 5, "wrote remaining %d bytes of large object data (result = %d)\n",
|
||||||
die_horribly(AH, modulename, "could not write to large object (result: %d, expected: %d)\n",
|
(int)AH->lo_buf_used, res);
|
||||||
res, AH->lo_buf_used);
|
if (res != AH->lo_buf_used)
|
||||||
AH->lo_buf_used = 0;
|
die_horribly(AH, modulename, "could not write to large object (result: %d, expected: %d)\n",
|
||||||
}
|
res, AH->lo_buf_used);
|
||||||
|
AH->lo_buf_used = 0;
|
||||||
|
}
|
||||||
|
|
||||||
lo_close(AH->connection, AH->loFd);
|
lo_close(AH->connection, AH->loFd);
|
||||||
AH->writingBlob = 0;
|
AH->writingBlob = 0;
|
||||||
@ -1444,7 +1448,7 @@ WriteInt(ArchiveHandle *AH, int i)
|
|||||||
for (b = 0; b < AH->intSize; b++)
|
for (b = 0; b < AH->intSize; b++)
|
||||||
{
|
{
|
||||||
(*AH->WriteBytePtr) (AH, i & 0xFF);
|
(*AH->WriteBytePtr) (AH, i & 0xFF);
|
||||||
i = i / 256;
|
i >>= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AH->intSize + 1;
|
return AH->intSize + 1;
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.18 2002/04/24 02:21:04 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.19 2002/05/29 01:38:56 tgl Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
||||||
*
|
*
|
||||||
@ -638,7 +638,7 @@ _PrintData(ArchiveHandle *AH)
|
|||||||
static void
|
static void
|
||||||
_LoadBlobs(ArchiveHandle *AH)
|
_LoadBlobs(ArchiveHandle *AH)
|
||||||
{
|
{
|
||||||
int oid;
|
Oid oid;
|
||||||
|
|
||||||
StartRestoreBlobs(AH);
|
StartRestoreBlobs(AH);
|
||||||
|
|
||||||
@ -664,7 +664,7 @@ _LoadBlobs(ArchiveHandle *AH)
|
|||||||
static void
|
static void
|
||||||
_skipBlobs(ArchiveHandle *AH)
|
_skipBlobs(ArchiveHandle *AH)
|
||||||
{
|
{
|
||||||
int oid;
|
Oid oid;
|
||||||
|
|
||||||
oid = ReadInt(AH);
|
oid = ReadInt(AH);
|
||||||
while (oid != 0)
|
while (oid != 0)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Implements the basic DB functions used by the archiver.
|
* Implements the basic DB functions used by the archiver.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.32 2002/05/10 22:36:26 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.33 2002/05/29 01:38:56 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -729,7 +729,7 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
|
|||||||
appendPQExpBuffer(tblQry,
|
appendPQExpBuffer(tblQry,
|
||||||
"SELECT a.attname FROM "
|
"SELECT a.attname FROM "
|
||||||
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
|
"pg_catalog.pg_attribute a, pg_catalog.pg_type t "
|
||||||
"WHERE a.attnum > 0 AND a.attrelid = '%s'::regclass "
|
"WHERE a.attnum > 0 AND a.attrelid = '%s'::pg_catalog.regclass "
|
||||||
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
|
"AND a.atttypid = t.oid AND t.typname in ('oid', 'lo')",
|
||||||
tblName->data);
|
tblName->data);
|
||||||
|
|
||||||
@ -799,7 +799,7 @@ CreateBlobXrefTable(ArchiveHandle *AH)
|
|||||||
|
|
||||||
ahlog(AH, 1, "creating table for large object cross-references\n");
|
ahlog(AH, 1, "creating table for large object cross-references\n");
|
||||||
|
|
||||||
appendPQExpBuffer(qry, "Create Temporary Table %s(oldOid oid, newOid oid);", BLOB_XREF_TABLE);
|
appendPQExpBuffer(qry, "Create Temporary Table %s(oldOid pg_catalog.oid, newOid pg_catalog.oid);", BLOB_XREF_TABLE);
|
||||||
|
|
||||||
ExecuteSqlCommand(AH, qry, "could not create large object cross-reference table", true);
|
ExecuteSqlCommand(AH, qry, "could not create large object cross-reference table", true);
|
||||||
|
|
||||||
@ -812,11 +812,13 @@ CreateBlobXrefTable(ArchiveHandle *AH)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
InsertBlobXref(ArchiveHandle *AH, int old, int new)
|
InsertBlobXref(ArchiveHandle *AH, Oid old, Oid new)
|
||||||
{
|
{
|
||||||
PQExpBuffer qry = createPQExpBuffer();
|
PQExpBuffer qry = createPQExpBuffer();
|
||||||
|
|
||||||
appendPQExpBuffer(qry, "Insert Into %s(oldOid, newOid) Values (%d, %d);", BLOB_XREF_TABLE, old, new);
|
appendPQExpBuffer(qry,
|
||||||
|
"Insert Into %s(oldOid, newOid) Values ('%u', '%u');",
|
||||||
|
BLOB_XREF_TABLE, old, new);
|
||||||
|
|
||||||
ExecuteSqlCommand(AH, qry, "could not create large object cross-reference entry", true);
|
ExecuteSqlCommand(AH, qry, "could not create large object cross-reference entry", true);
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Definitions for pg_backup_db.c
|
* Definitions for pg_backup_db.c
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.6 2002/05/10 22:36:26 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.7 2002/05/29 01:38:56 tgl Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BLOB_XREF_TABLE "pg_dump_blob_xref" /* MUST be lower case */
|
#define BLOB_XREF_TABLE "pg_dump_blob_xref" /* MUST be lower case */
|
||||||
@ -12,7 +12,7 @@ extern int ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc, boo
|
|||||||
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qry, int bufLen);
|
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qry, int bufLen);
|
||||||
|
|
||||||
extern void CreateBlobXrefTable(ArchiveHandle *AH);
|
extern void CreateBlobXrefTable(ArchiveHandle *AH);
|
||||||
extern void InsertBlobXref(ArchiveHandle *AH, int old, int new);
|
extern void InsertBlobXref(ArchiveHandle *AH, Oid old, Oid new);
|
||||||
extern void StartTransaction(ArchiveHandle *AH);
|
extern void StartTransaction(ArchiveHandle *AH);
|
||||||
extern void StartTransactionXref(ArchiveHandle *AH);
|
extern void StartTransactionXref(ArchiveHandle *AH);
|
||||||
extern void CommitTransaction(ArchiveHandle *AH);
|
extern void CommitTransaction(ArchiveHandle *AH);
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.15 2002/04/24 02:21:04 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.16 2002/05/29 01:38:56 tgl Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
||||||
*
|
*
|
||||||
@ -76,7 +76,7 @@ typedef struct
|
|||||||
|
|
||||||
static char *modulename = gettext_noop("file archiver");
|
static char *modulename = gettext_noop("file archiver");
|
||||||
static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
|
static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
|
||||||
static void _getBlobTocEntry(ArchiveHandle *AH, int *oid, char *fname);
|
static void _getBlobTocEntry(ArchiveHandle *AH, Oid *oid, char *fname);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initializer
|
* Initializer
|
||||||
@ -328,7 +328,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_getBlobTocEntry(ArchiveHandle *AH, int *oid, char fname[K_STD_BUF_SIZE])
|
_getBlobTocEntry(ArchiveHandle *AH, Oid *oid, char fname[K_STD_BUF_SIZE])
|
||||||
{
|
{
|
||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
char blobTe[K_STD_BUF_SIZE];
|
char blobTe[K_STD_BUF_SIZE];
|
||||||
@ -337,7 +337,7 @@ _getBlobTocEntry(ArchiveHandle *AH, int *oid, char fname[K_STD_BUF_SIZE])
|
|||||||
|
|
||||||
if (fgets(&blobTe[0], K_STD_BUF_SIZE - 1, ctx->blobToc) != NULL)
|
if (fgets(&blobTe[0], K_STD_BUF_SIZE - 1, ctx->blobToc) != NULL)
|
||||||
{
|
{
|
||||||
*oid = atoi(blobTe);
|
*oid = atooid(blobTe);
|
||||||
|
|
||||||
fpos = strcspn(blobTe, " ");
|
fpos = strcspn(blobTe, " ");
|
||||||
|
|
||||||
@ -360,7 +360,7 @@ _getBlobTocEntry(ArchiveHandle *AH, int *oid, char fname[K_STD_BUF_SIZE])
|
|||||||
static void
|
static void
|
||||||
_LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
|
_LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
|
||||||
{
|
{
|
||||||
int oid;
|
Oid oid;
|
||||||
lclContext *ctx = (lclContext *) AH->formatData;
|
lclContext *ctx = (lclContext *) AH->formatData;
|
||||||
char fname[K_STD_BUF_SIZE];
|
char fname[K_STD_BUF_SIZE];
|
||||||
|
|
||||||
@ -509,9 +509,9 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
|
|||||||
sfx = "";
|
sfx = "";
|
||||||
|
|
||||||
sprintf(fmode, "wb%d", AH->compression);
|
sprintf(fmode, "wb%d", AH->compression);
|
||||||
sprintf(fname, "blob_%d.dat%s", oid, sfx);
|
sprintf(fname, "blob_%u.dat%s", oid, sfx);
|
||||||
|
|
||||||
fprintf(ctx->blobToc, "%d %s\n", oid, fname);
|
fprintf(ctx->blobToc, "%u %s\n", oid, fname);
|
||||||
|
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
tctx->FH = gzopen(fname, fmode);
|
tctx->FH = gzopen(fname, fmode);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.22 2002/05/10 22:36:26 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.23 2002/05/29 01:38:56 tgl Exp $
|
||||||
*
|
*
|
||||||
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
|
||||||
*
|
*
|
||||||
@ -666,34 +666,6 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
|
|||||||
_PrintFileData(AH, tctx->filename, ropt);
|
_PrintFileData(AH, tctx->filename, ropt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static void _getBlobTocEntry(ArchiveHandle* AH, int *oid, char fname[K_STD_BUF_SIZE])
|
|
||||||
* {
|
|
||||||
* lclContext* ctx = (lclContext*)AH->formatData;
|
|
||||||
* char blobTe[K_STD_BUF_SIZE];
|
|
||||||
* int fpos;
|
|
||||||
* int eos;
|
|
||||||
*
|
|
||||||
* if (tarGets(&blobTe[0], K_STD_BUF_SIZE - 1, ctx->blobToc) != NULL)
|
|
||||||
* {
|
|
||||||
* *oid = atoi(blobTe);
|
|
||||||
*
|
|
||||||
* fpos = strcspn(blobTe, " ");
|
|
||||||
*
|
|
||||||
* strncpy(fname, &blobTe[fpos+1], K_STD_BUF_SIZE - 1);
|
|
||||||
*
|
|
||||||
* eos = strlen(fname)-1;
|
|
||||||
*
|
|
||||||
* if (fname[eos] == '\n')
|
|
||||||
* fname[eos] = '\0';
|
|
||||||
*
|
|
||||||
* } else {
|
|
||||||
*
|
|
||||||
* *oid = 0;
|
|
||||||
* fname[0] = '\0';
|
|
||||||
* }
|
|
||||||
*}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
|
_LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
|
||||||
{
|
{
|
||||||
@ -710,20 +682,22 @@ _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
|
|||||||
{
|
{
|
||||||
ctx->FH = th;
|
ctx->FH = th;
|
||||||
|
|
||||||
oid = (Oid) strtoul(&th->targetFile[5], NULL, 10);
|
if (strncmp(th->targetFile, "blob_", 5) == 0)
|
||||||
|
|
||||||
if (strncmp(th->targetFile, "blob_", 5) == 0 && oid != 0)
|
|
||||||
{
|
{
|
||||||
ahlog(AH, 1, "restoring large object OID %u\n", oid);
|
oid = atooid(&th->targetFile[5]);
|
||||||
|
if (oid != 0)
|
||||||
StartRestoreBlob(AH, oid);
|
|
||||||
|
|
||||||
while ((cnt = tarRead(buf, 4095, th)) > 0)
|
|
||||||
{
|
{
|
||||||
buf[cnt] = '\0';
|
ahlog(AH, 1, "restoring large object OID %u\n", oid);
|
||||||
ahwrite(buf, 1, cnt, AH);
|
|
||||||
|
StartRestoreBlob(AH, oid);
|
||||||
|
|
||||||
|
while ((cnt = tarRead(buf, 4095, th)) > 0)
|
||||||
|
{
|
||||||
|
buf[cnt] = '\0';
|
||||||
|
ahwrite(buf, 1, cnt, AH);
|
||||||
|
}
|
||||||
|
EndRestoreBlob(AH, oid);
|
||||||
}
|
}
|
||||||
EndRestoreBlob(AH, oid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tarClose(AH, th);
|
tarClose(AH, th);
|
||||||
@ -916,9 +890,9 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
|
|||||||
else
|
else
|
||||||
sfx = "";
|
sfx = "";
|
||||||
|
|
||||||
sprintf(fname, "blob_%d.dat%s", oid, sfx);
|
sprintf(fname, "blob_%u.dat%s", oid, sfx);
|
||||||
|
|
||||||
tarPrintf(AH, ctx->blobToc, "%d %s\n", oid, fname);
|
tarPrintf(AH, ctx->blobToc, "%u %s\n", oid, fname);
|
||||||
|
|
||||||
tctx->TH = tarOpen(AH, fname, 'w');
|
tctx->TH = tarOpen(AH, fname, 'w');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user