Commit 3b157cf2 authored by Robert Haas's avatar Robert Haas

pg_dump: Remove global Archive pointer.

Instead, everything that needs the Archive object now gets it as a
parameter.  This is necessary infrastructure for parallel pg_dump,
but is also amply justified by the ugliness of the current code
(though a lot more than this is needed to fix that problem).
parent 622f8628
...@@ -76,7 +76,7 @@ static int strInArray(const char *pattern, char **arr, int arr_size); ...@@ -76,7 +76,7 @@ static int strInArray(const char *pattern, char **arr, int arr_size);
* Collect information about all potentially dumpable objects * Collect information about all potentially dumpable objects
*/ */
TableInfo * TableInfo *
getSchemaData(int *numTablesPtr) getSchemaData(Archive *fout, int *numTablesPtr)
{ {
ExtensionInfo *extinfo; ExtensionInfo *extinfo;
InhInfo *inhinfo; InhInfo *inhinfo;
...@@ -101,7 +101,7 @@ getSchemaData(int *numTablesPtr) ...@@ -101,7 +101,7 @@ getSchemaData(int *numTablesPtr)
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading schemas\n"); write_msg(NULL, "reading schemas\n");
getNamespaces(&numNamespaces); getNamespaces(fout, &numNamespaces);
/* /*
* getTables should be done as soon as possible, so as to minimize the * getTables should be done as soon as possible, so as to minimize the
...@@ -111,94 +111,94 @@ getSchemaData(int *numTablesPtr) ...@@ -111,94 +111,94 @@ getSchemaData(int *numTablesPtr)
*/ */
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined tables\n"); write_msg(NULL, "reading user-defined tables\n");
tblinfo = getTables(&numTables); tblinfo = getTables(fout, &numTables);
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo)); tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading extensions\n"); write_msg(NULL, "reading extensions\n");
extinfo = getExtensions(&numExtensions); extinfo = getExtensions(fout, &numExtensions);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined functions\n"); write_msg(NULL, "reading user-defined functions\n");
funinfo = getFuncs(&numFuncs); funinfo = getFuncs(fout, &numFuncs);
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo)); funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
/* this must be after getTables and getFuncs */ /* this must be after getTables and getFuncs */
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined types\n"); write_msg(NULL, "reading user-defined types\n");
typinfo = getTypes(&numTypes); typinfo = getTypes(fout, &numTypes);
typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo)); typinfoindex = buildIndexArray(typinfo, numTypes, sizeof(TypeInfo));
/* this must be after getFuncs, too */ /* this must be after getFuncs, too */
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading procedural languages\n"); write_msg(NULL, "reading procedural languages\n");
getProcLangs(&numProcLangs); getProcLangs(fout, &numProcLangs);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined aggregate functions\n"); write_msg(NULL, "reading user-defined aggregate functions\n");
getAggregates(&numAggregates); getAggregates(fout, &numAggregates);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined operators\n"); write_msg(NULL, "reading user-defined operators\n");
oprinfo = getOperators(&numOperators); oprinfo = getOperators(fout, &numOperators);
oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo)); oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo));
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined operator classes\n"); write_msg(NULL, "reading user-defined operator classes\n");
getOpclasses(&numOpclasses); getOpclasses(fout, &numOpclasses);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined operator families\n"); write_msg(NULL, "reading user-defined operator families\n");
getOpfamilies(&numOpfamilies); getOpfamilies(fout, &numOpfamilies);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined text search parsers\n"); write_msg(NULL, "reading user-defined text search parsers\n");
getTSParsers(&numTSParsers); getTSParsers(fout, &numTSParsers);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined text search templates\n"); write_msg(NULL, "reading user-defined text search templates\n");
getTSTemplates(&numTSTemplates); getTSTemplates(fout, &numTSTemplates);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined text search dictionaries\n"); write_msg(NULL, "reading user-defined text search dictionaries\n");
getTSDictionaries(&numTSDicts); getTSDictionaries(fout, &numTSDicts);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined text search configurations\n"); write_msg(NULL, "reading user-defined text search configurations\n");
getTSConfigurations(&numTSConfigs); getTSConfigurations(fout, &numTSConfigs);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined foreign-data wrappers\n"); write_msg(NULL, "reading user-defined foreign-data wrappers\n");
getForeignDataWrappers(&numForeignDataWrappers); getForeignDataWrappers(fout, &numForeignDataWrappers);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined foreign servers\n"); write_msg(NULL, "reading user-defined foreign servers\n");
getForeignServers(&numForeignServers); getForeignServers(fout, &numForeignServers);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading default privileges\n"); write_msg(NULL, "reading default privileges\n");
getDefaultACLs(&numDefaultACLs); getDefaultACLs(fout, &numDefaultACLs);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined collations\n"); write_msg(NULL, "reading user-defined collations\n");
collinfo = getCollations(&numCollations); collinfo = getCollations(fout, &numCollations);
collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo)); collinfoindex = buildIndexArray(collinfo, numCollations, sizeof(CollInfo));
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined conversions\n"); write_msg(NULL, "reading user-defined conversions\n");
getConversions(&numConversions); getConversions(fout, &numConversions);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading type casts\n"); write_msg(NULL, "reading type casts\n");
getCasts(&numCasts); getCasts(fout, &numCasts);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading table inheritance information\n"); write_msg(NULL, "reading table inheritance information\n");
inhinfo = getInherits(&numInherits); inhinfo = getInherits(fout, &numInherits);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading rewrite rules\n"); write_msg(NULL, "reading rewrite rules\n");
getRules(&numRules); getRules(fout, &numRules);
/* /*
* Identify extension member objects and mark them as not to be dumped. * Identify extension member objects and mark them as not to be dumped.
...@@ -207,7 +207,7 @@ getSchemaData(int *numTablesPtr) ...@@ -207,7 +207,7 @@ getSchemaData(int *numTablesPtr)
*/ */
if (g_verbose) if (g_verbose)
write_msg(NULL, "finding extension members\n"); write_msg(NULL, "finding extension members\n");
getExtensionMembership(extinfo, numExtensions); getExtensionMembership(fout, extinfo, numExtensions);
/* Link tables to parents, mark parents of target tables interesting */ /* Link tables to parents, mark parents of target tables interesting */
if (g_verbose) if (g_verbose)
...@@ -216,7 +216,7 @@ getSchemaData(int *numTablesPtr) ...@@ -216,7 +216,7 @@ getSchemaData(int *numTablesPtr)
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading column info for interesting tables\n"); write_msg(NULL, "reading column info for interesting tables\n");
getTableAttrs(tblinfo, numTables); getTableAttrs(fout, tblinfo, numTables);
if (g_verbose) if (g_verbose)
write_msg(NULL, "flagging inherited columns in subtables\n"); write_msg(NULL, "flagging inherited columns in subtables\n");
...@@ -224,15 +224,15 @@ getSchemaData(int *numTablesPtr) ...@@ -224,15 +224,15 @@ getSchemaData(int *numTablesPtr)
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading indexes\n"); write_msg(NULL, "reading indexes\n");
getIndexes(tblinfo, numTables); getIndexes(fout, tblinfo, numTables);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading constraints\n"); write_msg(NULL, "reading constraints\n");
getConstraints(tblinfo, numTables); getConstraints(fout, tblinfo, numTables);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading triggers\n"); write_msg(NULL, "reading triggers\n");
getTriggers(tblinfo, numTables); getTriggers(fout, tblinfo, numTables);
*numTablesPtr = numTables; *numTablesPtr = numTables;
return tblinfo; return tblinfo;
......
...@@ -81,7 +81,7 @@ typedef enum ...@@ -81,7 +81,7 @@ typedef enum
* We may want to have some more user-readable data, but in the mean * We may want to have some more user-readable data, but in the mean
* time this gives us some abstraction and type checking. * time this gives us some abstraction and type checking.
*/ */
typedef struct _Archive struct Archive
{ {
int verbose; int verbose;
char *remoteVersionStr; /* server's version string */ char *remoteVersionStr; /* server's version string */
...@@ -99,7 +99,7 @@ typedef struct _Archive ...@@ -99,7 +99,7 @@ typedef struct _Archive
int n_errors; /* number of errors (if no die) */ int n_errors; /* number of errors (if no die) */
/* The rest is private */ /* The rest is private */
} Archive; };
typedef int (*DataDumperPtr) (Archive *AH, void *userArg); typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
......
...@@ -85,7 +85,6 @@ typedef struct ...@@ -85,7 +85,6 @@ typedef struct
/* global decls */ /* global decls */
bool g_verbose; /* User wants verbose narration of our bool g_verbose; /* User wants verbose narration of our
* activities. */ * activities. */
Archive *g_fout; /* the script file */
PGconn *g_conn; /* the database connection */ PGconn *g_conn; /* the database connection */
/* various user-settable parameters */ /* various user-settable parameters */
...@@ -148,11 +147,12 @@ static void help(const char *progname); ...@@ -148,11 +147,12 @@ static void help(const char *progname);
static void setup_connection(Archive *AH, const char *dumpencoding, static void setup_connection(Archive *AH, const char *dumpencoding,
char *use_role); char *use_role);
static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode); static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode);
static void expand_schema_name_patterns(SimpleStringList *patterns, static void expand_schema_name_patterns(Archive *fout,
SimpleStringList *patterns,
SimpleOidList *oids); SimpleOidList *oids);
static void expand_table_name_patterns(SimpleStringList *patterns, static void expand_table_name_patterns(SimpleStringList *patterns,
SimpleOidList *oids); SimpleOidList *oids);
static NamespaceInfo *findNamespace(Oid nsoid, Oid objoid); static NamespaceInfo *findNamespace(Archive *fout, Oid nsoid, Oid objoid);
static void dumpTableData(Archive *fout, TableDataInfo *tdinfo); static void dumpTableData(Archive *fout, TableDataInfo *tdinfo);
static void guessConstraintInheritance(TableInfo *tblinfo, int numTables); static void guessConstraintInheritance(TableInfo *tblinfo, int numTables);
static void dumpComment(Archive *fout, const char *target, static void dumpComment(Archive *fout, const char *target,
...@@ -212,29 +212,33 @@ static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, ...@@ -212,29 +212,33 @@ static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
const char *tag, const char *nspname, const char *owner, const char *tag, const char *nspname, const char *owner,
const char *acls); const char *acls);
static void getDependencies(void); static void getDependencies(Archive *fout);
static void getDomainConstraints(TypeInfo *tyinfo); static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo);
static void getTableData(TableInfo *tblinfo, int numTables, bool oids); static void getTableData(TableInfo *tblinfo, int numTables, bool oids);
static void makeTableDataInfo(TableInfo *tbinfo, bool oids); static void makeTableDataInfo(TableInfo *tbinfo, bool oids);
static void getTableDataFKConstraints(void); static void getTableDataFKConstraints(void);
static char *format_function_arguments(FuncInfo *finfo, char *funcargs); static char *format_function_arguments(FuncInfo *finfo, char *funcargs);
static char *format_function_arguments_old(FuncInfo *finfo, int nallargs, static char *format_function_arguments_old(Archive *fout,
FuncInfo *finfo, int nallargs,
char **allargtypes, char **allargtypes,
char **argmodes, char **argmodes,
char **argnames); char **argnames);
static char *format_function_signature(FuncInfo *finfo, bool honor_quotes); static char *format_function_signature(Archive *fout,
static const char *convertRegProcReference(const char *proc); FuncInfo *finfo, bool honor_quotes);
static const char *convertOperatorReference(const char *opr); static const char *convertRegProcReference(Archive *fout,
const char *proc);
static const char *convertOperatorReference(Archive *fout, const char *opr);
static const char *convertTSFunction(Oid funcOid); static const char *convertTSFunction(Oid funcOid);
static Oid findLastBuiltinOid_V71(const char *); static Oid findLastBuiltinOid_V71(Archive *fout, const char *);
static Oid findLastBuiltinOid_V70(void); static Oid findLastBuiltinOid_V70(void);
static void selectSourceSchema(const char *schemaName); static void selectSourceSchema(Archive *fout, const char *schemaName);
static char *getFormattedTypeName(Oid oid, OidOptions opts); static char *getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts);
static char *myFormatType(const char *typname, int32 typmod); static char *myFormatType(const char *typname, int32 typmod);
static const char *fmtQualifiedId(const char *schema, const char *id); static const char *fmtQualifiedId(Archive *fout,
static void getBlobs(Archive *AH); const char *schema, const char *id);
static void dumpBlob(Archive *AH, BlobInfo *binfo); static void getBlobs(Archive *fout);
static int dumpBlobs(Archive *AH, void *arg); static void dumpBlob(Archive *fout, BlobInfo *binfo);
static int dumpBlobs(Archive *fout, void *arg);
static void dumpDatabase(Archive *AH); static void dumpDatabase(Archive *AH);
static void dumpEncoding(Archive *AH); static void dumpEncoding(Archive *AH);
static void dumpStdStrings(Archive *AH); static void dumpStdStrings(Archive *AH);
...@@ -284,6 +288,7 @@ main(int argc, char **argv) ...@@ -284,6 +288,7 @@ main(int argc, char **argv)
RestoreOptions *ropt; RestoreOptions *ropt;
ArchiveFormat archiveFormat = archUnknown; ArchiveFormat archiveFormat = archUnknown;
ArchiveMode archiveMode; ArchiveMode archiveMode;
Archive *fout; /* the script file */
static int disable_triggers = 0; static int disable_triggers = 0;
static int outputNoTablespaces = 0; static int outputNoTablespaces = 0;
...@@ -577,16 +582,16 @@ main(int argc, char **argv) ...@@ -577,16 +582,16 @@ main(int argc, char **argv)
} }
/* Open the output file */ /* Open the output file */
g_fout = CreateArchive(filename, archiveFormat, compressLevel, archiveMode); fout = CreateArchive(filename, archiveFormat, compressLevel, archiveMode);
if (g_fout == NULL) if (fout == NULL)
{ {
write_msg(NULL, "could not open output file \"%s\" for writing\n", filename); write_msg(NULL, "could not open output file \"%s\" for writing\n", filename);
exit(1); exit(1);
} }
/* Let the archiver know how noisy to be */ /* Let the archiver know how noisy to be */
g_fout->verbose = g_verbose; fout->verbose = g_verbose;
my_version = parse_version(PG_VERSION); my_version = parse_version(PG_VERSION);
if (my_version < 0) if (my_version < 0)
...@@ -599,30 +604,30 @@ main(int argc, char **argv) ...@@ -599,30 +604,30 @@ main(int argc, char **argv)
* We allow the server to be back to 7.0, and up to any minor release of * We allow the server to be back to 7.0, and up to any minor release of
* our own major version. (See also version check in pg_dumpall.c.) * our own major version. (See also version check in pg_dumpall.c.)
*/ */
g_fout->minRemoteVersion = 70000; fout->minRemoteVersion = 70000;
g_fout->maxRemoteVersion = (my_version / 100) * 100 + 99; fout->maxRemoteVersion = (my_version / 100) * 100 + 99;
/* /*
* Open the database using the Archiver, so it knows about it. Errors mean * Open the database using the Archiver, so it knows about it. Errors mean
* death. * death.
*/ */
g_conn = ConnectDatabase(g_fout, dbname, pghost, pgport, g_conn = ConnectDatabase(fout, dbname, pghost, pgport,
username, prompt_password); username, prompt_password);
setup_connection(g_fout, dumpencoding, use_role); setup_connection(fout, dumpencoding, use_role);
/* /*
* Disable security label support if server version < v9.1.x (prevents * Disable security label support if server version < v9.1.x (prevents
* access to nonexistent pg_seclabel catalog) * access to nonexistent pg_seclabel catalog)
*/ */
if (g_fout->remoteVersion < 90100) if (fout->remoteVersion < 90100)
no_security_labels = 1; no_security_labels = 1;
/* /*
* Start transaction-snapshot mode transaction to dump consistent data. * Start transaction-snapshot mode transaction to dump consistent data.
*/ */
do_sql_command(g_conn, "BEGIN"); do_sql_command(g_conn, "BEGIN");
if (g_fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
{ {
if (serializable_deferrable) if (serializable_deferrable)
do_sql_command(g_conn, do_sql_command(g_conn,
...@@ -636,18 +641,18 @@ main(int argc, char **argv) ...@@ -636,18 +641,18 @@ main(int argc, char **argv)
do_sql_command(g_conn, "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); do_sql_command(g_conn, "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE");
/* Select the appropriate subquery to convert user IDs to names */ /* Select the appropriate subquery to convert user IDs to names */
if (g_fout->remoteVersion >= 80100) if (fout->remoteVersion >= 80100)
username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid ="; username_subquery = "SELECT rolname FROM pg_catalog.pg_roles WHERE oid =";
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
username_subquery = "SELECT usename FROM pg_catalog.pg_user WHERE usesysid ="; username_subquery = "SELECT usename FROM pg_catalog.pg_user WHERE usesysid =";
else else
username_subquery = "SELECT usename FROM pg_user WHERE usesysid ="; username_subquery = "SELECT usename FROM pg_user WHERE usesysid =";
/* Find the last built-in OID, if needed */ /* Find the last built-in OID, if needed */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
if (g_fout->remoteVersion >= 70100) if (fout->remoteVersion >= 70100)
g_last_builtin_oid = findLastBuiltinOid_V71(PQdb(g_conn)); g_last_builtin_oid = findLastBuiltinOid_V71(fout, PQdb(g_conn));
else else
g_last_builtin_oid = findLastBuiltinOid_V70(); g_last_builtin_oid = findLastBuiltinOid_V70();
if (g_verbose) if (g_verbose)
...@@ -657,7 +662,7 @@ main(int argc, char **argv) ...@@ -657,7 +662,7 @@ main(int argc, char **argv)
/* Expand schema selection patterns into OID lists */ /* Expand schema selection patterns into OID lists */
if (schema_include_patterns.head != NULL) if (schema_include_patterns.head != NULL)
{ {
expand_schema_name_patterns(&schema_include_patterns, expand_schema_name_patterns(fout, &schema_include_patterns,
&schema_include_oids); &schema_include_oids);
if (schema_include_oids.head == NULL) if (schema_include_oids.head == NULL)
{ {
...@@ -665,7 +670,7 @@ main(int argc, char **argv) ...@@ -665,7 +670,7 @@ main(int argc, char **argv)
exit_nicely(); exit_nicely();
} }
} }
expand_schema_name_patterns(&schema_exclude_patterns, expand_schema_name_patterns(fout, &schema_exclude_patterns,
&schema_exclude_oids); &schema_exclude_oids);
/* non-matching exclusion patterns aren't an error */ /* non-matching exclusion patterns aren't an error */
...@@ -699,9 +704,9 @@ main(int argc, char **argv) ...@@ -699,9 +704,9 @@ main(int argc, char **argv)
* Now scan the database and create DumpableObject structs for all the * Now scan the database and create DumpableObject structs for all the
* objects we intend to dump. * objects we intend to dump.
*/ */
tblinfo = getSchemaData(&numTables); tblinfo = getSchemaData(fout, &numTables);
if (g_fout->remoteVersion < 80400) if (fout->remoteVersion < 80400)
guessConstraintInheritance(tblinfo, numTables); guessConstraintInheritance(tblinfo, numTables);
if (!schemaOnly) if (!schemaOnly)
...@@ -712,12 +717,12 @@ main(int argc, char **argv) ...@@ -712,12 +717,12 @@ main(int argc, char **argv)
} }
if (outputBlobs) if (outputBlobs)
getBlobs(g_fout); getBlobs(fout);
/* /*
* Collect dependency data to assist in ordering the objects. * Collect dependency data to assist in ordering the objects.
*/ */
getDependencies(); getDependencies(fout);
/* /*
* Sort the objects into a safe dump order (no forward references). * Sort the objects into a safe dump order (no forward references).
...@@ -730,7 +735,7 @@ main(int argc, char **argv) ...@@ -730,7 +735,7 @@ main(int argc, char **argv)
*/ */
getDumpableObjects(&dobjs, &numObjs); getDumpableObjects(&dobjs, &numObjs);
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
sortDumpableObjectsByTypeName(dobjs, numObjs); sortDumpableObjectsByTypeName(dobjs, numObjs);
else else
sortDumpableObjectsByTypeOid(dobjs, numObjs); sortDumpableObjectsByTypeOid(dobjs, numObjs);
...@@ -743,16 +748,16 @@ main(int argc, char **argv) ...@@ -743,16 +748,16 @@ main(int argc, char **argv)
*/ */
/* First the special ENCODING and STDSTRINGS entries. */ /* First the special ENCODING and STDSTRINGS entries. */
dumpEncoding(g_fout); dumpEncoding(fout);
dumpStdStrings(g_fout); dumpStdStrings(fout);
/* The database item is always next, unless we don't want it at all */ /* The database item is always next, unless we don't want it at all */
if (include_everything && !dataOnly) if (include_everything && !dataOnly)
dumpDatabase(g_fout); dumpDatabase(fout);
/* Now the rearrangeable objects. */ /* Now the rearrangeable objects. */
for (i = 0; i < numObjs; i++) for (i = 0; i < numObjs; i++)
dumpDumpableObject(g_fout, dobjs[i]); dumpDumpableObject(fout, dobjs[i]);
/* /*
* And finally we can do the actual output. * And finally we can do the actual output.
...@@ -778,10 +783,10 @@ main(int argc, char **argv) ...@@ -778,10 +783,10 @@ main(int argc, char **argv)
ropt->suppressDumpWarnings = true; /* We've already shown them */ ropt->suppressDumpWarnings = true; /* We've already shown them */
RestoreArchive(g_fout, ropt); RestoreArchive(fout, ropt);
} }
CloseArchive(g_fout); CloseArchive(fout);
PQfinish(g_conn); PQfinish(g_conn);
...@@ -980,7 +985,9 @@ parseArchiveFormat(const char *format, ArchiveMode *mode) ...@@ -980,7 +985,9 @@ parseArchiveFormat(const char *format, ArchiveMode *mode)
* and append them to the given OID list. * and append them to the given OID list.
*/ */
static void static void
expand_schema_name_patterns(SimpleStringList *patterns, SimpleOidList *oids) expand_schema_name_patterns(Archive *fout,
SimpleStringList *patterns,
SimpleOidList *oids)
{ {
PQExpBuffer query; PQExpBuffer query;
PGresult *res; PGresult *res;
...@@ -990,7 +997,7 @@ expand_schema_name_patterns(SimpleStringList *patterns, SimpleOidList *oids) ...@@ -990,7 +997,7 @@ expand_schema_name_patterns(SimpleStringList *patterns, SimpleOidList *oids)
if (patterns->head == NULL) if (patterns->head == NULL)
return; /* nothing to do */ return; /* nothing to do */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
write_msg(NULL, "server version must be at least 7.3 to use schema selection switches\n"); write_msg(NULL, "server version must be at least 7.3 to use schema selection switches\n");
exit_nicely(); exit_nicely();
...@@ -1281,7 +1288,7 @@ dumpTableData_copy(Archive *fout, void *dcontext) ...@@ -1281,7 +1288,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
* this ensures reproducible results in case the table contains regproc, * this ensures reproducible results in case the table contains regproc,
* regclass, etc columns. * regclass, etc columns.
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
/* /*
* If possible, specify the column list explicitly so that we have no * If possible, specify the column list explicitly so that we have no
...@@ -1297,7 +1304,8 @@ dumpTableData_copy(Archive *fout, void *dcontext) ...@@ -1297,7 +1304,8 @@ dumpTableData_copy(Archive *fout, void *dcontext)
if (oids && hasoids) if (oids && hasoids)
{ {
appendPQExpBuffer(q, "COPY %s %s WITH OIDS TO stdout;", appendPQExpBuffer(q, "COPY %s %s WITH OIDS TO stdout;",
fmtQualifiedId(tbinfo->dobj.namespace->dobj.name, fmtQualifiedId(fout,
tbinfo->dobj.namespace->dobj.name,
classname), classname),
column_list); column_list);
} }
...@@ -1314,14 +1322,16 @@ dumpTableData_copy(Archive *fout, void *dcontext) ...@@ -1314,14 +1322,16 @@ dumpTableData_copy(Archive *fout, void *dcontext)
else else
appendPQExpBufferStr(q, "* "); appendPQExpBufferStr(q, "* ");
appendPQExpBuffer(q, "FROM %s %s) TO stdout;", appendPQExpBuffer(q, "FROM %s %s) TO stdout;",
fmtQualifiedId(tbinfo->dobj.namespace->dobj.name, fmtQualifiedId(fout,
tbinfo->dobj.namespace->dobj.name,
classname), classname),
tdinfo->filtercond); tdinfo->filtercond);
} }
else else
{ {
appendPQExpBuffer(q, "COPY %s %s TO stdout;", appendPQExpBuffer(q, "COPY %s %s TO stdout;",
fmtQualifiedId(tbinfo->dobj.namespace->dobj.name, fmtQualifiedId(fout,
tbinfo->dobj.namespace->dobj.name,
classname), classname),
column_list); column_list);
} }
...@@ -1434,20 +1444,22 @@ dumpTableData_insert(Archive *fout, void *dcontext) ...@@ -1434,20 +1444,22 @@ dumpTableData_insert(Archive *fout, void *dcontext)
* this ensures reproducible results in case the table contains regproc, * this ensures reproducible results in case the table contains regproc,
* regclass, etc columns. * regclass, etc columns.
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
if (fout->remoteVersion >= 70100) if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR " appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR "
"SELECT * FROM ONLY %s", "SELECT * FROM ONLY %s",
fmtQualifiedId(tbinfo->dobj.namespace->dobj.name, fmtQualifiedId(fout,
tbinfo->dobj.namespace->dobj.name,
classname)); classname));
} }
else else
{ {
appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR " appendPQExpBuffer(q, "DECLARE _pg_dump_cursor CURSOR FOR "
"SELECT * FROM %s", "SELECT * FROM %s",
fmtQualifiedId(tbinfo->dobj.namespace->dobj.name, fmtQualifiedId(fout,
tbinfo->dobj.namespace->dobj.name,
classname)); classname));
} }
if (tdinfo->filtercond) if (tdinfo->filtercond)
...@@ -1802,7 +1814,7 @@ guessConstraintInheritance(TableInfo *tblinfo, int numTables) ...@@ -1802,7 +1814,7 @@ guessConstraintInheritance(TableInfo *tblinfo, int numTables)
* dump the database definition * dump the database definition
*/ */
static void static void
dumpDatabase(Archive *AH) dumpDatabase(Archive *fout)
{ {
PQExpBuffer dbQry = createPQExpBuffer(); PQExpBuffer dbQry = createPQExpBuffer();
PQExpBuffer delQry = createPQExpBuffer(); PQExpBuffer delQry = createPQExpBuffer();
...@@ -1833,10 +1845,10 @@ dumpDatabase(Archive *AH) ...@@ -1833,10 +1845,10 @@ dumpDatabase(Archive *AH)
write_msg(NULL, "saving database definition\n"); write_msg(NULL, "saving database definition\n");
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* Get the database owner and parameters from pg_database */ /* Get the database owner and parameters from pg_database */
if (g_fout->remoteVersion >= 80400) if (fout->remoteVersion >= 80400)
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
...@@ -1848,9 +1860,9 @@ dumpDatabase(Archive *AH) ...@@ -1848,9 +1860,9 @@ dumpDatabase(Archive *AH)
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, AH); appendStringLiteralAH(dbQry, datname, fout);
} }
else if (g_fout->remoteVersion >= 80200) else if (fout->remoteVersion >= 80200)
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
...@@ -1862,9 +1874,9 @@ dumpDatabase(Archive *AH) ...@@ -1862,9 +1874,9 @@ dumpDatabase(Archive *AH)
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, AH); appendStringLiteralAH(dbQry, datname, fout);
} }
else if (g_fout->remoteVersion >= 80000) else if (fout->remoteVersion >= 80000)
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
...@@ -1874,9 +1886,9 @@ dumpDatabase(Archive *AH) ...@@ -1874,9 +1886,9 @@ dumpDatabase(Archive *AH)
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, AH); appendStringLiteralAH(dbQry, datname, fout);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(dbQry, "SELECT tableoid, oid, " appendPQExpBuffer(dbQry, "SELECT tableoid, oid, "
"(%s datdba) AS dba, " "(%s datdba) AS dba, "
...@@ -1887,7 +1899,7 @@ dumpDatabase(Archive *AH) ...@@ -1887,7 +1899,7 @@ dumpDatabase(Archive *AH)
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, AH); appendStringLiteralAH(dbQry, datname, fout);
} }
else else
{ {
...@@ -1902,7 +1914,7 @@ dumpDatabase(Archive *AH) ...@@ -1902,7 +1914,7 @@ dumpDatabase(Archive *AH)
"FROM pg_database " "FROM pg_database "
"WHERE datname = ", "WHERE datname = ",
username_subquery); username_subquery);
appendStringLiteralAH(dbQry, datname, AH); appendStringLiteralAH(dbQry, datname, fout);
} }
res = PQexec(g_conn, dbQry->data); res = PQexec(g_conn, dbQry->data);
...@@ -1947,17 +1959,17 @@ dumpDatabase(Archive *AH) ...@@ -1947,17 +1959,17 @@ dumpDatabase(Archive *AH)
if (strlen(encoding) > 0) if (strlen(encoding) > 0)
{ {
appendPQExpBuffer(creaQry, " ENCODING = "); appendPQExpBuffer(creaQry, " ENCODING = ");
appendStringLiteralAH(creaQry, encoding, AH); appendStringLiteralAH(creaQry, encoding, fout);
} }
if (strlen(collate) > 0) if (strlen(collate) > 0)
{ {
appendPQExpBuffer(creaQry, " LC_COLLATE = "); appendPQExpBuffer(creaQry, " LC_COLLATE = ");
appendStringLiteralAH(creaQry, collate, AH); appendStringLiteralAH(creaQry, collate, fout);
} }
if (strlen(ctype) > 0) if (strlen(ctype) > 0)
{ {
appendPQExpBuffer(creaQry, " LC_CTYPE = "); appendPQExpBuffer(creaQry, " LC_CTYPE = ");
appendStringLiteralAH(creaQry, ctype, AH); appendStringLiteralAH(creaQry, ctype, fout);
} }
if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0) if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0)
appendPQExpBuffer(creaQry, " TABLESPACE = %s", appendPQExpBuffer(creaQry, " TABLESPACE = %s",
...@@ -1971,7 +1983,7 @@ dumpDatabase(Archive *AH) ...@@ -1971,7 +1983,7 @@ dumpDatabase(Archive *AH)
"SET datfrozenxid = '%u'\n" "SET datfrozenxid = '%u'\n"
"WHERE datname = ", "WHERE datname = ",
frozenxid); frozenxid);
appendStringLiteralAH(creaQry, datname, AH); appendStringLiteralAH(creaQry, datname, fout);
appendPQExpBuffer(creaQry, ";\n"); appendPQExpBuffer(creaQry, ";\n");
} }
...@@ -1981,7 +1993,7 @@ dumpDatabase(Archive *AH) ...@@ -1981,7 +1993,7 @@ dumpDatabase(Archive *AH)
dbDumpId = createDumpId(); dbDumpId = createDumpId();
ArchiveEntry(AH, ArchiveEntry(fout,
dbCatId, /* catalog ID */ dbCatId, /* catalog ID */
dbDumpId, /* dump ID */ dbDumpId, /* dump ID */
datname, /* Name */ datname, /* Name */
...@@ -2035,7 +2047,7 @@ dumpDatabase(Archive *AH) ...@@ -2035,7 +2047,7 @@ dumpDatabase(Archive *AH)
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)), atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
LargeObjectRelationId); LargeObjectRelationId);
ArchiveEntry(AH, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
"pg_largeobject", NULL, NULL, "", "pg_largeobject", NULL, NULL, "",
false, "pg_largeobject", SECTION_PRE_DATA, false, "pg_largeobject", SECTION_PRE_DATA,
loOutQry->data, "", NULL, loOutQry->data, "", NULL,
...@@ -2047,7 +2059,7 @@ dumpDatabase(Archive *AH) ...@@ -2047,7 +2059,7 @@ dumpDatabase(Archive *AH)
/* /*
* pg_largeobject_metadata * pg_largeobject_metadata
*/ */
if (g_fout->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
{ {
resetPQExpBuffer(loFrozenQry); resetPQExpBuffer(loFrozenQry);
resetPQExpBuffer(loOutQry); resetPQExpBuffer(loOutQry);
...@@ -2074,7 +2086,7 @@ dumpDatabase(Archive *AH) ...@@ -2074,7 +2086,7 @@ dumpDatabase(Archive *AH)
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)), atoi(PQgetvalue(lo_res, 0, i_relfrozenxid)),
LargeObjectMetadataRelationId); LargeObjectMetadataRelationId);
ArchiveEntry(AH, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
"pg_largeobject_metadata", NULL, NULL, "", "pg_largeobject_metadata", NULL, NULL, "",
false, "pg_largeobject_metadata", SECTION_PRE_DATA, false, "pg_largeobject_metadata", SECTION_PRE_DATA,
loOutQry->data, "", NULL, loOutQry->data, "", NULL,
...@@ -2089,7 +2101,7 @@ dumpDatabase(Archive *AH) ...@@ -2089,7 +2101,7 @@ dumpDatabase(Archive *AH)
} }
/* Dump DB comment if any */ /* Dump DB comment if any */
if (g_fout->remoteVersion >= 80200) if (fout->remoteVersion >= 80200)
{ {
/* /*
* 8.2 keeps comments on shared objects in a shared table, so we * 8.2 keeps comments on shared objects in a shared table, so we
...@@ -2106,10 +2118,10 @@ dumpDatabase(Archive *AH) ...@@ -2106,10 +2118,10 @@ dumpDatabase(Archive *AH)
* database. * database.
*/ */
appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname)); appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
appendStringLiteralAH(dbQry, comment, AH); appendStringLiteralAH(dbQry, comment, fout);
appendPQExpBuffer(dbQry, ";\n"); appendPQExpBuffer(dbQry, ";\n");
ArchiveEntry(AH, dbCatId, createDumpId(), datname, NULL, NULL, ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "COMMENT", SECTION_NONE, dba, false, "COMMENT", SECTION_NONE,
dbQry->data, "", NULL, dbQry->data, "", NULL,
&dbDumpId, 1, NULL, NULL); &dbDumpId, 1, NULL, NULL);
...@@ -2119,14 +2131,14 @@ dumpDatabase(Archive *AH) ...@@ -2119,14 +2131,14 @@ dumpDatabase(Archive *AH)
{ {
resetPQExpBuffer(dbQry); resetPQExpBuffer(dbQry);
appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname)); appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname));
dumpComment(AH, dbQry->data, NULL, "", dumpComment(fout, dbQry->data, NULL, "",
dbCatId, 0, dbDumpId); dbCatId, 0, dbDumpId);
} }
PQclear(res); PQclear(res);
/* Dump shared security label. */ /* Dump shared security label. */
if (!no_security_labels && g_fout->remoteVersion >= 90200) if (!no_security_labels && fout->remoteVersion >= 90200)
{ {
PQExpBuffer seclabelQry = createPQExpBuffer(); PQExpBuffer seclabelQry = createPQExpBuffer();
...@@ -2136,7 +2148,7 @@ dumpDatabase(Archive *AH) ...@@ -2136,7 +2148,7 @@ dumpDatabase(Archive *AH)
resetPQExpBuffer(seclabelQry); resetPQExpBuffer(seclabelQry);
emitShSecLabels(g_conn, res, seclabelQry, "DATABASE", datname); emitShSecLabels(g_conn, res, seclabelQry, "DATABASE", datname);
if (strlen(seclabelQry->data)) if (strlen(seclabelQry->data))
ArchiveEntry(AH, dbCatId, createDumpId(), datname, NULL, NULL, ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "SECURITY LABEL", SECTION_NONE, dba, false, "SECURITY LABEL", SECTION_NONE,
seclabelQry->data, "", NULL, seclabelQry->data, "", NULL,
&dbDumpId, 1, NULL, NULL); &dbDumpId, 1, NULL, NULL);
...@@ -2208,7 +2220,7 @@ dumpStdStrings(Archive *AH) ...@@ -2208,7 +2220,7 @@ dumpStdStrings(Archive *AH)
* Collect schema-level data about large objects * Collect schema-level data about large objects
*/ */
static void static void
getBlobs(Archive *AH) getBlobs(Archive *fout)
{ {
PQExpBuffer blobQry = createPQExpBuffer(); PQExpBuffer blobQry = createPQExpBuffer();
BlobInfo *binfo; BlobInfo *binfo;
...@@ -2222,15 +2234,15 @@ getBlobs(Archive *AH) ...@@ -2222,15 +2234,15 @@ getBlobs(Archive *AH)
write_msg(NULL, "reading large objects\n"); write_msg(NULL, "reading large objects\n");
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* Fetch BLOB OIDs, and owner/ACL data if >= 9.0 */ /* Fetch BLOB OIDs, and owner/ACL data if >= 9.0 */
if (AH->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
appendPQExpBuffer(blobQry, appendPQExpBuffer(blobQry,
"SELECT oid, (%s lomowner) AS rolname, lomacl" "SELECT oid, (%s lomowner) AS rolname, lomacl"
" FROM pg_largeobject_metadata", " FROM pg_largeobject_metadata",
username_subquery); username_subquery);
else if (AH->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
appendPQExpBuffer(blobQry, appendPQExpBuffer(blobQry,
"SELECT DISTINCT loid, NULL::oid, NULL::oid" "SELECT DISTINCT loid, NULL::oid, NULL::oid"
" FROM pg_largeobject"); " FROM pg_largeobject");
...@@ -2289,7 +2301,7 @@ getBlobs(Archive *AH) ...@@ -2289,7 +2301,7 @@ getBlobs(Archive *AH)
* dump the definition (metadata) of the given large object * dump the definition (metadata) of the given large object
*/ */
static void static void
dumpBlob(Archive *AH, BlobInfo *binfo) dumpBlob(Archive *fout, BlobInfo *binfo)
{ {
PQExpBuffer cquery = createPQExpBuffer(); PQExpBuffer cquery = createPQExpBuffer();
PQExpBuffer dquery = createPQExpBuffer(); PQExpBuffer dquery = createPQExpBuffer();
...@@ -2302,7 +2314,7 @@ dumpBlob(Archive *AH, BlobInfo *binfo) ...@@ -2302,7 +2314,7 @@ dumpBlob(Archive *AH, BlobInfo *binfo)
"SELECT pg_catalog.lo_unlink('%s');\n", "SELECT pg_catalog.lo_unlink('%s');\n",
binfo->dobj.name); binfo->dobj.name);
ArchiveEntry(AH, binfo->dobj.catId, binfo->dobj.dumpId, ArchiveEntry(fout, binfo->dobj.catId, binfo->dobj.dumpId,
binfo->dobj.name, binfo->dobj.name,
NULL, NULL, NULL, NULL,
binfo->rolname, false, binfo->rolname, false,
...@@ -2316,18 +2328,18 @@ dumpBlob(Archive *AH, BlobInfo *binfo) ...@@ -2316,18 +2328,18 @@ dumpBlob(Archive *AH, BlobInfo *binfo)
appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name); appendPQExpBuffer(cquery, "LARGE OBJECT %s", binfo->dobj.name);
/* Dump comment if any */ /* Dump comment if any */
dumpComment(AH, cquery->data, dumpComment(fout, cquery->data,
NULL, binfo->rolname, NULL, binfo->rolname,
binfo->dobj.catId, 0, binfo->dobj.dumpId); binfo->dobj.catId, 0, binfo->dobj.dumpId);
/* Dump security label if any */ /* Dump security label if any */
dumpSecLabel(AH, cquery->data, dumpSecLabel(fout, cquery->data,
NULL, binfo->rolname, NULL, binfo->rolname,
binfo->dobj.catId, 0, binfo->dobj.dumpId); binfo->dobj.catId, 0, binfo->dobj.dumpId);
/* Dump ACL if any */ /* Dump ACL if any */
if (binfo->blobacl) if (binfo->blobacl)
dumpACL(AH, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT", dumpACL(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT",
binfo->dobj.name, NULL, cquery->data, binfo->dobj.name, NULL, cquery->data,
NULL, binfo->rolname, binfo->blobacl); NULL, binfo->rolname, binfo->blobacl);
...@@ -2340,7 +2352,7 @@ dumpBlob(Archive *AH, BlobInfo *binfo) ...@@ -2340,7 +2352,7 @@ dumpBlob(Archive *AH, BlobInfo *binfo)
* dump the data contents of all large objects * dump the data contents of all large objects
*/ */
static int static int
dumpBlobs(Archive *AH, void *arg) dumpBlobs(Archive *fout, void *arg)
{ {
const char *blobQry; const char *blobQry;
const char *blobFetchQry; const char *blobFetchQry;
...@@ -2354,15 +2366,15 @@ dumpBlobs(Archive *AH, void *arg) ...@@ -2354,15 +2366,15 @@ dumpBlobs(Archive *AH, void *arg)
write_msg(NULL, "saving large objects\n"); write_msg(NULL, "saving large objects\n");
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* /*
* Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning * Currently, we re-fetch all BLOB OIDs using a cursor. Consider scanning
* the already-in-memory dumpable objects instead... * the already-in-memory dumpable objects instead...
*/ */
if (AH->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata"; blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_largeobject_metadata";
else if (AH->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject"; blobQry = "DECLARE bloboid CURSOR FOR SELECT DISTINCT loid FROM pg_largeobject";
else else
blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_class WHERE relkind = 'l'"; blobQry = "DECLARE bloboid CURSOR FOR SELECT oid FROM pg_class WHERE relkind = 'l'";
...@@ -2398,7 +2410,7 @@ dumpBlobs(Archive *AH, void *arg) ...@@ -2398,7 +2410,7 @@ dumpBlobs(Archive *AH, void *arg)
exit_nicely(); exit_nicely();
} }
StartBlob(AH, blobOid); StartBlob(fout, blobOid);
/* Now read it in chunks, sending data to archive */ /* Now read it in chunks, sending data to archive */
do do
...@@ -2411,12 +2423,12 @@ dumpBlobs(Archive *AH, void *arg) ...@@ -2411,12 +2423,12 @@ dumpBlobs(Archive *AH, void *arg)
exit_nicely(); exit_nicely();
} }
WriteData(AH, buf, cnt); WriteData(fout, buf, cnt);
} while (cnt > 0); } while (cnt > 0);
lo_close(g_conn, loFd); lo_close(g_conn, loFd);
EndBlob(AH, blobOid); EndBlob(fout, blobOid);
} }
} while (ntups > 0); } while (ntups > 0);
...@@ -2656,7 +2668,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, ...@@ -2656,7 +2668,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
* numNamespaces is set to the number of namespaces read in * numNamespaces is set to the number of namespaces read in
*/ */
NamespaceInfo * NamespaceInfo *
getNamespaces(int *numNamespaces) getNamespaces(Archive *fout, int *numNamespaces)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -2673,7 +2685,7 @@ getNamespaces(int *numNamespaces) ...@@ -2673,7 +2685,7 @@ getNamespaces(int *numNamespaces)
* Before 7.3, there are no real namespaces; create two dummy entries, one * Before 7.3, there are no real namespaces; create two dummy entries, one
* for user stuff and one for system stuff. * for user stuff and one for system stuff.
*/ */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
nsinfo = (NamespaceInfo *) pg_malloc(2 * sizeof(NamespaceInfo)); nsinfo = (NamespaceInfo *) pg_malloc(2 * sizeof(NamespaceInfo));
...@@ -2706,7 +2718,7 @@ getNamespaces(int *numNamespaces) ...@@ -2706,7 +2718,7 @@ getNamespaces(int *numNamespaces)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* /*
* we fetch all namespaces including system ones, so that every object we * we fetch all namespaces including system ones, so that every object we
...@@ -2766,11 +2778,11 @@ getNamespaces(int *numNamespaces) ...@@ -2766,11 +2778,11 @@ getNamespaces(int *numNamespaces)
* a system object or not. In 7.3 and later there is no guessing. * a system object or not. In 7.3 and later there is no guessing.
*/ */
static NamespaceInfo * static NamespaceInfo *
findNamespace(Oid nsoid, Oid objoid) findNamespace(Archive *fout, Oid nsoid, Oid objoid)
{ {
int i; int i;
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
for (i = 0; i < g_numNamespaces; i++) for (i = 0; i < g_numNamespaces; i++)
{ {
...@@ -2803,7 +2815,7 @@ findNamespace(Oid nsoid, Oid objoid) ...@@ -2803,7 +2815,7 @@ findNamespace(Oid nsoid, Oid objoid)
* numExtensions is set to the number of extensions read in * numExtensions is set to the number of extensions read in
*/ */
ExtensionInfo * ExtensionInfo *
getExtensions(int *numExtensions) getExtensions(Archive *fout, int *numExtensions)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -2822,7 +2834,7 @@ getExtensions(int *numExtensions) ...@@ -2822,7 +2834,7 @@ getExtensions(int *numExtensions)
/* /*
* Before 9.1, there are no extensions. * Before 9.1, there are no extensions.
*/ */
if (g_fout->remoteVersion < 90100) if (fout->remoteVersion < 90100)
{ {
*numExtensions = 0; *numExtensions = 0;
return NULL; return NULL;
...@@ -2831,7 +2843,7 @@ getExtensions(int *numExtensions) ...@@ -2831,7 +2843,7 @@ getExtensions(int *numExtensions)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT x.tableoid, x.oid, " appendPQExpBuffer(query, "SELECT x.tableoid, x.oid, "
"x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition " "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
...@@ -2890,7 +2902,7 @@ getExtensions(int *numExtensions) ...@@ -2890,7 +2902,7 @@ getExtensions(int *numExtensions)
* findFuncByOid(). * findFuncByOid().
*/ */
TypeInfo * TypeInfo *
getTypes(int *numTypes) getTypes(Archive *fout, int *numTypes)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -2929,9 +2941,9 @@ getTypes(int *numTypes) ...@@ -2929,9 +2941,9 @@ getTypes(int *numTypes)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 80300) if (fout->remoteVersion >= 80300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, " "typnamespace, "
...@@ -2946,7 +2958,7 @@ getTypes(int *numTypes) ...@@ -2946,7 +2958,7 @@ getTypes(int *numTypes)
"FROM pg_type", "FROM pg_type",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"typnamespace, " "typnamespace, "
...@@ -2960,7 +2972,7 @@ getTypes(int *numTypes) ...@@ -2960,7 +2972,7 @@ getTypes(int *numTypes)
"FROM pg_type", "FROM pg_type",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, typname, " appendPQExpBuffer(query, "SELECT tableoid, oid, typname, "
"0::oid AS typnamespace, " "0::oid AS typnamespace, "
...@@ -3019,7 +3031,9 @@ getTypes(int *numTypes) ...@@ -3019,7 +3031,9 @@ getTypes(int *numTypes)
tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); tyinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tyinfo[i].dobj); AssignDumpId(&tyinfo[i].dobj);
tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname)); tyinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_typname));
tyinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_typnamespace)), tyinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_typnamespace)),
tyinfo[i].dobj.catId.oid); tyinfo[i].dobj.catId.oid);
tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tyinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem)); tyinfo[i].typelem = atooid(PQgetvalue(res, i, i_typelem));
...@@ -3047,7 +3061,7 @@ getTypes(int *numTypes) ...@@ -3047,7 +3061,7 @@ getTypes(int *numTypes)
tyinfo[i].nDomChecks = 0; tyinfo[i].nDomChecks = 0;
tyinfo[i].domChecks = NULL; tyinfo[i].domChecks = NULL;
if (tyinfo[i].dobj.dump && tyinfo[i].typtype == TYPTYPE_DOMAIN) if (tyinfo[i].dobj.dump && tyinfo[i].typtype == TYPTYPE_DOMAIN)
getDomainConstraints(&(tyinfo[i])); getDomainConstraints(fout, &(tyinfo[i]));
/* /*
* If it's a base type, make a DumpableObject representing a shell * If it's a base type, make a DumpableObject representing a shell
...@@ -3084,7 +3098,7 @@ getTypes(int *numTypes) ...@@ -3084,7 +3098,7 @@ getTypes(int *numTypes)
* typinput and typoutput since the other functions only exist * typinput and typoutput since the other functions only exist
* post-7.3. * post-7.3.
*/ */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
Oid typinput; Oid typinput;
Oid typoutput; Oid typoutput;
...@@ -3143,7 +3157,7 @@ getTypes(int *numTypes) ...@@ -3143,7 +3157,7 @@ getTypes(int *numTypes)
* numOprs is set to the number of operators read in * numOprs is set to the number of operators read in
*/ */
OprInfo * OprInfo *
getOperators(int *numOprs) getOperators(Archive *fout, int *numOprs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3164,9 +3178,9 @@ getOperators(int *numOprs) ...@@ -3164,9 +3178,9 @@ getOperators(int *numOprs)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
"oprnamespace, " "oprnamespace, "
...@@ -3176,7 +3190,7 @@ getOperators(int *numOprs) ...@@ -3176,7 +3190,7 @@ getOperators(int *numOprs)
"FROM pg_operator", "FROM pg_operator",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
"0::oid AS oprnamespace, " "0::oid AS oprnamespace, "
...@@ -3222,7 +3236,9 @@ getOperators(int *numOprs) ...@@ -3222,7 +3236,9 @@ getOperators(int *numOprs)
oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); oprinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&oprinfo[i].dobj); AssignDumpId(&oprinfo[i].dobj);
oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname)); oprinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_oprname));
oprinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)), oprinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_oprnamespace)),
oprinfo[i].dobj.catId.oid); oprinfo[i].dobj.catId.oid);
oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0]; oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
...@@ -3251,7 +3267,7 @@ getOperators(int *numOprs) ...@@ -3251,7 +3267,7 @@ getOperators(int *numOprs)
* numCollations is set to the number of collations read in * numCollations is set to the number of collations read in
*/ */
CollInfo * CollInfo *
getCollations(int *numCollations) getCollations(Archive *fout, int *numCollations)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3265,7 +3281,7 @@ getCollations(int *numCollations) ...@@ -3265,7 +3281,7 @@ getCollations(int *numCollations)
int i_rolname; int i_rolname;
/* Collations didn't exist pre-9.1 */ /* Collations didn't exist pre-9.1 */
if (g_fout->remoteVersion < 90100) if (fout->remoteVersion < 90100)
{ {
*numCollations = 0; *numCollations = 0;
return NULL; return NULL;
...@@ -3277,7 +3293,7 @@ getCollations(int *numCollations) ...@@ -3277,7 +3293,7 @@ getCollations(int *numCollations)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, collname, " appendPQExpBuffer(query, "SELECT tableoid, oid, collname, "
"collnamespace, " "collnamespace, "
...@@ -3306,7 +3322,9 @@ getCollations(int *numCollations) ...@@ -3306,7 +3322,9 @@ getCollations(int *numCollations)
collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); collinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&collinfo[i].dobj); AssignDumpId(&collinfo[i].dobj);
collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname)); collinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_collname));
collinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_collnamespace)), collinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_collnamespace)),
collinfo[i].dobj.catId.oid); collinfo[i].dobj.catId.oid);
collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); collinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
...@@ -3329,7 +3347,7 @@ getCollations(int *numCollations) ...@@ -3329,7 +3347,7 @@ getCollations(int *numCollations)
* numConversions is set to the number of conversions read in * numConversions is set to the number of conversions read in
*/ */
ConvInfo * ConvInfo *
getConversions(int *numConversions) getConversions(Archive *fout, int *numConversions)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3343,7 +3361,7 @@ getConversions(int *numConversions) ...@@ -3343,7 +3361,7 @@ getConversions(int *numConversions)
int i_rolname; int i_rolname;
/* Conversions didn't exist pre-7.3 */ /* Conversions didn't exist pre-7.3 */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
*numConversions = 0; *numConversions = 0;
return NULL; return NULL;
...@@ -3355,7 +3373,7 @@ getConversions(int *numConversions) ...@@ -3355,7 +3373,7 @@ getConversions(int *numConversions)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
"connamespace, " "connamespace, "
...@@ -3384,7 +3402,9 @@ getConversions(int *numConversions) ...@@ -3384,7 +3402,9 @@ getConversions(int *numConversions)
convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); convinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&convinfo[i].dobj); AssignDumpId(&convinfo[i].dobj);
convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname)); convinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_conname));
convinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_connamespace)), convinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_connamespace)),
convinfo[i].dobj.catId.oid); convinfo[i].dobj.catId.oid);
convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); convinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
...@@ -3407,7 +3427,7 @@ getConversions(int *numConversions) ...@@ -3407,7 +3427,7 @@ getConversions(int *numConversions)
* numOpclasses is set to the number of opclasses read in * numOpclasses is set to the number of opclasses read in
*/ */
OpclassInfo * OpclassInfo *
getOpclasses(int *numOpclasses) getOpclasses(Archive *fout, int *numOpclasses)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3426,9 +3446,9 @@ getOpclasses(int *numOpclasses) ...@@ -3426,9 +3446,9 @@ getOpclasses(int *numOpclasses)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
"opcnamespace, " "opcnamespace, "
...@@ -3436,7 +3456,7 @@ getOpclasses(int *numOpclasses) ...@@ -3436,7 +3456,7 @@ getOpclasses(int *numOpclasses)
"FROM pg_opclass", "FROM pg_opclass",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, "
"0::oid AS opcnamespace, " "0::oid AS opcnamespace, "
...@@ -3474,14 +3494,16 @@ getOpclasses(int *numOpclasses) ...@@ -3474,14 +3494,16 @@ getOpclasses(int *numOpclasses)
opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); opcinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opcinfo[i].dobj); AssignDumpId(&opcinfo[i].dobj);
opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname)); opcinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opcname));
opcinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opcnamespace)), opcinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_opcnamespace)),
opcinfo[i].dobj.catId.oid); opcinfo[i].dobj.catId.oid);
opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); opcinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
selectDumpableObject(&(opcinfo[i].dobj)); selectDumpableObject(&(opcinfo[i].dobj));
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
if (strlen(opcinfo[i].rolname) == 0) if (strlen(opcinfo[i].rolname) == 0)
write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n", write_msg(NULL, "WARNING: owner of operator class \"%s\" appears to be invalid\n",
...@@ -3504,7 +3526,7 @@ getOpclasses(int *numOpclasses) ...@@ -3504,7 +3526,7 @@ getOpclasses(int *numOpclasses)
* numOpfamilies is set to the number of opfamilies read in * numOpfamilies is set to the number of opfamilies read in
*/ */
OpfamilyInfo * OpfamilyInfo *
getOpfamilies(int *numOpfamilies) getOpfamilies(Archive *fout, int *numOpfamilies)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3518,7 +3540,7 @@ getOpfamilies(int *numOpfamilies) ...@@ -3518,7 +3540,7 @@ getOpfamilies(int *numOpfamilies)
int i_rolname; int i_rolname;
/* Before 8.3, there is no separate concept of opfamilies */ /* Before 8.3, there is no separate concept of opfamilies */
if (g_fout->remoteVersion < 80300) if (fout->remoteVersion < 80300)
{ {
*numOpfamilies = 0; *numOpfamilies = 0;
return NULL; return NULL;
...@@ -3532,7 +3554,7 @@ getOpfamilies(int *numOpfamilies) ...@@ -3532,7 +3554,7 @@ getOpfamilies(int *numOpfamilies)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, " appendPQExpBuffer(query, "SELECT tableoid, oid, opfname, "
"opfnamespace, " "opfnamespace, "
...@@ -3561,14 +3583,16 @@ getOpfamilies(int *numOpfamilies) ...@@ -3561,14 +3583,16 @@ getOpfamilies(int *numOpfamilies)
opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); opfinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&opfinfo[i].dobj); AssignDumpId(&opfinfo[i].dobj);
opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname)); opfinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_opfname));
opfinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_opfnamespace)), opfinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_opfnamespace)),
opfinfo[i].dobj.catId.oid); opfinfo[i].dobj.catId.oid);
opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); opfinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
selectDumpableObject(&(opfinfo[i].dobj)); selectDumpableObject(&(opfinfo[i].dobj));
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
if (strlen(opfinfo[i].rolname) == 0) if (strlen(opfinfo[i].rolname) == 0)
write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n", write_msg(NULL, "WARNING: owner of operator family \"%s\" appears to be invalid\n",
...@@ -3591,7 +3615,7 @@ getOpfamilies(int *numOpfamilies) ...@@ -3591,7 +3615,7 @@ getOpfamilies(int *numOpfamilies)
* numAggs is set to the number of aggregates read in * numAggs is set to the number of aggregates read in
*/ */
AggInfo * AggInfo *
getAggregates(int *numAggs) getAggregates(Archive *fout, int *numAggs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3608,14 +3632,14 @@ getAggregates(int *numAggs) ...@@ -3608,14 +3632,14 @@ getAggregates(int *numAggs)
int i_aggacl; int i_aggacl;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* /*
* Find all user-defined aggregates. See comment in getFuncs() for the * Find all user-defined aggregates. See comment in getFuncs() for the
* rationale behind the filtering logic. * rationale behind the filtering logic.
*/ */
if (g_fout->remoteVersion >= 80200) if (fout->remoteVersion >= 80200)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
"pronamespace AS aggnamespace, " "pronamespace AS aggnamespace, "
...@@ -3628,7 +3652,7 @@ getAggregates(int *numAggs) ...@@ -3628,7 +3652,7 @@ getAggregates(int *numAggs)
"(SELECT oid FROM pg_namespace " "(SELECT oid FROM pg_namespace "
"WHERE nspname = 'pg_catalog')", "WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
if (binary_upgrade && g_fout->remoteVersion >= 90100) if (binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBuffer(query, appendPQExpBuffer(query,
" OR EXISTS(SELECT 1 FROM pg_depend WHERE " " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
"classid = 'pg_proc'::regclass AND " "classid = 'pg_proc'::regclass AND "
...@@ -3637,7 +3661,7 @@ getAggregates(int *numAggs) ...@@ -3637,7 +3661,7 @@ getAggregates(int *numAggs)
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBuffer(query, ")"); appendPQExpBuffer(query, ")");
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, " appendPQExpBuffer(query, "SELECT tableoid, oid, proname AS aggname, "
"pronamespace AS aggnamespace, " "pronamespace AS aggnamespace, "
...@@ -3651,7 +3675,7 @@ getAggregates(int *numAggs) ...@@ -3651,7 +3675,7 @@ getAggregates(int *numAggs)
"(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')", "(SELECT oid FROM pg_namespace WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, aggname, " appendPQExpBuffer(query, "SELECT tableoid, oid, aggname, "
"0::oid AS aggnamespace, " "0::oid AS aggnamespace, "
...@@ -3704,7 +3728,9 @@ getAggregates(int *numAggs) ...@@ -3704,7 +3728,9 @@ getAggregates(int *numAggs)
agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); agginfo[i].aggfn.dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&agginfo[i].aggfn.dobj); AssignDumpId(&agginfo[i].aggfn.dobj);
agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname)); agginfo[i].aggfn.dobj.name = pg_strdup(PQgetvalue(res, i, i_aggname));
agginfo[i].aggfn.dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_aggnamespace)), agginfo[i].aggfn.dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_aggnamespace)),
agginfo[i].aggfn.dobj.catId.oid); agginfo[i].aggfn.dobj.catId.oid);
agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); agginfo[i].aggfn.rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
if (strlen(agginfo[i].aggfn.rolname) == 0) if (strlen(agginfo[i].aggfn.rolname) == 0)
...@@ -3719,7 +3745,7 @@ getAggregates(int *numAggs) ...@@ -3719,7 +3745,7 @@ getAggregates(int *numAggs)
else else
{ {
agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid)); agginfo[i].aggfn.argtypes = (Oid *) pg_malloc(agginfo[i].aggfn.nargs * sizeof(Oid));
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
parseOidArray(PQgetvalue(res, i, i_proargtypes), parseOidArray(PQgetvalue(res, i, i_proargtypes),
agginfo[i].aggfn.argtypes, agginfo[i].aggfn.argtypes,
agginfo[i].aggfn.nargs); agginfo[i].aggfn.nargs);
...@@ -3747,7 +3773,7 @@ getAggregates(int *numAggs) ...@@ -3747,7 +3773,7 @@ getAggregates(int *numAggs)
* numFuncs is set to the number of functions read in * numFuncs is set to the number of functions read in
*/ */
FuncInfo * FuncInfo *
getFuncs(int *numFuncs) getFuncs(Archive *fout, int *numFuncs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3766,7 +3792,7 @@ getFuncs(int *numFuncs) ...@@ -3766,7 +3792,7 @@ getFuncs(int *numFuncs)
int i_proacl; int i_proacl;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* /*
* Find all user-defined functions. Normally we can exclude functions in * Find all user-defined functions. Normally we can exclude functions in
...@@ -3784,7 +3810,7 @@ getFuncs(int *numFuncs) ...@@ -3784,7 +3810,7 @@ getFuncs(int *numFuncs)
* doesn't have; otherwise we might not get creation ordering correct. * doesn't have; otherwise we might not get creation ordering correct.
*/ */
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT tableoid, oid, proname, prolang, " "SELECT tableoid, oid, proname, prolang, "
...@@ -3797,12 +3823,12 @@ getFuncs(int *numFuncs) ...@@ -3797,12 +3823,12 @@ getFuncs(int *numFuncs)
"(SELECT oid FROM pg_namespace " "(SELECT oid FROM pg_namespace "
"WHERE nspname = 'pg_catalog')", "WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
if (g_fout->remoteVersion >= 90200) if (fout->remoteVersion >= 90200)
appendPQExpBuffer(query, appendPQExpBuffer(query,
"\n AND NOT EXISTS (SELECT 1 FROM pg_depend " "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
"WHERE classid = 'pg_proc'::regclass AND " "WHERE classid = 'pg_proc'::regclass AND "
"objid = p.oid AND deptype = 'i')"); "objid = p.oid AND deptype = 'i')");
if (binary_upgrade && g_fout->remoteVersion >= 90100) if (binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBuffer(query, appendPQExpBuffer(query,
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
"classid = 'pg_proc'::regclass AND " "classid = 'pg_proc'::regclass AND "
...@@ -3811,7 +3837,7 @@ getFuncs(int *numFuncs) ...@@ -3811,7 +3837,7 @@ getFuncs(int *numFuncs)
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBuffer(query, ")"); appendPQExpBuffer(query, ")");
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT tableoid, oid, proname, prolang, " "SELECT tableoid, oid, proname, prolang, "
...@@ -3869,7 +3895,8 @@ getFuncs(int *numFuncs) ...@@ -3869,7 +3895,8 @@ getFuncs(int *numFuncs)
AssignDumpId(&finfo[i].dobj); AssignDumpId(&finfo[i].dobj);
finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname)); finfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_proname));
finfo[i].dobj.namespace = finfo[i].dobj.namespace =
findNamespace(atooid(PQgetvalue(res, i, i_pronamespace)), findNamespace(fout,
atooid(PQgetvalue(res, i, i_pronamespace)),
finfo[i].dobj.catId.oid); finfo[i].dobj.catId.oid);
finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); finfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang)); finfo[i].lang = atooid(PQgetvalue(res, i, i_prolang));
...@@ -3909,7 +3936,7 @@ getFuncs(int *numFuncs) ...@@ -3909,7 +3936,7 @@ getFuncs(int *numFuncs)
* numTables is set to the number of tables read in * numTables is set to the number of tables read in
*/ */
TableInfo * TableInfo *
getTables(int *numTables) getTables(Archive *fout, int *numTables)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3940,7 +3967,7 @@ getTables(int *numTables) ...@@ -3940,7 +3967,7 @@ getTables(int *numTables)
int i_reloftype; int i_reloftype;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* /*
* Find all the tables (including views and sequences). * Find all the tables (including views and sequences).
...@@ -3962,7 +3989,7 @@ getTables(int *numTables) ...@@ -3962,7 +3989,7 @@ getTables(int *numTables)
* we cannot correctly identify inherited columns, owned sequences, etc. * we cannot correctly identify inherited columns, owned sequences, etc.
*/ */
if (g_fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -3998,7 +4025,7 @@ getTables(int *numTables) ...@@ -3998,7 +4025,7 @@ getTables(int *numTables)
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, RELKIND_VIEW, RELKIND_COMPOSITE_TYPE,
RELKIND_FOREIGN_TABLE); RELKIND_FOREIGN_TABLE);
} }
else if (g_fout->remoteVersion >= 90000) else if (fout->remoteVersion >= 90000)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -4033,7 +4060,7 @@ getTables(int *numTables) ...@@ -4033,7 +4060,7 @@ getTables(int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (g_fout->remoteVersion >= 80400) else if (fout->remoteVersion >= 80400)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -4068,7 +4095,7 @@ getTables(int *numTables) ...@@ -4068,7 +4095,7 @@ getTables(int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (g_fout->remoteVersion >= 80200) else if (fout->remoteVersion >= 80200)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -4103,7 +4130,7 @@ getTables(int *numTables) ...@@ -4103,7 +4130,7 @@ getTables(int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (g_fout->remoteVersion >= 80000) else if (fout->remoteVersion >= 80000)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -4138,7 +4165,7 @@ getTables(int *numTables) ...@@ -4138,7 +4165,7 @@ getTables(int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
/* /*
* Left join to pick up dependency info linking sequences to their * Left join to pick up dependency info linking sequences to their
...@@ -4173,7 +4200,7 @@ getTables(int *numTables) ...@@ -4173,7 +4200,7 @@ getTables(int *numTables)
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_RELATION, RELKIND_SEQUENCE,
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
} }
else if (g_fout->remoteVersion >= 70200) else if (fout->remoteVersion >= 70200)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT tableoid, oid, relname, relacl, relkind, " "SELECT tableoid, oid, relname, relacl, relkind, "
...@@ -4197,7 +4224,7 @@ getTables(int *numTables) ...@@ -4197,7 +4224,7 @@ getTables(int *numTables)
username_subquery, username_subquery,
RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW); RELKIND_RELATION, RELKIND_SEQUENCE, RELKIND_VIEW);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
/* all tables have oids in 7.1 */ /* all tables have oids in 7.1 */
appendPQExpBuffer(query, appendPQExpBuffer(query,
...@@ -4302,7 +4329,7 @@ getTables(int *numTables) ...@@ -4302,7 +4329,7 @@ getTables(int *numTables)
i_toastreloptions = PQfnumber(res, "toast_reloptions"); i_toastreloptions = PQfnumber(res, "toast_reloptions");
i_reloftype = PQfnumber(res, "reloftype"); i_reloftype = PQfnumber(res, "reloftype");
if (lockWaitTimeout && g_fout->remoteVersion >= 70300) if (lockWaitTimeout && fout->remoteVersion >= 70300)
{ {
/* /*
* Arrange to fail instead of waiting forever for a table lock. * Arrange to fail instead of waiting forever for a table lock.
...@@ -4324,7 +4351,9 @@ getTables(int *numTables) ...@@ -4324,7 +4351,9 @@ getTables(int *numTables)
tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid)); tblinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_reloid));
AssignDumpId(&tblinfo[i].dobj); AssignDumpId(&tblinfo[i].dobj);
tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname)); tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname));
tblinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_relnamespace)), tblinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_relnamespace)),
tblinfo[i].dobj.catId.oid); tblinfo[i].dobj.catId.oid);
tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl)); tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl));
...@@ -4383,7 +4412,8 @@ getTables(int *numTables) ...@@ -4383,7 +4412,8 @@ getTables(int *numTables)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, appendPQExpBuffer(query,
"LOCK TABLE %s IN ACCESS SHARE MODE", "LOCK TABLE %s IN ACCESS SHARE MODE",
fmtQualifiedId(tblinfo[i].dobj.namespace->dobj.name, fmtQualifiedId(fout,
tblinfo[i].dobj.namespace->dobj.name,
tblinfo[i].dobj.name)); tblinfo[i].dobj.name));
do_sql_command(g_conn, query->data); do_sql_command(g_conn, query->data);
} }
...@@ -4394,7 +4424,7 @@ getTables(int *numTables) ...@@ -4394,7 +4424,7 @@ getTables(int *numTables)
tblinfo[i].dobj.name); tblinfo[i].dobj.name);
} }
if (lockWaitTimeout && g_fout->remoteVersion >= 70300) if (lockWaitTimeout && fout->remoteVersion >= 70300)
{ {
do_sql_command(g_conn, "SET statement_timeout = 0"); do_sql_command(g_conn, "SET statement_timeout = 0");
} }
...@@ -4443,7 +4473,7 @@ getTables(int *numTables) ...@@ -4443,7 +4473,7 @@ getTables(int *numTables)
* numInherits is set to the number of pairs read in * numInherits is set to the number of pairs read in
*/ */
InhInfo * InhInfo *
getInherits(int *numInherits) getInherits(Archive *fout, int *numInherits)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -4455,7 +4485,7 @@ getInherits(int *numInherits) ...@@ -4455,7 +4485,7 @@ getInherits(int *numInherits)
int i_inhparent; int i_inhparent;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
/* find all the inheritance information */ /* find all the inheritance information */
...@@ -4494,7 +4524,7 @@ getInherits(int *numInherits) ...@@ -4494,7 +4524,7 @@ getInherits(int *numInherits)
* does get entered into the DumpableObject tables. * does get entered into the DumpableObject tables.
*/ */
void void
getIndexes(TableInfo tblinfo[], int numTables) getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
{ {
int i, int i,
j; j;
...@@ -4537,7 +4567,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4537,7 +4567,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
tbinfo->dobj.name); tbinfo->dobj.name);
/* Make sure we are in proper schema so indexdef is right */ /* Make sure we are in proper schema so indexdef is right */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
/* /*
* The point of the messy-looking outer join is to find a constraint * The point of the messy-looking outer join is to find a constraint
...@@ -4551,7 +4581,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4551,7 +4581,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
* is not. * is not.
*/ */
resetPQExpBuffer(query); resetPQExpBuffer(query);
if (g_fout->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -4576,7 +4606,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4576,7 +4606,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 80200) else if (fout->remoteVersion >= 80200)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -4604,7 +4634,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4604,7 +4634,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 80000) else if (fout->remoteVersion >= 80000)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -4632,7 +4662,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4632,7 +4662,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -4660,7 +4690,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4660,7 +4690,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
"ORDER BY indexname", "ORDER BY indexname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT t.tableoid, t.oid, " "SELECT t.tableoid, t.oid, "
...@@ -4825,7 +4855,7 @@ getIndexes(TableInfo tblinfo[], int numTables) ...@@ -4825,7 +4855,7 @@ getIndexes(TableInfo tblinfo[], int numTables)
* while check constraints are processed in getTableAttrs(). * while check constraints are processed in getTableAttrs().
*/ */
void void
getConstraints(TableInfo tblinfo[], int numTables) getConstraints(Archive *fout, TableInfo tblinfo[], int numTables)
{ {
int i, int i,
j; j;
...@@ -4840,7 +4870,7 @@ getConstraints(TableInfo tblinfo[], int numTables) ...@@ -4840,7 +4870,7 @@ getConstraints(TableInfo tblinfo[], int numTables)
int ntups; int ntups;
/* pg_constraint was created in 7.3, so nothing to do if older */ /* pg_constraint was created in 7.3, so nothing to do if older */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -4860,7 +4890,7 @@ getConstraints(TableInfo tblinfo[], int numTables) ...@@ -4860,7 +4890,7 @@ getConstraints(TableInfo tblinfo[], int numTables)
* select table schema to ensure constraint expr is qualified if * select table schema to ensure constraint expr is qualified if
* needed * needed
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, appendPQExpBuffer(query,
...@@ -4915,7 +4945,7 @@ getConstraints(TableInfo tblinfo[], int numTables) ...@@ -4915,7 +4945,7 @@ getConstraints(TableInfo tblinfo[], int numTables)
* Get info about constraints on a domain. * Get info about constraints on a domain.
*/ */
static void static void
getDomainConstraints(TypeInfo *tyinfo) getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
{ {
int i; int i;
ConstraintInfo *constrinfo; ConstraintInfo *constrinfo;
...@@ -4928,18 +4958,18 @@ getDomainConstraints(TypeInfo *tyinfo) ...@@ -4928,18 +4958,18 @@ getDomainConstraints(TypeInfo *tyinfo)
int ntups; int ntups;
/* pg_constraint was created in 7.3, so nothing to do if older */ /* pg_constraint was created in 7.3, so nothing to do if older */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
return; return;
/* /*
* select appropriate schema to ensure names in constraint are properly * select appropriate schema to ensure names in constraint are properly
* qualified * qualified
*/ */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
query = createPQExpBuffer(); query = createPQExpBuffer();
if (g_fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
"convalidated " "convalidated "
...@@ -4948,7 +4978,7 @@ getDomainConstraints(TypeInfo *tyinfo) ...@@ -4948,7 +4978,7 @@ getDomainConstraints(TypeInfo *tyinfo)
"ORDER BY conname", "ORDER BY conname",
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
else if (g_fout->remoteVersion >= 70400) else if (fout->remoteVersion >= 70400)
appendPQExpBuffer(query, "SELECT tableoid, oid, conname, " appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
"true as convalidated " "true as convalidated "
...@@ -5025,7 +5055,7 @@ getDomainConstraints(TypeInfo *tyinfo) ...@@ -5025,7 +5055,7 @@ getDomainConstraints(TypeInfo *tyinfo)
* numRules is set to the number of rules read in * numRules is set to the number of rules read in
*/ */
RuleInfo * RuleInfo *
getRules(int *numRules) getRules(Archive *fout, int *numRules)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -5041,9 +5071,9 @@ getRules(int *numRules) ...@@ -5041,9 +5071,9 @@ getRules(int *numRules)
int i_ev_enabled; int i_ev_enabled;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 80300) if (fout->remoteVersion >= 80300)
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBuffer(query, "SELECT "
"tableoid, oid, rulename, " "tableoid, oid, rulename, "
...@@ -5052,7 +5082,7 @@ getRules(int *numRules) ...@@ -5052,7 +5082,7 @@ getRules(int *numRules)
"FROM pg_rewrite " "FROM pg_rewrite "
"ORDER BY oid"); "ORDER BY oid");
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBuffer(query, "SELECT "
"tableoid, oid, rulename, " "tableoid, oid, rulename, "
...@@ -5154,7 +5184,7 @@ getRules(int *numRules) ...@@ -5154,7 +5184,7 @@ getRules(int *numRules)
* does get entered into the DumpableObject tables. * does get entered into the DumpableObject tables.
*/ */
void void
getTriggers(TableInfo tblinfo[], int numTables) getTriggers(Archive *fout, TableInfo tblinfo[], int numTables)
{ {
int i, int i,
j; j;
...@@ -5192,10 +5222,10 @@ getTriggers(TableInfo tblinfo[], int numTables) ...@@ -5192,10 +5222,10 @@ getTriggers(TableInfo tblinfo[], int numTables)
/* /*
* select table schema to ensure regproc name is qualified if needed * select table schema to ensure regproc name is qualified if needed
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
resetPQExpBuffer(query); resetPQExpBuffer(query);
if (g_fout->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
{ {
/* /*
* NB: think not to use pretty=true in pg_get_triggerdef. It * NB: think not to use pretty=true in pg_get_triggerdef. It
...@@ -5212,7 +5242,7 @@ getTriggers(TableInfo tblinfo[], int numTables) ...@@ -5212,7 +5242,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
"AND NOT tgisinternal", "AND NOT tgisinternal",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 80300) else if (fout->remoteVersion >= 80300)
{ {
/* /*
* We ignore triggers that are tied to a foreign-key constraint * We ignore triggers that are tied to a foreign-key constraint
...@@ -5229,7 +5259,7 @@ getTriggers(TableInfo tblinfo[], int numTables) ...@@ -5229,7 +5259,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
"AND tgconstraint = 0", "AND tgconstraint = 0",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
/* /*
* We ignore triggers that are tied to a foreign-key constraint, * We ignore triggers that are tied to a foreign-key constraint,
...@@ -5252,7 +5282,7 @@ getTriggers(TableInfo tblinfo[], int numTables) ...@@ -5252,7 +5282,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
" WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))", " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT tgname, tgfoid::regproc AS tgfname, " "SELECT tgname, tgfoid::regproc AS tgfname, "
...@@ -5384,7 +5414,7 @@ getTriggers(TableInfo tblinfo[], int numTables) ...@@ -5384,7 +5414,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
* findFuncByOid(). * findFuncByOid().
*/ */
ProcLangInfo * ProcLangInfo *
getProcLangs(int *numProcLangs) getProcLangs(Archive *fout, int *numProcLangs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -5402,9 +5432,9 @@ getProcLangs(int *numProcLangs) ...@@ -5402,9 +5432,9 @@ getProcLangs(int *numProcLangs)
int i_lanowner; int i_lanowner;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 90000) if (fout->remoteVersion >= 90000)
{ {
/* pg_language has a laninline column */ /* pg_language has a laninline column */
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBuffer(query, "SELECT tableoid, oid, "
...@@ -5416,7 +5446,7 @@ getProcLangs(int *numProcLangs) ...@@ -5416,7 +5446,7 @@ getProcLangs(int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 80300) else if (fout->remoteVersion >= 80300)
{ {
/* pg_language has a lanowner column */ /* pg_language has a lanowner column */
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBuffer(query, "SELECT tableoid, oid, "
...@@ -5428,7 +5458,7 @@ getProcLangs(int *numProcLangs) ...@@ -5428,7 +5458,7 @@ getProcLangs(int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 80100) else if (fout->remoteVersion >= 80100)
{ {
/* Languages are owned by the bootstrap superuser, OID 10 */ /* Languages are owned by the bootstrap superuser, OID 10 */
appendPQExpBuffer(query, "SELECT tableoid, oid, *, " appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
...@@ -5438,7 +5468,7 @@ getProcLangs(int *numProcLangs) ...@@ -5438,7 +5468,7 @@ getProcLangs(int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70400) else if (fout->remoteVersion >= 70400)
{ {
/* Languages are owned by the bootstrap superuser, sysid 1 */ /* Languages are owned by the bootstrap superuser, sysid 1 */
appendPQExpBuffer(query, "SELECT tableoid, oid, *, " appendPQExpBuffer(query, "SELECT tableoid, oid, *, "
...@@ -5448,7 +5478,7 @@ getProcLangs(int *numProcLangs) ...@@ -5448,7 +5478,7 @@ getProcLangs(int *numProcLangs)
"ORDER BY oid", "ORDER BY oid",
username_subquery); username_subquery);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
/* No clear notion of an owner at all before 7.4 ... */ /* No clear notion of an owner at all before 7.4 ... */
appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language " appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language "
...@@ -5511,7 +5541,7 @@ getProcLangs(int *numProcLangs) ...@@ -5511,7 +5541,7 @@ getProcLangs(int *numProcLangs)
else else
planginfo[i].lanowner = pg_strdup(""); planginfo[i].lanowner = pg_strdup("");
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
{ {
/* /*
* We need to make a dependency to ensure the function will be * We need to make a dependency to ensure the function will be
...@@ -5540,7 +5570,7 @@ getProcLangs(int *numProcLangs) ...@@ -5540,7 +5570,7 @@ getProcLangs(int *numProcLangs)
* numCasts is set to the number of casts read in * numCasts is set to the number of casts read in
*/ */
CastInfo * CastInfo *
getCasts(int *numCasts) getCasts(Archive *fout, int *numCasts)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -5556,16 +5586,16 @@ getCasts(int *numCasts) ...@@ -5556,16 +5586,16 @@ getCasts(int *numCasts)
int i_castmethod; int i_castmethod;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 80400) if (fout->remoteVersion >= 80400)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBuffer(query, "SELECT tableoid, oid, "
"castsource, casttarget, castfunc, castcontext, " "castsource, casttarget, castfunc, castcontext, "
"castmethod " "castmethod "
"FROM pg_cast ORDER BY 3,4"); "FROM pg_cast ORDER BY 3,4");
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBuffer(query, "SELECT tableoid, oid, "
"castsource, casttarget, castfunc, castcontext, " "castsource, casttarget, castfunc, castcontext, "
...@@ -5668,7 +5698,7 @@ getCasts(int *numCasts) ...@@ -5668,7 +5698,7 @@ getCasts(int *numCasts)
* modifies tblinfo * modifies tblinfo
*/ */
void void
getTableAttrs(TableInfo *tblinfo, int numTables) getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
{ {
int i, int i,
j; j;
...@@ -5709,7 +5739,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5709,7 +5739,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
* Make sure we are in proper schema for this table; this allows * Make sure we are in proper schema for this table; this allows
* correct retrieval of formatted type names and default exprs * correct retrieval of formatted type names and default exprs
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
/* find all the user attributes and their types */ /* find all the user attributes and their types */
...@@ -5726,7 +5756,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5726,7 +5756,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
resetPQExpBuffer(q); resetPQExpBuffer(q);
if (g_fout->remoteVersion >= 90200) if (fout->remoteVersion >= 90200)
{ {
/* /*
* attfdwoptions is new in 9.2. * attfdwoptions is new in 9.2.
...@@ -5752,7 +5782,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5752,7 +5782,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attrelid, a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 90100) else if (fout->remoteVersion >= 90100)
{ {
/* /*
* attcollation is new in 9.1. Since we only want to dump COLLATE * attcollation is new in 9.1. Since we only want to dump COLLATE
...@@ -5776,7 +5806,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5776,7 +5806,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attrelid, a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 90000) else if (fout->remoteVersion >= 90000)
{ {
/* attoptions is new in 9.0 */ /* attoptions is new in 9.0 */
appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, "
...@@ -5794,7 +5824,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5794,7 +5824,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attrelid, a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
/* need left join here to not fail on dropped columns ... */ /* need left join here to not fail on dropped columns ... */
appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, " appendPQExpBuffer(q, "SELECT a.attnum, a.attname, a.atttypmod, "
...@@ -5811,7 +5841,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5811,7 +5841,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY a.attrelid, a.attnum", "ORDER BY a.attrelid, a.attnum",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
/* /*
* attstattarget doesn't exist in 7.1. It does exist in 7.2, but * attstattarget doesn't exist in 7.1. It does exist in 7.2, but
...@@ -5941,7 +5971,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5941,7 +5971,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tbinfo->dobj.name); tbinfo->dobj.name);
resetPQExpBuffer(q); resetPQExpBuffer(q);
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, " appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, "
"pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc " "pg_catalog.pg_get_expr(adbin, adrelid) AS adsrc "
...@@ -5949,7 +5979,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5949,7 +5979,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"WHERE adrelid = '%u'::pg_catalog.oid", "WHERE adrelid = '%u'::pg_catalog.oid",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70200) else if (fout->remoteVersion >= 70200)
{ {
/* 7.2 did not have OIDs in pg_attrdef */ /* 7.2 did not have OIDs in pg_attrdef */
appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, adnum, " appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, adnum, "
...@@ -5958,7 +5988,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -5958,7 +5988,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"WHERE adrelid = '%u'::oid", "WHERE adrelid = '%u'::oid",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
/* no pg_get_expr, so must rely on adsrc */ /* no pg_get_expr, so must rely on adsrc */
appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, adsrc " appendPQExpBuffer(q, "SELECT tableoid, oid, adnum, adsrc "
...@@ -6044,7 +6074,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6044,7 +6074,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
tbinfo->dobj.name); tbinfo->dobj.name);
resetPQExpBuffer(q); resetPQExpBuffer(q);
if (g_fout->remoteVersion >= 90200) if (fout->remoteVersion >= 90200)
{ {
/* /*
* conisonly and convalidated are new in 9.2 (actually, the latter * conisonly and convalidated are new in 9.2 (actually, the latter
...@@ -6060,7 +6090,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6060,7 +6090,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 80400) else if (fout->remoteVersion >= 80400)
{ {
appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " appendPQExpBuffer(q, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
...@@ -6072,7 +6102,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6072,7 +6102,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70400) else if (fout->remoteVersion >= 70400)
{ {
appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " appendPQExpBuffer(q, "SELECT tableoid, oid, conname, "
"pg_catalog.pg_get_constraintdef(oid) AS consrc, " "pg_catalog.pg_get_constraintdef(oid) AS consrc, "
...@@ -6084,7 +6114,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6084,7 +6114,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
/* no pg_get_constraintdef, must use consrc */ /* no pg_get_constraintdef, must use consrc */
appendPQExpBuffer(q, "SELECT tableoid, oid, conname, " appendPQExpBuffer(q, "SELECT tableoid, oid, conname, "
...@@ -6097,7 +6127,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6097,7 +6127,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY conname", "ORDER BY conname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70200) else if (fout->remoteVersion >= 70200)
{ {
/* 7.2 did not have OIDs in pg_relcheck */ /* 7.2 did not have OIDs in pg_relcheck */
appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, " appendPQExpBuffer(q, "SELECT tableoid, 0 AS oid, "
...@@ -6110,7 +6140,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6110,7 +6140,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
"ORDER BY rcname", "ORDER BY rcname",
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(q, "SELECT tableoid, oid, " appendPQExpBuffer(q, "SELECT tableoid, oid, "
"rcname AS conname, " "rcname AS conname, "
...@@ -6219,7 +6249,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables) ...@@ -6219,7 +6249,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
* numTSParsers is set to the number of parsers read in * numTSParsers is set to the number of parsers read in
*/ */
TSParserInfo * TSParserInfo *
getTSParsers(int *numTSParsers) getTSParsers(Archive *fout, int *numTSParsers)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6237,7 +6267,7 @@ getTSParsers(int *numTSParsers) ...@@ -6237,7 +6267,7 @@ getTSParsers(int *numTSParsers)
int i_prslextype; int i_prslextype;
/* Before 8.3, there is no built-in text search support */ /* Before 8.3, there is no built-in text search support */
if (g_fout->remoteVersion < 80300) if (fout->remoteVersion < 80300)
{ {
*numTSParsers = 0; *numTSParsers = 0;
return NULL; return NULL;
...@@ -6249,7 +6279,7 @@ getTSParsers(int *numTSParsers) ...@@ -6249,7 +6279,7 @@ getTSParsers(int *numTSParsers)
*/ */
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, prsname, prsnamespace, " appendPQExpBuffer(query, "SELECT tableoid, oid, prsname, prsnamespace, "
"prsstart::oid, prstoken::oid, " "prsstart::oid, prstoken::oid, "
...@@ -6281,7 +6311,9 @@ getTSParsers(int *numTSParsers) ...@@ -6281,7 +6311,9 @@ getTSParsers(int *numTSParsers)
prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); prsinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&prsinfo[i].dobj); AssignDumpId(&prsinfo[i].dobj);
prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname)); prsinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_prsname));
prsinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_prsnamespace)), prsinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_prsnamespace)),
prsinfo[i].dobj.catId.oid); prsinfo[i].dobj.catId.oid);
prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart)); prsinfo[i].prsstart = atooid(PQgetvalue(res, i, i_prsstart));
prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken)); prsinfo[i].prstoken = atooid(PQgetvalue(res, i, i_prstoken));
...@@ -6308,7 +6340,7 @@ getTSParsers(int *numTSParsers) ...@@ -6308,7 +6340,7 @@ getTSParsers(int *numTSParsers)
* numTSDicts is set to the number of dictionaries read in * numTSDicts is set to the number of dictionaries read in
*/ */
TSDictInfo * TSDictInfo *
getTSDictionaries(int *numTSDicts) getTSDictionaries(Archive *fout, int *numTSDicts)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6324,14 +6356,14 @@ getTSDictionaries(int *numTSDicts) ...@@ -6324,14 +6356,14 @@ getTSDictionaries(int *numTSDicts)
int i_dictinitoption; int i_dictinitoption;
/* Before 8.3, there is no built-in text search support */ /* Before 8.3, there is no built-in text search support */
if (g_fout->remoteVersion < 80300) if (fout->remoteVersion < 80300)
{ {
*numTSDicts = 0; *numTSDicts = 0;
return NULL; return NULL;
} }
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, dictname, " appendPQExpBuffer(query, "SELECT tableoid, oid, dictname, "
"dictnamespace, (%s dictowner) AS rolname, " "dictnamespace, (%s dictowner) AS rolname, "
...@@ -6362,7 +6394,9 @@ getTSDictionaries(int *numTSDicts) ...@@ -6362,7 +6394,9 @@ getTSDictionaries(int *numTSDicts)
dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); dictinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&dictinfo[i].dobj); AssignDumpId(&dictinfo[i].dobj);
dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname)); dictinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_dictname));
dictinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_dictnamespace)), dictinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_dictnamespace)),
dictinfo[i].dobj.catId.oid); dictinfo[i].dobj.catId.oid);
dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); dictinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate)); dictinfo[i].dicttemplate = atooid(PQgetvalue(res, i, i_dicttemplate));
...@@ -6390,7 +6424,7 @@ getTSDictionaries(int *numTSDicts) ...@@ -6390,7 +6424,7 @@ getTSDictionaries(int *numTSDicts)
* numTSTemplates is set to the number of templates read in * numTSTemplates is set to the number of templates read in
*/ */
TSTemplateInfo * TSTemplateInfo *
getTSTemplates(int *numTSTemplates) getTSTemplates(Archive *fout, int *numTSTemplates)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6405,14 +6439,14 @@ getTSTemplates(int *numTSTemplates) ...@@ -6405,14 +6439,14 @@ getTSTemplates(int *numTSTemplates)
int i_tmpllexize; int i_tmpllexize;
/* Before 8.3, there is no built-in text search support */ /* Before 8.3, there is no built-in text search support */
if (g_fout->remoteVersion < 80300) if (fout->remoteVersion < 80300)
{ {
*numTSTemplates = 0; *numTSTemplates = 0;
return NULL; return NULL;
} }
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, tmplname, " appendPQExpBuffer(query, "SELECT tableoid, oid, tmplname, "
"tmplnamespace, tmplinit::oid, tmpllexize::oid " "tmplnamespace, tmplinit::oid, tmpllexize::oid "
...@@ -6440,7 +6474,9 @@ getTSTemplates(int *numTSTemplates) ...@@ -6440,7 +6474,9 @@ getTSTemplates(int *numTSTemplates)
tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); tmplinfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&tmplinfo[i].dobj); AssignDumpId(&tmplinfo[i].dobj);
tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname)); tmplinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_tmplname));
tmplinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_tmplnamespace)), tmplinfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_tmplnamespace)),
tmplinfo[i].dobj.catId.oid); tmplinfo[i].dobj.catId.oid);
tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit)); tmplinfo[i].tmplinit = atooid(PQgetvalue(res, i, i_tmplinit));
tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize)); tmplinfo[i].tmpllexize = atooid(PQgetvalue(res, i, i_tmpllexize));
...@@ -6464,7 +6500,7 @@ getTSTemplates(int *numTSTemplates) ...@@ -6464,7 +6500,7 @@ getTSTemplates(int *numTSTemplates)
* numTSConfigs is set to the number of configurations read in * numTSConfigs is set to the number of configurations read in
*/ */
TSConfigInfo * TSConfigInfo *
getTSConfigurations(int *numTSConfigs) getTSConfigurations(Archive *fout, int *numTSConfigs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6479,14 +6515,14 @@ getTSConfigurations(int *numTSConfigs) ...@@ -6479,14 +6515,14 @@ getTSConfigurations(int *numTSConfigs)
int i_cfgparser; int i_cfgparser;
/* Before 8.3, there is no built-in text search support */ /* Before 8.3, there is no built-in text search support */
if (g_fout->remoteVersion < 80300) if (fout->remoteVersion < 80300)
{ {
*numTSConfigs = 0; *numTSConfigs = 0;
return NULL; return NULL;
} }
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, cfgname, " appendPQExpBuffer(query, "SELECT tableoid, oid, cfgname, "
"cfgnamespace, (%s cfgowner) AS rolname, cfgparser " "cfgnamespace, (%s cfgowner) AS rolname, cfgparser "
...@@ -6515,7 +6551,9 @@ getTSConfigurations(int *numTSConfigs) ...@@ -6515,7 +6551,9 @@ getTSConfigurations(int *numTSConfigs)
cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid)); cfginfo[i].dobj.catId.oid = atooid(PQgetvalue(res, i, i_oid));
AssignDumpId(&cfginfo[i].dobj); AssignDumpId(&cfginfo[i].dobj);
cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname)); cfginfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_cfgname));
cfginfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_cfgnamespace)), cfginfo[i].dobj.namespace =
findNamespace(fout,
atooid(PQgetvalue(res, i, i_cfgnamespace)),
cfginfo[i].dobj.catId.oid); cfginfo[i].dobj.catId.oid);
cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); cfginfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser)); cfginfo[i].cfgparser = atooid(PQgetvalue(res, i, i_cfgparser));
...@@ -6539,7 +6577,7 @@ getTSConfigurations(int *numTSConfigs) ...@@ -6539,7 +6577,7 @@ getTSConfigurations(int *numTSConfigs)
* numForeignDataWrappers is set to the number of fdws read in * numForeignDataWrappers is set to the number of fdws read in
*/ */
FdwInfo * FdwInfo *
getForeignDataWrappers(int *numForeignDataWrappers) getForeignDataWrappers(Archive *fout, int *numForeignDataWrappers)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6556,16 +6594,16 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -6556,16 +6594,16 @@ getForeignDataWrappers(int *numForeignDataWrappers)
int i_fdwoptions; int i_fdwoptions;
/* Before 8.4, there are no foreign-data wrappers */ /* Before 8.4, there are no foreign-data wrappers */
if (g_fout->remoteVersion < 80400) if (fout->remoteVersion < 80400)
{ {
*numForeignDataWrappers = 0; *numForeignDataWrappers = 0;
return NULL; return NULL;
} }
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (g_fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, " appendPQExpBuffer(query, "SELECT tableoid, oid, fdwname, "
"(%s fdwowner) AS rolname, " "(%s fdwowner) AS rolname, "
...@@ -6646,7 +6684,7 @@ getForeignDataWrappers(int *numForeignDataWrappers) ...@@ -6646,7 +6684,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
* numForeignServers is set to the number of servers read in * numForeignServers is set to the number of servers read in
*/ */
ForeignServerInfo * ForeignServerInfo *
getForeignServers(int *numForeignServers) getForeignServers(Archive *fout, int *numForeignServers)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -6664,14 +6702,14 @@ getForeignServers(int *numForeignServers) ...@@ -6664,14 +6702,14 @@ getForeignServers(int *numForeignServers)
int i_srvoptions; int i_srvoptions;
/* Before 8.4, there are no foreign servers */ /* Before 8.4, there are no foreign servers */
if (g_fout->remoteVersion < 80400) if (fout->remoteVersion < 80400)
{ {
*numForeignServers = 0; *numForeignServers = 0;
return NULL; return NULL;
} }
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout,"pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, " appendPQExpBuffer(query, "SELECT tableoid, oid, srvname, "
"(%s srvowner) AS rolname, " "(%s srvowner) AS rolname, "
...@@ -6737,7 +6775,7 @@ getForeignServers(int *numForeignServers) ...@@ -6737,7 +6775,7 @@ getForeignServers(int *numForeignServers)
* numDefaultACLs is set to the number of ACLs read in * numDefaultACLs is set to the number of ACLs read in
*/ */
DefaultACLInfo * DefaultACLInfo *
getDefaultACLs(int *numDefaultACLs) getDefaultACLs(Archive *fout, int *numDefaultACLs)
{ {
DefaultACLInfo *daclinfo; DefaultACLInfo *daclinfo;
PQExpBuffer query; PQExpBuffer query;
...@@ -6751,7 +6789,7 @@ getDefaultACLs(int *numDefaultACLs) ...@@ -6751,7 +6789,7 @@ getDefaultACLs(int *numDefaultACLs)
int i, int i,
ntups; ntups;
if (g_fout->remoteVersion < 90000) if (fout->remoteVersion < 90000)
{ {
*numDefaultACLs = 0; *numDefaultACLs = 0;
return NULL; return NULL;
...@@ -6760,7 +6798,7 @@ getDefaultACLs(int *numDefaultACLs) ...@@ -6760,7 +6798,7 @@ getDefaultACLs(int *numDefaultACLs)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT oid, tableoid, " appendPQExpBuffer(query, "SELECT oid, tableoid, "
"(%s defaclrole) AS defaclrole, " "(%s defaclrole) AS defaclrole, "
...@@ -6797,7 +6835,7 @@ getDefaultACLs(int *numDefaultACLs) ...@@ -6797,7 +6835,7 @@ getDefaultACLs(int *numDefaultACLs)
daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype)); daclinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_defaclobjtype));
if (nspid != InvalidOid) if (nspid != InvalidOid)
daclinfo[i].dobj.namespace = findNamespace(nspid, daclinfo[i].dobj.namespace = findNamespace(fout, nspid,
daclinfo[i].dobj.catId.oid); daclinfo[i].dobj.catId.oid);
else else
daclinfo[i].dobj.namespace = NULL; daclinfo[i].dobj.namespace = NULL;
...@@ -7505,7 +7543,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -7505,7 +7543,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
char *label; char *label;
/* Set proper schema search path */ /* Set proper schema search path */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
appendPQExpBuffer(query, "SELECT oid, enumlabel " appendPQExpBuffer(query, "SELECT oid, enumlabel "
...@@ -7627,7 +7665,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -7627,7 +7665,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
* select appropriate schema to ensure names in CREATE are properly * select appropriate schema to ensure names in CREATE are properly
* qualified * qualified
*/ */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, " "SELECT pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
...@@ -7776,7 +7814,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -7776,7 +7814,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
bool typdefault_is_literal = false; bool typdefault_is_literal = false;
/* Set proper schema search path so regproc references list correctly */ /* Set proper schema search path so regproc references list correctly */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
/* Fetch type-specific details */ /* Fetch type-specific details */
if (fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
...@@ -8059,8 +8097,8 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8059,8 +8097,8 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
char *elemType; char *elemType;
/* reselect schema in case changed by function dump */ /* reselect schema in case changed by function dump */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
elemType = getFormattedTypeName(tyinfo->typelem, zeroAsOpaque); elemType = getFormattedTypeName(fout, tyinfo->typelem, zeroAsOpaque);
appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType); appendPQExpBuffer(q, ",\n ELEMENT = %s", elemType);
free(elemType); free(elemType);
} }
...@@ -8154,7 +8192,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8154,7 +8192,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
bool typdefault_is_literal = false; bool typdefault_is_literal = false;
/* Set proper schema search path so type references list correctly */ /* Set proper schema search path so type references list correctly */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
/* Fetch domain specific details */ /* Fetch domain specific details */
if (fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
...@@ -8325,7 +8363,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8325,7 +8363,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
int actual_atts; int actual_atts;
/* Set proper schema search path so type references list correctly */ /* Set proper schema search path so type references list correctly */
selectSourceSchema(tyinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tyinfo->dobj.namespace->dobj.name);
/* Fetch type specific details */ /* Fetch type specific details */
if (fout->remoteVersion >= 90100) if (fout->remoteVersion >= 90100)
...@@ -8888,7 +8926,8 @@ format_function_arguments(FuncInfo *finfo, char *funcargs) ...@@ -8888,7 +8926,8 @@ format_function_arguments(FuncInfo *finfo, char *funcargs)
* Any or all of allargtypes, argmodes, argnames may be NULL. * Any or all of allargtypes, argmodes, argnames may be NULL.
*/ */
static char * static char *
format_function_arguments_old(FuncInfo *finfo, int nallargs, format_function_arguments_old(Archive *fout,
FuncInfo *finfo, int nallargs,
char **allargtypes, char **allargtypes,
char **argmodes, char **argmodes,
char **argnames) char **argnames)
...@@ -8906,7 +8945,7 @@ format_function_arguments_old(FuncInfo *finfo, int nallargs, ...@@ -8906,7 +8945,7 @@ format_function_arguments_old(FuncInfo *finfo, int nallargs,
const char *argname; const char *argname;
typid = allargtypes ? atooid(allargtypes[j]) : finfo->argtypes[j]; typid = allargtypes ? atooid(allargtypes[j]) : finfo->argtypes[j];
typname = getFormattedTypeName(typid, zeroAsOpaque); typname = getFormattedTypeName(fout, typid, zeroAsOpaque);
if (argmodes) if (argmodes)
{ {
...@@ -8957,7 +8996,7 @@ format_function_arguments_old(FuncInfo *finfo, int nallargs, ...@@ -8957,7 +8996,7 @@ format_function_arguments_old(FuncInfo *finfo, int nallargs,
* This is appropriate for use in TOC tags, but not in SQL commands. * This is appropriate for use in TOC tags, but not in SQL commands.
*/ */
static char * static char *
format_function_signature(FuncInfo *finfo, bool honor_quotes) format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
{ {
PQExpBufferData fn; PQExpBufferData fn;
int j; int j;
...@@ -8971,7 +9010,8 @@ format_function_signature(FuncInfo *finfo, bool honor_quotes) ...@@ -8971,7 +9010,8 @@ format_function_signature(FuncInfo *finfo, bool honor_quotes)
{ {
char *typname; char *typname;
typname = getFormattedTypeName(finfo->argtypes[j], zeroAsOpaque); typname = getFormattedTypeName(fout, finfo->argtypes[j],
zeroAsOpaque);
appendPQExpBuffer(&fn, "%s%s", appendPQExpBuffer(&fn, "%s%s",
(j > 0) ? ", " : "", (j > 0) ? ", " : "",
...@@ -9037,7 +9077,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9037,7 +9077,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
asPart = createPQExpBuffer(); asPart = createPQExpBuffer();
/* Set proper schema search path so type references list correctly */ /* Set proper schema search path so type references list correctly */
selectSourceSchema(finfo->dobj.namespace->dobj.name); selectSourceSchema(fout, finfo->dobj.namespace->dobj.name);
/* Fetch function-specific details */ /* Fetch function-specific details */
if (fout->remoteVersion >= 80400) if (fout->remoteVersion >= 80400)
...@@ -9114,7 +9154,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9114,7 +9154,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
"WHERE oid = '%u'::pg_catalog.oid", "WHERE oid = '%u'::pg_catalog.oid",
finfo->dobj.catId.oid); finfo->dobj.catId.oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT proretset, prosrc, probin, " "SELECT proretset, prosrc, probin, "
...@@ -9166,7 +9206,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9166,7 +9206,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
proretset = PQgetvalue(res, 0, PQfnumber(res, "proretset")); proretset = PQgetvalue(res, 0, PQfnumber(res, "proretset"));
prosrc = PQgetvalue(res, 0, PQfnumber(res, "prosrc")); prosrc = PQgetvalue(res, 0, PQfnumber(res, "prosrc"));
probin = PQgetvalue(res, 0, PQfnumber(res, "probin")); probin = PQgetvalue(res, 0, PQfnumber(res, "probin"));
if (g_fout->remoteVersion >= 80400) if (fout->remoteVersion >= 80400)
{ {
funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs")); funcargs = PQgetvalue(res, 0, PQfnumber(res, "funcargs"));
funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs")); funciargs = PQgetvalue(res, 0, PQfnumber(res, "funciargs"));
...@@ -9294,12 +9334,13 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9294,12 +9334,13 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
else else
{ {
/* pre-8.4, do it ourselves */ /* pre-8.4, do it ourselves */
funcsig = format_function_arguments_old(finfo, nallargs, allargtypes, funcsig = format_function_arguments_old(fout,
finfo, nallargs, allargtypes,
argmodes, argnames); argmodes, argnames);
funcfullsig = funcsig; funcfullsig = funcsig;
} }
funcsig_tag = format_function_signature(finfo, false); funcsig_tag = format_function_signature(fout, finfo, false);
/* /*
* DROP must be fully qualified in case same name appears in pg_catalog * DROP must be fully qualified in case same name appears in pg_catalog
...@@ -9313,7 +9354,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9313,7 +9354,8 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
appendPQExpBuffer(q, "RETURNS %s", funcresult); appendPQExpBuffer(q, "RETURNS %s", funcresult);
else else
{ {
rettypename = getFormattedTypeName(finfo->prorettype, zeroAsOpaque); rettypename = getFormattedTypeName(fout, finfo->prorettype,
zeroAsOpaque);
appendPQExpBuffer(q, "RETURNS %s%s", appendPQExpBuffer(q, "RETURNS %s%s",
(proretset[0] == 't') ? "SETOF " : "", (proretset[0] == 't') ? "SETOF " : "",
rettypename); rettypename);
...@@ -9515,19 +9557,19 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -9515,19 +9557,19 @@ dumpCast(Archive *fout, CastInfo *cast)
} }
/* Make sure we are in proper schema (needed for getFormattedTypeName) */ /* Make sure we are in proper schema (needed for getFormattedTypeName) */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
defqry = createPQExpBuffer(); defqry = createPQExpBuffer();
delqry = createPQExpBuffer(); delqry = createPQExpBuffer();
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n", appendPQExpBuffer(delqry, "DROP CAST (%s AS %s);\n",
getFormattedTypeName(cast->castsource, zeroAsNone), getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(cast->casttarget, zeroAsNone)); getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ", appendPQExpBuffer(defqry, "CREATE CAST (%s AS %s) ",
getFormattedTypeName(cast->castsource, zeroAsNone), getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(cast->casttarget, zeroAsNone)); getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
switch (cast->castmethod) switch (cast->castmethod)
{ {
...@@ -9546,7 +9588,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -9546,7 +9588,7 @@ dumpCast(Archive *fout, CastInfo *cast)
appendPQExpBuffer(defqry, "WITH FUNCTION %s.", appendPQExpBuffer(defqry, "WITH FUNCTION %s.",
fmtId(funcInfo->dobj.namespace->dobj.name)); fmtId(funcInfo->dobj.namespace->dobj.name));
appendPQExpBuffer(defqry, "%s", appendPQExpBuffer(defqry, "%s",
format_function_signature(funcInfo, true)); format_function_signature(fout, funcInfo, true));
break; break;
default: default:
write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n"); write_msg(NULL, "WARNING: bogus value in pg_cast.castmethod field\n");
...@@ -9559,8 +9601,8 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -9559,8 +9601,8 @@ dumpCast(Archive *fout, CastInfo *cast)
appendPQExpBuffer(defqry, ";\n"); appendPQExpBuffer(defqry, ";\n");
appendPQExpBuffer(labelq, "CAST (%s AS %s)", appendPQExpBuffer(labelq, "CAST (%s AS %s)",
getFormattedTypeName(cast->castsource, zeroAsNone), getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(cast->casttarget, zeroAsNone)); getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data); binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
...@@ -9639,7 +9681,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -9639,7 +9681,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
details = createPQExpBuffer(); details = createPQExpBuffer();
/* Make sure we are in proper schema so regoperator works correctly */ /* Make sure we are in proper schema so regoperator works correctly */
selectSourceSchema(oprinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, oprinfo->dobj.namespace->dobj.name);
if (fout->remoteVersion >= 80300) if (fout->remoteVersion >= 80300)
{ {
...@@ -9738,7 +9780,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -9738,7 +9780,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
oprcanhash = PQgetvalue(res, 0, i_oprcanhash); oprcanhash = PQgetvalue(res, 0, i_oprcanhash);
appendPQExpBuffer(details, " PROCEDURE = %s", appendPQExpBuffer(details, " PROCEDURE = %s",
convertRegProcReference(oprcode)); convertRegProcReference(fout, oprcode));
appendPQExpBuffer(oprid, "%s (", appendPQExpBuffer(oprid, "%s (",
oprinfo->dobj.name); oprinfo->dobj.name);
...@@ -9773,11 +9815,11 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -9773,11 +9815,11 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
else else
appendPQExpBuffer(oprid, ", NONE)"); appendPQExpBuffer(oprid, ", NONE)");
name = convertOperatorReference(oprcom); name = convertOperatorReference(fout, oprcom);
if (name) if (name)
appendPQExpBuffer(details, ",\n COMMUTATOR = %s", name); appendPQExpBuffer(details, ",\n COMMUTATOR = %s", name);
name = convertOperatorReference(oprnegate); name = convertOperatorReference(fout, oprnegate);
if (name) if (name)
appendPQExpBuffer(details, ",\n NEGATOR = %s", name); appendPQExpBuffer(details, ",\n NEGATOR = %s", name);
...@@ -9787,11 +9829,11 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -9787,11 +9829,11 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
if (strcmp(oprcanhash, "t") == 0) if (strcmp(oprcanhash, "t") == 0)
appendPQExpBuffer(details, ",\n HASHES"); appendPQExpBuffer(details, ",\n HASHES");
name = convertRegProcReference(oprrest); name = convertRegProcReference(fout, oprrest);
if (name) if (name)
appendPQExpBuffer(details, ",\n RESTRICT = %s", name); appendPQExpBuffer(details, ",\n RESTRICT = %s", name);
name = convertRegProcReference(oprjoin); name = convertRegProcReference(fout, oprjoin);
if (name) if (name)
appendPQExpBuffer(details, ",\n JOIN = %s", name); appendPQExpBuffer(details, ",\n JOIN = %s", name);
...@@ -9844,13 +9886,13 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -9844,13 +9886,13 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
* argument-types part. In prior versions, the input is a REGPROC display. * argument-types part. In prior versions, the input is a REGPROC display.
*/ */
static const char * static const char *
convertRegProcReference(const char *proc) convertRegProcReference(Archive *fout, const char *proc)
{ {
/* In all cases "-" means a null reference */ /* In all cases "-" means a null reference */
if (strcmp(proc, "-") == 0) if (strcmp(proc, "-") == 0)
return NULL; return NULL;
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
char *name; char *name;
char *paren; char *paren;
...@@ -9887,7 +9929,7 @@ convertRegProcReference(const char *proc) ...@@ -9887,7 +9929,7 @@ convertRegProcReference(const char *proc)
* which we search our operator list for. * which we search our operator list for.
*/ */
static const char * static const char *
convertOperatorReference(const char *opr) convertOperatorReference(Archive *fout, const char *opr)
{ {
OprInfo *oprInfo; OprInfo *oprInfo;
...@@ -9895,7 +9937,7 @@ convertOperatorReference(const char *opr) ...@@ -9895,7 +9937,7 @@ convertOperatorReference(const char *opr)
if (strcmp(opr, "0") == 0) if (strcmp(opr, "0") == 0)
return NULL; return NULL;
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
char *name; char *name;
char *oname; char *oname;
...@@ -10043,7 +10085,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10043,7 +10085,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema so regoperator works correctly */ /* Make sure we are in proper schema so regoperator works correctly */
selectSourceSchema(opcinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, opcinfo->dobj.namespace->dobj.name);
/* Get additional fields from the pg_opclass row */ /* Get additional fields from the pg_opclass row */
if (fout->remoteVersion >= 80300) if (fout->remoteVersion >= 80300)
...@@ -10425,7 +10467,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -10425,7 +10467,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema so regoperator works correctly */ /* Make sure we are in proper schema so regoperator works correctly */
selectSourceSchema(opfinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, opfinfo->dobj.namespace->dobj.name);
/* /*
* Fetch only those opfamily members that are tied directly to the * Fetch only those opfamily members that are tied directly to the
...@@ -10723,7 +10765,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -10723,7 +10765,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(collinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, collinfo->dobj.namespace->dobj.name);
/* Get conversion-specific details */ /* Get conversion-specific details */
appendPQExpBuffer(query, "SELECT " appendPQExpBuffer(query, "SELECT "
...@@ -10828,7 +10870,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -10828,7 +10870,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(convinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, convinfo->dobj.namespace->dobj.name);
/* Get conversion-specific details */ /* Get conversion-specific details */
appendPQExpBuffer(query, "SELECT " appendPQExpBuffer(query, "SELECT "
...@@ -10936,7 +10978,8 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -10936,7 +10978,8 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
{ {
char *typname; char *typname;
typname = getFormattedTypeName(agginfo->aggfn.argtypes[j], zeroAsOpaque); typname = getFormattedTypeName(fout, agginfo->aggfn.argtypes[j],
zeroAsOpaque);
appendPQExpBuffer(&buf, "%s%s", appendPQExpBuffer(&buf, "%s%s",
(j > 0) ? ", " : "", (j > 0) ? ", " : "",
...@@ -10988,7 +11031,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -10988,7 +11031,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
details = createPQExpBuffer(); details = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(agginfo->aggfn.dobj.namespace->dobj.name); selectSourceSchema(fout, agginfo->aggfn.dobj.namespace->dobj.name);
/* Get aggregate-specific details */ /* Get aggregate-specific details */
if (fout->remoteVersion >= 80100) if (fout->remoteVersion >= 80100)
...@@ -11112,7 +11155,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11112,7 +11155,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
aggfinalfn); aggfinalfn);
} }
aggsortop = convertOperatorReference(aggsortop); aggsortop = convertOperatorReference(fout, aggsortop);
if (aggsortop) if (aggsortop)
{ {
appendPQExpBuffer(details, ",\n SORTOP = %s", appendPQExpBuffer(details, ",\n SORTOP = %s",
...@@ -11160,8 +11203,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11160,8 +11203,8 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
free(aggsig); free(aggsig);
free(aggsig_tag); free(aggsig_tag);
aggsig = format_function_signature(&agginfo->aggfn, true); aggsig = format_function_signature(fout, &agginfo->aggfn, true);
aggsig_tag = format_function_signature(&agginfo->aggfn, false); aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false);
dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId, dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
"FUNCTION", "FUNCTION",
...@@ -11201,7 +11244,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) ...@@ -11201,7 +11244,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(prsinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, prsinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(q, "CREATE TEXT SEARCH PARSER %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH PARSER %s (\n",
fmtId(prsinfo->dobj.name)); fmtId(prsinfo->dobj.name));
...@@ -11278,7 +11321,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -11278,7 +11321,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Fetch name and namespace of the dictionary's template */ /* Fetch name and namespace of the dictionary's template */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT nspname, tmplname " appendPQExpBuffer(query, "SELECT nspname, tmplname "
"FROM pg_ts_template p, pg_namespace n " "FROM pg_ts_template p, pg_namespace n "
"WHERE p.oid = '%u' AND n.oid = tmplnamespace", "WHERE p.oid = '%u' AND n.oid = tmplnamespace",
...@@ -11298,7 +11341,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -11298,7 +11341,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
tmplname = PQgetvalue(res, 0, 1); tmplname = PQgetvalue(res, 0, 1);
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(dictinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, dictinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(q, "CREATE TEXT SEARCH DICTIONARY %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH DICTIONARY %s (\n",
fmtId(dictinfo->dobj.name)); fmtId(dictinfo->dobj.name));
...@@ -11371,7 +11414,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) ...@@ -11371,7 +11414,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(tmplinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tmplinfo->dobj.namespace->dobj.name);
appendPQExpBuffer(q, "CREATE TEXT SEARCH TEMPLATE %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH TEMPLATE %s (\n",
fmtId(tmplinfo->dobj.name)); fmtId(tmplinfo->dobj.name));
...@@ -11445,7 +11488,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -11445,7 +11488,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
query = createPQExpBuffer(); query = createPQExpBuffer();
/* Fetch name and namespace of the config's parser */ /* Fetch name and namespace of the config's parser */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT nspname, prsname " appendPQExpBuffer(query, "SELECT nspname, prsname "
"FROM pg_ts_parser p, pg_namespace n " "FROM pg_ts_parser p, pg_namespace n "
"WHERE p.oid = '%u' AND n.oid = prsnamespace", "WHERE p.oid = '%u' AND n.oid = prsnamespace",
...@@ -11465,7 +11508,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -11465,7 +11508,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
prsname = PQgetvalue(res, 0, 1); prsname = PQgetvalue(res, 0, 1);
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(cfginfo->dobj.namespace->dobj.name); selectSourceSchema(fout, cfginfo->dobj.namespace->dobj.name);
appendPQExpBuffer(q, "CREATE TEXT SEARCH CONFIGURATION %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH CONFIGURATION %s (\n",
fmtId(cfginfo->dobj.name)); fmtId(cfginfo->dobj.name));
...@@ -11666,7 +11709,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -11666,7 +11709,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
qsrvname = pg_strdup(fmtId(srvinfo->dobj.name)); qsrvname = pg_strdup(fmtId(srvinfo->dobj.name));
/* look up the foreign-data wrapper */ /* look up the foreign-data wrapper */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT fdwname " appendPQExpBuffer(query, "SELECT fdwname "
"FROM pg_foreign_data_wrapper w " "FROM pg_foreign_data_wrapper w "
"WHERE w.oid = '%u'", "WHERE w.oid = '%u'",
...@@ -11783,7 +11826,7 @@ dumpUserMappings(Archive *fout, ...@@ -11783,7 +11826,7 @@ dumpUserMappings(Archive *fout,
* OPTIONS clause. A possible alternative is to skip such mappings * OPTIONS clause. A possible alternative is to skip such mappings
* altogether, but it's not clear that that's an improvement. * altogether, but it's not clear that that's an improvement.
*/ */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT usename, " "SELECT usename, "
...@@ -12363,7 +12406,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -12363,7 +12406,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
k; k;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
if (binary_upgrade) if (binary_upgrade)
binary_upgrade_set_type_oids_by_rel_oid(q, binary_upgrade_set_type_oids_by_rel_oid(q,
...@@ -13353,7 +13396,7 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) ...@@ -13353,7 +13396,7 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
* pg_database entry for the current database * pg_database entry for the current database
*/ */
static Oid static Oid
findLastBuiltinOid_V71(const char *dbname) findLastBuiltinOid_V71(Archive *fout, const char *dbname)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -13362,7 +13405,7 @@ findLastBuiltinOid_V71(const char *dbname) ...@@ -13362,7 +13405,7 @@ findLastBuiltinOid_V71(const char *dbname)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = "); appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = ");
appendStringLiteralAH(query, dbname, g_fout); appendStringLiteralAH(query, dbname, fout);
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK); check_sql_result(res, g_conn, query->data, PGRES_TUPLES_OK);
...@@ -13439,7 +13482,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) ...@@ -13439,7 +13482,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer labelq = createPQExpBuffer();
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE); snprintf(bufm, sizeof(bufm), INT64_FORMAT, SEQ_MINVALUE);
snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE); snprintf(bufx, sizeof(bufx), INT64_FORMAT, SEQ_MAXVALUE);
...@@ -13897,7 +13940,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -13897,7 +13940,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
/* /*
* Make sure we are in proper schema. * Make sure we are in proper schema.
*/ */
selectSourceSchema(tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
query = createPQExpBuffer(); query = createPQExpBuffer();
cmd = createPQExpBuffer(); cmd = createPQExpBuffer();
...@@ -14000,7 +14043,8 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -14000,7 +14043,8 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
* getExtensionMembership --- obtain extension membership data * getExtensionMembership --- obtain extension membership data
*/ */
void void
getExtensionMembership(ExtensionInfo extinfo[], int numExtensions) getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
int numExtensions)
{ {
PQExpBuffer query; PQExpBuffer query;
PGresult *res; PGresult *res;
...@@ -14018,7 +14062,7 @@ getExtensionMembership(ExtensionInfo extinfo[], int numExtensions) ...@@ -14018,7 +14062,7 @@ getExtensionMembership(ExtensionInfo extinfo[], int numExtensions)
return; return;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -14161,7 +14205,7 @@ getExtensionMembership(ExtensionInfo extinfo[], int numExtensions) ...@@ -14161,7 +14205,7 @@ getExtensionMembership(ExtensionInfo extinfo[], int numExtensions)
* getDependencies --- obtain available dependency data * getDependencies --- obtain available dependency data
*/ */
static void static void
getDependencies(void) getDependencies(Archive *fout)
{ {
PQExpBuffer query; PQExpBuffer query;
PGresult *res; PGresult *res;
...@@ -14176,14 +14220,14 @@ getDependencies(void) ...@@ -14176,14 +14220,14 @@ getDependencies(void)
*refdobj; *refdobj;
/* No dependency info available before 7.3 */ /* No dependency info available before 7.3 */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
return; return;
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading dependency data\n"); write_msg(NULL, "reading dependency data\n");
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema("pg_catalog"); selectSourceSchema(fout, "pg_catalog");
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -14291,13 +14335,13 @@ getDependencies(void) ...@@ -14291,13 +14335,13 @@ getDependencies(void)
* references to system catalogs and types in our emitted commands! * references to system catalogs and types in our emitted commands!
*/ */
static void static void
selectSourceSchema(const char *schemaName) selectSourceSchema(Archive *fout, const char *schemaName)
{ {
static char *curSchemaName = NULL; static char *curSchemaName = NULL;
PQExpBuffer query; PQExpBuffer query;
/* Not relevant if fetching from pre-7.3 DB */ /* Not relevant if fetching from pre-7.3 DB */
if (g_fout->remoteVersion < 70300) if (fout->remoteVersion < 70300)
return; return;
/* Ignore null schema names */ /* Ignore null schema names */
if (schemaName == NULL || *schemaName == '\0') if (schemaName == NULL || *schemaName == '\0')
...@@ -14328,7 +14372,7 @@ selectSourceSchema(const char *schemaName) ...@@ -14328,7 +14372,7 @@ selectSourceSchema(const char *schemaName)
* schema; this is why we don't try to cache the names. * schema; this is why we don't try to cache the names.
*/ */
static char * static char *
getFormattedTypeName(Oid oid, OidOptions opts) getFormattedTypeName(Archive *fout, Oid oid, OidOptions opts)
{ {
char *result; char *result;
PQExpBuffer query; PQExpBuffer query;
...@@ -14348,12 +14392,12 @@ getFormattedTypeName(Oid oid, OidOptions opts) ...@@ -14348,12 +14392,12 @@ getFormattedTypeName(Oid oid, OidOptions opts)
} }
query = createPQExpBuffer(); query = createPQExpBuffer();
if (g_fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)", appendPQExpBuffer(query, "SELECT pg_catalog.format_type('%u'::pg_catalog.oid, NULL)",
oid); oid);
} }
else if (g_fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT format_type('%u'::oid, NULL)", appendPQExpBuffer(query, "SELECT format_type('%u'::oid, NULL)",
oid); oid);
...@@ -14380,7 +14424,7 @@ getFormattedTypeName(Oid oid, OidOptions opts) ...@@ -14380,7 +14424,7 @@ getFormattedTypeName(Oid oid, OidOptions opts)
exit_nicely(); exit_nicely();
} }
if (g_fout->remoteVersion >= 70100) if (fout->remoteVersion >= 70100)
{ {
/* already quoted */ /* already quoted */
result = pg_strdup(PQgetvalue(res, 0, 0)); result = pg_strdup(PQgetvalue(res, 0, 0));
...@@ -14474,7 +14518,7 @@ myFormatType(const char *typname, int32 typmod) ...@@ -14474,7 +14518,7 @@ myFormatType(const char *typname, int32 typmod)
* Like fmtId, use the result before calling again. * Like fmtId, use the result before calling again.
*/ */
static const char * static const char *
fmtQualifiedId(const char *schema, const char *id) fmtQualifiedId(Archive *fout, const char *schema, const char *id)
{ {
static PQExpBuffer id_return = NULL; static PQExpBuffer id_return = NULL;
...@@ -14484,7 +14528,7 @@ fmtQualifiedId(const char *schema, const char *id) ...@@ -14484,7 +14528,7 @@ fmtQualifiedId(const char *schema, const char *id)
id_return = createPQExpBuffer(); id_return = createPQExpBuffer();
/* Suppress schema name if fetching from pre-7.3 DB */ /* Suppress schema name if fetching from pre-7.3 DB */
if (g_fout->remoteVersion >= 70300 && schema && *schema) if (fout->remoteVersion >= 70300 && schema && *schema)
{ {
appendPQExpBuffer(id_return, "%s.", appendPQExpBuffer(id_return, "%s.",
fmtId(schema)); fmtId(schema));
......
...@@ -493,7 +493,10 @@ extern char g_opaque_type[10]; /* name for the opaque type */ ...@@ -493,7 +493,10 @@ extern char g_opaque_type[10]; /* name for the opaque type */
* common utility functions * common utility functions
*/ */
extern TableInfo *getSchemaData(int *numTablesPtr); struct Archive;
typedef struct Archive Archive;
extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
typedef enum _OidOptions typedef enum _OidOptions
{ {
...@@ -535,32 +538,35 @@ extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs); ...@@ -535,32 +538,35 @@ extern void sortDumpableObjectsByTypeOid(DumpableObject **objs, int numObjs);
/* /*
* version specific routines * version specific routines
*/ */
extern NamespaceInfo *getNamespaces(int *numNamespaces); extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces);
extern ExtensionInfo *getExtensions(int *numExtensions); extern ExtensionInfo *getExtensions(Archive *fout, int *numExtensions);
extern TypeInfo *getTypes(int *numTypes); extern TypeInfo *getTypes(Archive *fout, int *numTypes);
extern FuncInfo *getFuncs(int *numFuncs); extern FuncInfo *getFuncs(Archive *fout, int *numFuncs);
extern AggInfo *getAggregates(int *numAggregates); extern AggInfo *getAggregates(Archive *fout, int *numAggregates);
extern OprInfo *getOperators(int *numOperators); extern OprInfo *getOperators(Archive *fout, int *numOperators);
extern OpclassInfo *getOpclasses(int *numOpclasses); extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
extern OpfamilyInfo *getOpfamilies(int *numOpfamilies); extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
extern CollInfo *getCollations(int *numCollations); extern CollInfo *getCollations(Archive *fout, int *numCollations);
extern ConvInfo *getConversions(int *numConversions); extern ConvInfo *getConversions(Archive *fout, int *numConversions);
extern TableInfo *getTables(int *numTables); extern TableInfo *getTables(Archive *fout, int *numTables);
extern InhInfo *getInherits(int *numInherits); extern InhInfo *getInherits(Archive *fout, int *numInherits);
extern void getIndexes(TableInfo tblinfo[], int numTables); extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
extern void getConstraints(TableInfo tblinfo[], int numTables); extern void getConstraints(Archive *fout, TableInfo tblinfo[], int numTables);
extern RuleInfo *getRules(int *numRules); extern RuleInfo *getRules(Archive *fout, int *numRules);
extern void getTriggers(TableInfo tblinfo[], int numTables); extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
extern ProcLangInfo *getProcLangs(int *numProcLangs); extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
extern CastInfo *getCasts(int *numCasts); extern CastInfo *getCasts(Archive *fout, int *numCasts);
extern void getTableAttrs(TableInfo *tbinfo, int numTables); extern void getTableAttrs(Archive *fout, TableInfo *tbinfo, int numTables);
extern TSParserInfo *getTSParsers(int *numTSParsers); extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
extern TSDictInfo *getTSDictionaries(int *numTSDicts); extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
extern TSTemplateInfo *getTSTemplates(int *numTSTemplates); extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
extern TSConfigInfo *getTSConfigurations(int *numTSConfigs); extern TSConfigInfo *getTSConfigurations(Archive *fout, int *numTSConfigs);
extern FdwInfo *getForeignDataWrappers(int *numForeignDataWrappers); extern FdwInfo *getForeignDataWrappers(Archive *fout,
extern ForeignServerInfo *getForeignServers(int *numForeignServers); int *numForeignDataWrappers);
extern DefaultACLInfo *getDefaultACLs(int *numDefaultACLs); extern ForeignServerInfo *getForeignServers(Archive *fout,
extern void getExtensionMembership(ExtensionInfo extinfo[], int numExtensions); int *numForeignServers);
extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs);
extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
int numExtensions);
#endif /* PG_DUMP_H */ #endif /* PG_DUMP_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment