From ef88199f611e625b496ff92aa17a447d254b9796 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 3 Oct 2003 20:10:59 +0000 Subject: [PATCH] Issue 'SET check_function_bodies = false' to suppress possible restore failures in SQL functions, due to forward references or unqualified references to objects in other schemas. Per recent discussion. --- src/bin/pg_dump/pg_backup_archiver.c | 12 +++++++++++- src/bin/pg_dump/pg_backup_archiver.h | 10 +++++++--- src/bin/pg_dump/pg_backup_db.c | 7 +------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index a2181ce772..7096df3b95 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.77 2003/09/23 23:31:52 tgl Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.78 2003/10/03 20:10:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1708,6 +1708,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, AH->currUser = strdup(""); /* So it's valid, but we can free() it * later if necessary */ AH->currSchema = strdup(""); /* ditto */ + AH->chk_fn_bodies = true; /* assumed default state */ AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry)); if (!AH->toc) @@ -2103,6 +2104,8 @@ _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user) if (AH->currSchema) free(AH->currSchema); AH->currSchema = strdup(""); + + AH->chk_fn_bodies = true; /* assumed default state */ } /* @@ -2198,6 +2201,13 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat _becomeOwner(AH, te); _selectOutputSchema(AH, te->namespace); + /* If it's a function, make sure function checking is disabled */ + if (AH->chk_fn_bodies && strcmp(te->desc, "FUNCTION") == 0) + { + ahprintf(AH, "SET check_function_bodies = false;\n\n"); + AH->chk_fn_bodies = false; + } + if (isData) pfx = "Data for "; else diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h index f893a3ba7f..fbfbba988e 100644 --- a/src/bin/pg_dump/pg_backup_archiver.h +++ b/src/bin/pg_dump/pg_backup_archiver.h @@ -17,7 +17,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.51 2003/08/04 00:43:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.52 2003/10/03 20:10:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -231,14 +231,18 @@ typedef struct _archiveHandle struct _tocEntry *toc; /* List of TOC entries */ int tocCount; /* Number of TOC entries */ struct _tocEntry *currToc; /* Used when dumping data */ - char *currUser; /* Restore: current username in script */ - char *currSchema; /* Restore: current schema in script */ int compression; /* Compression requested on open */ ArchiveMode mode; /* File mode - r or w */ void *formatData; /* Header data specific to file format */ RestoreOptions *ropt; /* Used to check restore options in * ahwrite etc */ + + /* these vars track state to avoid sending redundant SET commands */ + char *currUser; /* current username */ + char *currSchema; /* current schema */ + bool chk_fn_bodies; /* current state of check_function_bodies */ + void *lo_buf; size_t lo_buf_used; size_t lo_buf_size; diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index ae3d9cc14a..cab9d7830b 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -5,7 +5,7 @@ * Implements the basic DB functions used by the archiver. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.49 2003/07/23 08:47:30 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.50 2003/10/03 20:10:59 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -116,11 +116,6 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username) PQfinish(AH->connection); AH->connection = newConn; - /* don't assume we still know the output schema */ - if (AH->currSchema) - free(AH->currSchema); - AH->currSchema = strdup(""); - return 1; }