Commit 0eea8047 authored by Alvaro Herrera's avatar Alvaro Herrera

pg_dump: Reduce use of global variables

Most pg_dump.c global variables, which were passed down individually to
dumping routines, are now grouped as members of the new DumpOptions
struct, which is used as a local variable and passed down into routines
that need it.  This helps future development efforts; in particular it
is said to enable a mode in which a parallel pg_dump run can output
multiple streams, and have them restored in parallel.

Also take the opportunity to clean up the pg_dump header files somewhat,
to avoid circularity.

Author: Joachim Wieland, revised by Álvaro Herrera
Reviewed by Peter Eisentraut
parent e0d97d77
...@@ -13,8 +13,11 @@ ...@@ -13,8 +13,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "pg_dump.h"
#include <ctype.h> #include <ctype.h>
...@@ -64,7 +67,7 @@ static DumpableObject **nspinfoindex; ...@@ -64,7 +67,7 @@ static DumpableObject **nspinfoindex;
static void flagInhTables(TableInfo *tbinfo, int numTables, static void flagInhTables(TableInfo *tbinfo, int numTables,
InhInfo *inhinfo, int numInherits); InhInfo *inhinfo, int numInherits);
static void flagInhAttrs(TableInfo *tblinfo, int numTables); static void flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables);
static DumpableObject **buildIndexArray(void *objArray, int numObjs, static DumpableObject **buildIndexArray(void *objArray, int numObjs,
Size objSize); Size objSize);
static int DOCatalogIdCompare(const void *p1, const void *p2); static int DOCatalogIdCompare(const void *p1, const void *p2);
...@@ -78,7 +81,7 @@ static int strInArray(const char *pattern, char **arr, int arr_size); ...@@ -78,7 +81,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(Archive *fout, int *numTablesPtr) getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
{ {
ExtensionInfo *extinfo; ExtensionInfo *extinfo;
InhInfo *inhinfo; InhInfo *inhinfo;
...@@ -114,7 +117,7 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -114,7 +117,7 @@ getSchemaData(Archive *fout, 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(fout, &numTables); tblinfo = getTables(fout, dopt, &numTables);
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo)); tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
/* Do this after we've built tblinfoindex */ /* Do this after we've built tblinfoindex */
...@@ -122,11 +125,11 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -122,11 +125,11 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading extensions\n"); write_msg(NULL, "reading extensions\n");
extinfo = getExtensions(fout, &numExtensions); extinfo = getExtensions(fout, dopt, &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(fout, &numFuncs); funinfo = getFuncs(fout, dopt, &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 */
...@@ -142,7 +145,7 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -142,7 +145,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
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(fout, &numAggregates); getAggregates(fout, dopt, &numAggregates);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined operators\n"); write_msg(NULL, "reading user-defined operators\n");
...@@ -183,7 +186,7 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -183,7 +186,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading default privileges\n"); write_msg(NULL, "reading default privileges\n");
getDefaultACLs(fout, &numDefaultACLs); getDefaultACLs(fout, dopt, &numDefaultACLs);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading user-defined collations\n"); write_msg(NULL, "reading user-defined collations\n");
...@@ -213,7 +216,7 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -213,7 +216,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
*/ */
if (g_verbose) if (g_verbose)
write_msg(NULL, "finding extension members\n"); write_msg(NULL, "finding extension members\n");
getExtensionMembership(fout, extinfo, numExtensions); getExtensionMembership(fout, dopt, 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)
...@@ -222,11 +225,11 @@ getSchemaData(Archive *fout, int *numTablesPtr) ...@@ -222,11 +225,11 @@ getSchemaData(Archive *fout, 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(fout, tblinfo, numTables); getTableAttrs(fout, dopt, 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");
flagInhAttrs(tblinfo, numTables); flagInhAttrs(dopt, tblinfo, numTables);
if (g_verbose) if (g_verbose)
write_msg(NULL, "reading indexes\n"); write_msg(NULL, "reading indexes\n");
...@@ -307,7 +310,7 @@ flagInhTables(TableInfo *tblinfo, int numTables, ...@@ -307,7 +310,7 @@ flagInhTables(TableInfo *tblinfo, int numTables,
* modifies tblinfo * modifies tblinfo
*/ */
static void static void
flagInhAttrs(TableInfo *tblinfo, int numTables) flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables)
{ {
int i, int i,
j, j,
...@@ -384,7 +387,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables) ...@@ -384,7 +387,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables)
attrDef->adef_expr = pg_strdup("NULL"); attrDef->adef_expr = pg_strdup("NULL");
/* Will column be dumped explicitly? */ /* Will column be dumped explicitly? */
if (shouldPrintColumn(tbinfo, j)) if (shouldPrintColumn(dopt, tbinfo, j))
{ {
attrDef->separate = false; attrDef->separate = false;
/* No dependency needed: NULL cannot have dependencies */ /* No dependency needed: NULL cannot have dependencies */
......
...@@ -51,10 +51,11 @@ ...@@ -51,10 +51,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "compress_io.h" #include "compress_io.h"
#include "pg_backup_utils.h"
#include "parallel.h" #include "parallel.h"
#include "pg_backup_utils.h"
/*---------------------- /*----------------------
* Compressor API * Compressor API
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef __COMPRESS_IO__ #ifndef __COMPRESS_IO__
#define __COMPRESS_IO__ #define __COMPRESS_IO__
#include "postgres_fe.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
/* Initial buffer sizes used in zlib compression. */ /* Initial buffer sizes used in zlib compression. */
......
...@@ -12,13 +12,29 @@ ...@@ -12,13 +12,29 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef DUMPUTILS_H #ifndef DUMPUTILS_H
#define DUMPUTILS_H #define DUMPUTILS_H
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
/*
* Data structures for simple lists of OIDs and strings. The support for
* these is very primitive compared to the backend's List facilities, but
* it's all we need in pg_dump.
*/
typedef struct SimpleOidListCell
{
struct SimpleOidListCell *next;
Oid val;
} SimpleOidListCell;
typedef struct SimpleOidList
{
SimpleOidListCell *head;
SimpleOidListCell *tail;
} SimpleOidList;
typedef struct SimpleStringListCell typedef struct SimpleStringListCell
{ {
struct SimpleStringListCell *next; struct SimpleStringListCell *next;
...@@ -31,6 +47,7 @@ typedef struct SimpleStringList ...@@ -31,6 +47,7 @@ typedef struct SimpleStringList
SimpleStringListCell *tail; SimpleStringListCell *tail;
} SimpleStringList; } SimpleStringList;
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
extern int quote_all_identifiers; extern int quote_all_identifiers;
extern PQExpBuffer (*getLocalPQExpBuffer) (void); extern PQExpBuffer (*getLocalPQExpBuffer) (void);
......
...@@ -18,8 +18,8 @@ ...@@ -18,8 +18,8 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "pg_backup_utils.h"
#include "parallel.h" #include "parallel.h"
#include "pg_backup_utils.h"
#ifndef WIN32 #ifndef WIN32
#include <sys/types.h> #include <sys/types.h>
...@@ -89,11 +89,12 @@ static void WaitForTerminatingWorkers(ParallelState *pstate); ...@@ -89,11 +89,12 @@ static void WaitForTerminatingWorkers(ParallelState *pstate);
static void sigTermHandler(int signum); static void sigTermHandler(int signum);
#endif #endif
static void SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, static void SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
DumpOptions *dopt,
RestoreOptions *ropt); RestoreOptions *ropt);
static bool HasEveryWorkerTerminated(ParallelState *pstate); static bool HasEveryWorkerTerminated(ParallelState *pstate);
static void lockTableNoWait(ArchiveHandle *AH, TocEntry *te); static void lockTableNoWait(ArchiveHandle *AH, TocEntry *te);
static void WaitForCommands(ArchiveHandle *AH, int pipefd[2]); static void WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2]);
static char *getMessageFromMaster(int pipefd[2]); static char *getMessageFromMaster(int pipefd[2]);
static void sendMessageToMaster(int pipefd[2], const char *str); static void sendMessageToMaster(int pipefd[2], const char *str);
static int select_loop(int maxFd, fd_set *workerset); static int select_loop(int maxFd, fd_set *workerset);
...@@ -436,6 +437,7 @@ sigTermHandler(int signum) ...@@ -436,6 +437,7 @@ sigTermHandler(int signum)
*/ */
static void static void
SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
DumpOptions *dopt,
RestoreOptions *ropt) RestoreOptions *ropt)
{ {
/* /*
...@@ -445,11 +447,11 @@ SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker, ...@@ -445,11 +447,11 @@ SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
* properly when we shut down. This happens only that way when it is * properly when we shut down. This happens only that way when it is
* brought down because of an error. * brought down because of an error.
*/ */
(AH->SetupWorkerPtr) ((Archive *) AH, ropt); (AH->SetupWorkerPtr) ((Archive *) AH, dopt, ropt);
Assert(AH->connection != NULL); Assert(AH->connection != NULL);
WaitForCommands(AH, pipefd); WaitForCommands(AH, dopt, pipefd);
closesocket(pipefd[PIPE_READ]); closesocket(pipefd[PIPE_READ]);
closesocket(pipefd[PIPE_WRITE]); closesocket(pipefd[PIPE_WRITE]);
...@@ -481,7 +483,7 @@ init_spawned_worker_win32(WorkerInfo *wi) ...@@ -481,7 +483,7 @@ init_spawned_worker_win32(WorkerInfo *wi)
* of threads while it does a fork() on Unix. * of threads while it does a fork() on Unix.
*/ */
ParallelState * ParallelState *
ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt) ParallelBackupStart(ArchiveHandle *AH, DumpOptions *dopt, RestoreOptions *ropt)
{ {
ParallelState *pstate; ParallelState *pstate;
int i; int i;
...@@ -598,7 +600,7 @@ ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt) ...@@ -598,7 +600,7 @@ ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt)
closesocket(pstate->parallelSlot[j].pipeWrite); closesocket(pstate->parallelSlot[j].pipeWrite);
} }
SetupWorker(pstate->parallelSlot[i].args->AH, pipefd, i, ropt); SetupWorker(pstate->parallelSlot[i].args->AH, pipefd, i, dopt, ropt);
exit(0); exit(0);
} }
...@@ -856,7 +858,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te) ...@@ -856,7 +858,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te)
* exit. * exit.
*/ */
static void static void
WaitForCommands(ArchiveHandle *AH, int pipefd[2]) WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2])
{ {
char *command; char *command;
DumpId dumpId; DumpId dumpId;
...@@ -896,7 +898,7 @@ WaitForCommands(ArchiveHandle *AH, int pipefd[2]) ...@@ -896,7 +898,7 @@ WaitForCommands(ArchiveHandle *AH, int pipefd[2])
* The message we return here has been pg_malloc()ed and we are * The message we return here has been pg_malloc()ed and we are
* responsible for free()ing it. * responsible for free()ing it.
*/ */
str = (AH->WorkerJobDumpPtr) (AH, te); str = (AH->WorkerJobDumpPtr) (AH, dopt, te);
Assert(AH->connection != NULL); Assert(AH->connection != NULL);
sendMessageToMaster(pipefd, str); sendMessageToMaster(pipefd, str);
free(str); free(str);
......
...@@ -19,10 +19,7 @@ ...@@ -19,10 +19,7 @@
#ifndef PG_DUMP_PARALLEL_H #ifndef PG_DUMP_PARALLEL_H
#define PG_DUMP_PARALLEL_H #define PG_DUMP_PARALLEL_H
#include "pg_backup_db.h" #include "pg_backup_archiver.h"
struct _archiveHandle;
struct _tocEntry;
typedef enum typedef enum
{ {
...@@ -35,8 +32,8 @@ typedef enum ...@@ -35,8 +32,8 @@ typedef enum
/* Arguments needed for a worker process */ /* Arguments needed for a worker process */
typedef struct ParallelArgs typedef struct ParallelArgs
{ {
struct _archiveHandle *AH; ArchiveHandle *AH;
struct _tocEntry *te; TocEntry *te;
} ParallelArgs; } ParallelArgs;
/* State for each parallel activity slot */ /* State for each parallel activity slot */
...@@ -74,22 +71,19 @@ extern void init_parallel_dump_utils(void); ...@@ -74,22 +71,19 @@ extern void init_parallel_dump_utils(void);
extern int GetIdleWorker(ParallelState *pstate); extern int GetIdleWorker(ParallelState *pstate);
extern bool IsEveryWorkerIdle(ParallelState *pstate); extern bool IsEveryWorkerIdle(ParallelState *pstate);
extern void ListenToWorkers(struct _archiveHandle * AH, ParallelState *pstate, bool do_wait); extern void ListenToWorkers(ArchiveHandle *AH, ParallelState *pstate, bool do_wait);
extern int ReapWorkerStatus(ParallelState *pstate, int *status); extern int ReapWorkerStatus(ParallelState *pstate, int *status);
extern void EnsureIdleWorker(struct _archiveHandle * AH, ParallelState *pstate); extern void EnsureIdleWorker(ArchiveHandle *AH, ParallelState *pstate);
extern void EnsureWorkersFinished(struct _archiveHandle * AH, ParallelState *pstate); extern void EnsureWorkersFinished(ArchiveHandle *AH, ParallelState *pstate);
extern ParallelState *ParallelBackupStart(struct _archiveHandle * AH, extern ParallelState *ParallelBackupStart(ArchiveHandle *AH,
DumpOptions *dopt,
RestoreOptions *ropt); RestoreOptions *ropt);
extern void DispatchJobForTocEntry(struct _archiveHandle * AH, extern void DispatchJobForTocEntry(ArchiveHandle *AH,
ParallelState *pstate, ParallelState *pstate,
struct _tocEntry * te, T_Action act); TocEntry *te, T_Action act);
extern void ParallelBackupEnd(struct _archiveHandle * AH, ParallelState *pstate); extern void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate);
extern void checkAborting(struct _archiveHandle * AH);
extern void extern void checkAborting(ArchiveHandle *AH);
exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
#endif /* PG_DUMP_PARALLEL_H */ #endif /* PG_DUMP_PARALLEL_H */
...@@ -23,27 +23,16 @@ ...@@ -23,27 +23,16 @@
#ifndef PG_BACKUP_H #ifndef PG_BACKUP_H
#define PG_BACKUP_H #define PG_BACKUP_H
#include "postgres_fe.h"
#include "pg_dump.h"
#include "dumputils.h" #include "dumputils.h"
#include "libpq-fe.h" #include "libpq-fe.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10)) typedef enum trivalue
#define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
#define oideq(x,y) ( (x) == (y) )
#define oidle(x,y) ( (x) <= (y) )
#define oidge(x,y) ( (x) >= (y) )
#define oidzero(x) ( (x) == 0 )
enum trivalue
{ {
TRI_DEFAULT, TRI_DEFAULT,
TRI_NO, TRI_NO,
TRI_YES TRI_YES
}; } trivalue;
typedef enum _archiveFormat typedef enum _archiveFormat
{ {
...@@ -73,7 +62,7 @@ typedef enum _teSection ...@@ -73,7 +62,7 @@ typedef enum _teSection
* 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.
*/ */
struct Archive typedef struct Archive
{ {
int verbose; int verbose;
char *remoteVersionStr; /* server's version string */ char *remoteVersionStr; /* server's version string */
...@@ -96,9 +85,7 @@ struct Archive ...@@ -96,9 +85,7 @@ 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 struct _restoreOptions typedef struct _restoreOptions
{ {
...@@ -109,17 +96,24 @@ typedef struct _restoreOptions ...@@ -109,17 +96,24 @@ typedef struct _restoreOptions
* restore */ * restore */
int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
* instead of OWNER TO */ * instead of OWNER TO */
int no_security_labels; /* Skip security label entries */
char *superuser; /* Username to use as superuser */ char *superuser; /* Username to use as superuser */
char *use_role; /* Issue SET ROLE to this */ char *use_role; /* Issue SET ROLE to this */
int dropSchema; int dropSchema;
int disable_dollar_quoting;
int dump_inserts;
int column_inserts;
int if_exists; int if_exists;
int no_security_labels; /* Skip security label entries */
const char *filename; const char *filename;
int dataOnly; int dataOnly;
int schemaOnly; int schemaOnly;
int dumpSections; int dumpSections;
int verbose; int verbose;
int aclsSkip; int aclsSkip;
const char *lockWaitTimeout;
int include_everything;
int tocSummary; int tocSummary;
char *tocFile; char *tocFile;
int format; int format;
...@@ -142,7 +136,7 @@ typedef struct _restoreOptions ...@@ -142,7 +136,7 @@ typedef struct _restoreOptions
char *pghost; char *pghost;
char *username; char *username;
int noDataForFailedTables; int noDataForFailedTables;
enum trivalue promptPassword; trivalue promptPassword;
int exit_on_error; int exit_on_error;
int compression; int compression;
int suppressDumpWarnings; /* Suppress output of WARNING entries int suppressDumpWarnings; /* Suppress output of WARNING entries
...@@ -153,7 +147,76 @@ typedef struct _restoreOptions ...@@ -153,7 +147,76 @@ typedef struct _restoreOptions
int enable_row_security; int enable_row_security;
} RestoreOptions; } RestoreOptions;
typedef void (*SetupWorkerPtr) (Archive *AH, RestoreOptions *ropt); typedef struct _dumpOptions
{
const char *dbname;
const char *pghost;
const char *pgport;
const char *username;
bool oids;
int binary_upgrade;
/* various user-settable parameters */
bool schemaOnly;
bool dataOnly;
int dumpSections; /* bitmask of chosen sections */
bool aclsSkip;
const char *lockWaitTimeout;
/* flags for various command-line long options */
int disable_dollar_quoting;
int dump_inserts;
int column_inserts;
int if_exists;
int no_security_labels;
int no_synchronized_snapshots;
int no_unlogged_table_data;
int serializable_deferrable;
int quote_all_identifiers;
int disable_triggers;
int outputNoTablespaces;
int use_setsessauth;
int enable_row_security;
/* default, if no "inclusion" switches appear, is to dump everything */
bool include_everything;
int outputClean;
int outputCreateDB;
bool outputBlobs;
int outputNoOwner;
char *outputSuperuser;
} DumpOptions;
/*
* pg_dump uses two different mechanisms for identifying database objects:
*
* CatalogId represents an object by the tableoid and oid of its defining
* entry in the system catalogs. We need this to interpret pg_depend entries,
* for instance.
*
* DumpId is a simple sequential integer counter assigned as dumpable objects
* are identified during a pg_dump run. We use DumpId internally in preference
* to CatalogId for two reasons: it's more compact, and we can assign DumpIds
* to "objects" that don't have a separate CatalogId. For example, it is
* convenient to consider a table, its data, and its ACL as three separate
* dumpable "objects" with distinct DumpIds --- this lets us reason about the
* order in which to dump these things.
*/
typedef struct
{
Oid tableoid;
Oid oid;
} CatalogId;
typedef int DumpId;
typedef int (*DataDumperPtr) (Archive *AH, DumpOptions *dopt, void *userArg);
typedef void (*SetupWorkerPtr) (Archive *AH, DumpOptions *dopt, RestoreOptions *ropt);
/* /*
* Main archiver interface. * Main archiver interface.
...@@ -164,7 +227,7 @@ extern void ConnectDatabase(Archive *AH, ...@@ -164,7 +227,7 @@ extern void ConnectDatabase(Archive *AH,
const char *pghost, const char *pghost,
const char *pgport, const char *pgport,
const char *username, const char *username,
enum trivalue prompt_password); trivalue prompt_password);
extern void DisconnectDatabase(Archive *AHX); extern void DisconnectDatabase(Archive *AHX);
extern PGconn *GetConnection(Archive *AHX); extern PGconn *GetConnection(Archive *AHX);
...@@ -186,7 +249,7 @@ extern void WriteData(Archive *AH, const void *data, size_t dLen); ...@@ -186,7 +249,7 @@ extern void WriteData(Archive *AH, const void *data, size_t dLen);
extern int StartBlob(Archive *AH, Oid oid); extern int StartBlob(Archive *AH, Oid oid);
extern int EndBlob(Archive *AH, Oid oid); extern int EndBlob(Archive *AH, Oid oid);
extern void CloseArchive(Archive *AH); extern void CloseArchive(Archive *AH, DumpOptions *dopt);
extern void SetArchiveRestoreOptions(Archive *AH, RestoreOptions *ropt); extern void SetArchiveRestoreOptions(Archive *AH, RestoreOptions *ropt);
...@@ -205,6 +268,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt); ...@@ -205,6 +268,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
extern RestoreOptions *NewRestoreOptions(void); extern RestoreOptions *NewRestoreOptions(void);
extern DumpOptions *NewDumpOptions(void);
extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt);
/* Rearrange and filter TOC entries */ /* Rearrange and filter TOC entries */
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt); extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);
......
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "parallel.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h" #include "pg_backup_db.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "parallel.h"
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -106,6 +108,61 @@ static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te, ...@@ -106,6 +108,61 @@ static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te,
static void mark_create_done(ArchiveHandle *AH, TocEntry *te); static void mark_create_done(ArchiveHandle *AH, TocEntry *te);
static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te); static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te);
/*
* Allocate a new DumpOptions block.
* This is mainly so we can initialize it, but also for future expansion.
* We pg_malloc0 the structure, so we don't need to initialize whatever is
* 0, NULL or false anyway.
*/
DumpOptions *
NewDumpOptions(void)
{
DumpOptions *opts;
opts = (DumpOptions *) pg_malloc0(sizeof(DumpOptions));
/* set any fields that shouldn't default to zeroes */
opts->include_everything = true;
opts->dumpSections = DUMP_UNSECTIONED;
return opts;
}
/*
* Create a freshly allocated DumpOptions with options equivalent to those
* found in the given RestoreOptions.
*/
DumpOptions *
dumpOptionsFromRestoreOptions(RestoreOptions *ropt)
{
DumpOptions *dopt = NewDumpOptions();
/* this is the inverse of what's at the end of pg_dump.c's main() */
dopt->outputClean = ropt->dropSchema;
dopt->dataOnly = ropt->dataOnly;
dopt->schemaOnly = ropt->schemaOnly;
dopt->if_exists = ropt->if_exists;
dopt->column_inserts = ropt->column_inserts;
dopt->dumpSections = ropt->dumpSections;
dopt->aclsSkip = ropt->aclsSkip;
dopt->outputSuperuser = ropt->superuser;
dopt->outputCreateDB = ropt->createDB;
dopt->outputNoOwner = ropt->noOwner;
dopt->outputNoTablespaces = ropt->noTablespace;
dopt->disable_triggers = ropt->disable_triggers;
dopt->use_setsessauth = ropt->use_setsessauth;
dopt->disable_dollar_quoting = ropt->disable_dollar_quoting;
dopt->dump_inserts = ropt->dump_inserts;
dopt->no_security_labels = ropt->no_security_labels;
dopt->lockWaitTimeout = ropt->lockWaitTimeout;
dopt->include_everything = ropt->include_everything;
dopt->enable_row_security = ropt->enable_row_security;
return dopt;
}
/* /*
* Wrapper functions. * Wrapper functions.
* *
...@@ -120,7 +177,7 @@ static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te); ...@@ -120,7 +177,7 @@ static void inhibit_data_for_failed_table(ArchiveHandle *AH, TocEntry *te);
* setup doesn't need to know anything much, so it's defined here. * setup doesn't need to know anything much, so it's defined here.
*/ */
static void static void
setupRestoreWorker(Archive *AHX, RestoreOptions *ropt) setupRestoreWorker(Archive *AHX, DumpOptions *dopt, RestoreOptions *ropt)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX; ArchiveHandle *AH = (ArchiveHandle *) AHX;
...@@ -152,12 +209,12 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt) ...@@ -152,12 +209,12 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
/* Public */ /* Public */
void void
CloseArchive(Archive *AHX) CloseArchive(Archive *AHX, DumpOptions *dopt)
{ {
int res = 0; int res = 0;
ArchiveHandle *AH = (ArchiveHandle *) AHX; ArchiveHandle *AH = (ArchiveHandle *) AHX;
(*AH->ClosePtr) (AH); (*AH->ClosePtr) (AH, dopt);
/* Close the output */ /* Close the output */
if (AH->gzOut) if (AH->gzOut)
...@@ -368,7 +425,7 @@ RestoreArchive(Archive *AHX) ...@@ -368,7 +425,7 @@ RestoreArchive(Archive *AHX)
if (ropt->single_txn) if (ropt->single_txn)
{ {
if (AH->connection) if (AH->connection)
StartTransaction(AH); StartTransaction(AHX);
else else
ahprintf(AH, "BEGIN;\n\n"); ahprintf(AH, "BEGIN;\n\n");
} }
...@@ -548,7 +605,7 @@ RestoreArchive(Archive *AHX) ...@@ -548,7 +605,7 @@ RestoreArchive(Archive *AHX)
Assert(AH->connection == NULL); Assert(AH->connection == NULL);
/* ParallelBackupStart() will actually fork the processes */ /* ParallelBackupStart() will actually fork the processes */
pstate = ParallelBackupStart(AH, ropt); pstate = ParallelBackupStart(AH, NULL, ropt);
restore_toc_entries_parallel(AH, pstate, &pending_list); restore_toc_entries_parallel(AH, pstate, &pending_list);
ParallelBackupEnd(AH, pstate); ParallelBackupEnd(AH, pstate);
...@@ -586,7 +643,7 @@ RestoreArchive(Archive *AHX) ...@@ -586,7 +643,7 @@ RestoreArchive(Archive *AHX)
if (ropt->single_txn) if (ropt->single_txn)
{ {
if (AH->connection) if (AH->connection)
CommitTransaction(AH); CommitTransaction(AHX);
else else
ahprintf(AH, "COMMIT;\n\n"); ahprintf(AH, "COMMIT;\n\n");
} }
...@@ -767,7 +824,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, ...@@ -767,7 +824,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
* Parallel restore is always talking directly to a * Parallel restore is always talking directly to a
* server, so no need to see if we should issue BEGIN. * server, so no need to see if we should issue BEGIN.
*/ */
StartTransaction(AH); StartTransaction(&AH->public);
/* /*
* If the server version is >= 8.4, make sure we issue * If the server version is >= 8.4, make sure we issue
...@@ -798,12 +855,12 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te, ...@@ -798,12 +855,12 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
*/ */
if (AH->outputKind == OUTPUT_COPYDATA && if (AH->outputKind == OUTPUT_COPYDATA &&
RestoringToDB(AH)) RestoringToDB(AH))
EndDBCopyMode(AH, te); EndDBCopyMode(&AH->public, te->tag);
AH->outputKind = OUTPUT_SQLCMDS; AH->outputKind = OUTPUT_SQLCMDS;
/* close out the transaction started above */ /* close out the transaction started above */
if (is_parallel && te->created) if (is_parallel && te->created)
CommitTransaction(AH); CommitTransaction(&AH->public);
_enableTriggersIfNecessary(AH, te, ropt); _enableTriggersIfNecessary(AH, te, ropt);
} }
...@@ -1099,7 +1156,7 @@ StartRestoreBlobs(ArchiveHandle *AH) ...@@ -1099,7 +1156,7 @@ StartRestoreBlobs(ArchiveHandle *AH)
if (!AH->ropt->single_txn) if (!AH->ropt->single_txn)
{ {
if (AH->connection) if (AH->connection)
StartTransaction(AH); StartTransaction(&AH->public);
else else
ahprintf(AH, "BEGIN;\n\n"); ahprintf(AH, "BEGIN;\n\n");
} }
...@@ -1116,7 +1173,7 @@ EndRestoreBlobs(ArchiveHandle *AH) ...@@ -1116,7 +1173,7 @@ EndRestoreBlobs(ArchiveHandle *AH)
if (!AH->ropt->single_txn) if (!AH->ropt->single_txn)
{ {
if (AH->connection) if (AH->connection)
CommitTransaction(AH); CommitTransaction(&AH->public);
else else
ahprintf(AH, "COMMIT;\n\n"); ahprintf(AH, "COMMIT;\n\n");
} }
...@@ -1573,7 +1630,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH) ...@@ -1573,7 +1630,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
* connected then send it to the DB. * connected then send it to the DB.
*/ */
if (RestoringToDB(AH)) if (RestoringToDB(AH))
bytes_written = ExecuteSqlCommandBuf(AH, (const char *) ptr, size * nmemb); bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
else else
bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size; bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
} }
...@@ -2240,7 +2297,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt, ...@@ -2240,7 +2297,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
} }
void void
WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate) WriteDataChunks(ArchiveHandle *AH, DumpOptions *dopt, ParallelState *pstate)
{ {
TocEntry *te; TocEntry *te;
...@@ -2263,13 +2320,13 @@ WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate) ...@@ -2263,13 +2320,13 @@ WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
DispatchJobForTocEntry(AH, pstate, te, ACT_DUMP); DispatchJobForTocEntry(AH, pstate, te, ACT_DUMP);
} }
else else
WriteDataChunksForTocEntry(AH, te); WriteDataChunksForTocEntry(AH, dopt, te);
} }
EnsureWorkersFinished(AH, pstate); EnsureWorkersFinished(AH, pstate);
} }
void void
WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te) WriteDataChunksForTocEntry(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te)
{ {
StartDataPtr startPtr; StartDataPtr startPtr;
EndDataPtr endPtr; EndDataPtr endPtr;
...@@ -2293,7 +2350,7 @@ WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te) ...@@ -2293,7 +2350,7 @@ WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
/* /*
* The user-provided DataDumper routine needs to call AH->WriteData * The user-provided DataDumper routine needs to call AH->WriteData
*/ */
(*te->dataDumper) ((Archive *) AH, te->dataDumperArg); (*te->dataDumper) ((Archive *) AH, dopt, te->dataDumperArg);
if (endPtr != NULL) if (endPtr != NULL)
(*endPtr) (AH, te); (*endPtr) (AH, te);
......
...@@ -21,11 +21,9 @@ ...@@ -21,11 +21,9 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef __PG_BACKUP_ARCHIVE__ #ifndef __PG_BACKUP_ARCHIVE__
#define __PG_BACKUP_ARCHIVE__ #define __PG_BACKUP_ARCHIVE__
#include "postgres_fe.h"
#include <time.h> #include <time.h>
...@@ -111,9 +109,8 @@ typedef z_stream *z_streamp; ...@@ -111,9 +109,8 @@ typedef z_stream *z_streamp;
#define WORKER_INHIBIT_DATA 11 #define WORKER_INHIBIT_DATA 11
#define WORKER_IGNORED_ERRORS 12 #define WORKER_IGNORED_ERRORS 12
struct _archiveHandle; typedef struct _archiveHandle ArchiveHandle;
struct _tocEntry; typedef struct _tocEntry TocEntry;
struct _restoreList;
struct ParallelArgs; struct ParallelArgs;
struct ParallelState; struct ParallelState;
...@@ -139,40 +136,40 @@ typedef enum T_Action ...@@ -139,40 +136,40 @@ typedef enum T_Action
ACT_RESTORE ACT_RESTORE
} T_Action; } T_Action;
typedef void (*ClosePtr) (struct _archiveHandle * AH); typedef void (*ClosePtr) (ArchiveHandle *AH, DumpOptions *dopt);
typedef void (*ReopenPtr) (struct _archiveHandle * AH); typedef void (*ReopenPtr) (ArchiveHandle *AH);
typedef void (*ArchiveEntryPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*ArchiveEntryPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*StartDataPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*WriteDataPtr) (struct _archiveHandle * AH, const void *data, size_t dLen); typedef void (*WriteDataPtr) (ArchiveHandle *AH, const void *data, size_t dLen);
typedef void (*EndDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*EndDataPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*StartBlobsPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid); typedef void (*StartBlobPtr) (ArchiveHandle *AH, TocEntry *te, Oid oid);
typedef void (*EndBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid); typedef void (*EndBlobPtr) (ArchiveHandle *AH, TocEntry *te, Oid oid);
typedef void (*EndBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*EndBlobsPtr) (ArchiveHandle *AH, TocEntry *te);
typedef int (*WriteBytePtr) (struct _archiveHandle * AH, const int i); typedef int (*WriteBytePtr) (ArchiveHandle *AH, const int i);
typedef int (*ReadBytePtr) (struct _archiveHandle * AH); typedef int (*ReadBytePtr) (ArchiveHandle *AH);
typedef void (*WriteBufPtr) (struct _archiveHandle * AH, const void *c, size_t len); typedef void (*WriteBufPtr) (ArchiveHandle *AH, const void *c, size_t len);
typedef void (*ReadBufPtr) (struct _archiveHandle * AH, void *buf, size_t len); typedef void (*ReadBufPtr) (ArchiveHandle *AH, void *buf, size_t len);
typedef void (*SaveArchivePtr) (struct _archiveHandle * AH); typedef void (*SaveArchivePtr) (ArchiveHandle *AH);
typedef void (*WriteExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*WriteExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*ReadExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*ReadExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*PrintExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef void (*PrintExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*PrintTocDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te, RestoreOptions *ropt); typedef void (*PrintTocDataPtr) (ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
typedef void (*ClonePtr) (struct _archiveHandle * AH); typedef void (*ClonePtr) (ArchiveHandle *AH);
typedef void (*DeClonePtr) (struct _archiveHandle * AH); typedef void (*DeClonePtr) (ArchiveHandle *AH);
typedef char *(*WorkerJobRestorePtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef char *(*WorkerJobRestorePtr) (ArchiveHandle *AH, TocEntry *te);
typedef char *(*WorkerJobDumpPtr) (struct _archiveHandle * AH, struct _tocEntry * te); typedef char *(*WorkerJobDumpPtr) (ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te);
typedef char *(*MasterStartParallelItemPtr) (struct _archiveHandle * AH, struct _tocEntry * te, typedef char *(*MasterStartParallelItemPtr) (ArchiveHandle *AH, TocEntry *te,
T_Action act); T_Action act);
typedef int (*MasterEndParallelItemPtr) (struct _archiveHandle * AH, struct _tocEntry * te, typedef int (*MasterEndParallelItemPtr) (ArchiveHandle *AH, TocEntry *te,
const char *str, T_Action act); const char *str, T_Action act);
typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len); typedef size_t (*CustomOutPtr) (ArchiveHandle *AH, const void *buf, size_t len);
typedef enum typedef enum
{ {
...@@ -210,7 +207,7 @@ typedef enum ...@@ -210,7 +207,7 @@ typedef enum
REQ_SPECIAL = 0x04 /* for special TOC entries */ REQ_SPECIAL = 0x04 /* for special TOC entries */
} teReqs; } teReqs;
typedef struct _archiveHandle struct _archiveHandle
{ {
Archive public; /* Public part of archive */ Archive public; /* Public part of archive */
char vmaj; /* Version of file */ char vmaj; /* Version of file */
...@@ -284,7 +281,7 @@ typedef struct _archiveHandle ...@@ -284,7 +281,7 @@ typedef struct _archiveHandle
/* Stuff for direct DB connection */ /* Stuff for direct DB connection */
char *archdbname; /* DB name *read* from archive */ char *archdbname; /* DB name *read* from archive */
enum trivalue promptPassword; trivalue promptPassword;
char *savedPassword; /* password for ropt->username, if known */ char *savedPassword; /* password for ropt->username, if known */
char *use_role; char *use_role;
PGconn *connection; PGconn *connection;
...@@ -336,9 +333,9 @@ typedef struct _archiveHandle ...@@ -336,9 +333,9 @@ typedef struct _archiveHandle
ArchiverStage lastErrorStage; ArchiverStage lastErrorStage;
struct _tocEntry *currentTE; struct _tocEntry *currentTE;
struct _tocEntry *lastErrorTE; struct _tocEntry *lastErrorTE;
} ArchiveHandle; };
typedef struct _tocEntry struct _tocEntry
{ {
struct _tocEntry *prev; struct _tocEntry *prev;
struct _tocEntry *next; struct _tocEntry *next;
...@@ -376,7 +373,7 @@ typedef struct _tocEntry ...@@ -376,7 +373,7 @@ typedef struct _tocEntry
int nRevDeps; /* number of such dependencies */ int nRevDeps; /* number of such dependencies */
DumpId *lockDeps; /* dumpIds of objects this one needs lock on */ DumpId *lockDeps; /* dumpIds of objects this one needs lock on */
int nLockDeps; /* number of such dependencies */ int nLockDeps; /* number of such dependencies */
} TocEntry; };
extern int parallel_restore(struct ParallelArgs *args); extern int parallel_restore(struct ParallelArgs *args);
extern void on_exit_close_archive(Archive *AHX); extern void on_exit_close_archive(Archive *AHX);
...@@ -389,8 +386,8 @@ extern void WriteHead(ArchiveHandle *AH); ...@@ -389,8 +386,8 @@ extern void WriteHead(ArchiveHandle *AH);
extern void ReadHead(ArchiveHandle *AH); extern void ReadHead(ArchiveHandle *AH);
extern void WriteToc(ArchiveHandle *AH); extern void WriteToc(ArchiveHandle *AH);
extern void ReadToc(ArchiveHandle *AH); extern void ReadToc(ArchiveHandle *AH);
extern void WriteDataChunks(ArchiveHandle *AH, struct ParallelState *pstate); extern void WriteDataChunks(ArchiveHandle *AH, DumpOptions *dopt, struct ParallelState *pstate);
extern void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te); extern void WriteDataChunksForTocEntry(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te);
extern ArchiveHandle *CloneArchive(ArchiveHandle *AH); extern ArchiveHandle *CloneArchive(ArchiveHandle *AH);
extern void DeCloneArchive(ArchiveHandle *AH); extern void DeCloneArchive(ArchiveHandle *AH);
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "compress_io.h" #include "compress_io.h"
#include "parallel.h" #include "parallel.h"
...@@ -41,7 +42,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i); ...@@ -41,7 +42,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *); static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH); static void _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt);
static void _ReopenArchive(ArchiveHandle *AH); static void _ReopenArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te); static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
...@@ -687,14 +688,14 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len) ...@@ -687,14 +688,14 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
* the process of saving it to files. No data should be written prior * the process of saving it to files. No data should be written prior
* to this point, since the user could sort the TOC after creating it. * to this point, since the user could sort the TOC after creating it.
* *
* If an archive is to be written, this toutine must call: * If an archive is to be written, this routine must call:
* WriteHead to save the archive header * WriteHead to save the archive header
* WriteToc to save the TOC entries * WriteToc to save the TOC entries
* WriteDataChunks to save all DATA & BLOBs. * WriteDataChunks to save all DATA & BLOBs.
* *
*/ */
static void static void
_CloseArchive(ArchiveHandle *AH) _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{ {
lclContext *ctx = (lclContext *) AH->formatData; lclContext *ctx = (lclContext *) AH->formatData;
pgoff_t tpos; pgoff_t tpos;
...@@ -709,7 +710,7 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -709,7 +710,7 @@ _CloseArchive(ArchiveHandle *AH)
strerror(errno)); strerror(errno));
WriteToc(AH); WriteToc(AH);
ctx->dataStart = _getFilePos(AH, ctx); ctx->dataStart = _getFilePos(AH, ctx);
WriteDataChunks(AH, NULL); WriteDataChunks(AH, dopt, NULL);
/* /*
* If possible, re-write the TOC in order to update the data offset * If possible, re-write the TOC in order to update the data offset
......
...@@ -9,11 +9,12 @@ ...@@ -9,11 +9,12 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "dumputils.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h" #include "pg_backup_db.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "dumputils.h"
#include "parallel.h"
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
...@@ -217,7 +218,7 @@ ConnectDatabase(Archive *AHX, ...@@ -217,7 +218,7 @@ ConnectDatabase(Archive *AHX,
const char *pghost, const char *pghost,
const char *pgport, const char *pgport,
const char *username, const char *username,
enum trivalue prompt_password) trivalue prompt_password)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX; ArchiveHandle *AH = (ArchiveHandle *) AHX;
char *password = AH->savedPassword; char *password = AH->savedPassword;
...@@ -500,8 +501,10 @@ ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen) ...@@ -500,8 +501,10 @@ ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
* Implement ahwrite() for direct-to-DB restore * Implement ahwrite() for direct-to-DB restore
*/ */
int int
ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen) ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX;
if (AH->outputKind == OUTPUT_COPYDATA) if (AH->outputKind == OUTPUT_COPYDATA)
{ {
/* /*
...@@ -553,8 +556,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen) ...@@ -553,8 +556,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen)
* Terminate a COPY operation during direct-to-DB restore * Terminate a COPY operation during direct-to-DB restore
*/ */
void void
EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX;
if (AH->pgCopyIn) if (AH->pgCopyIn)
{ {
PGresult *res; PGresult *res;
...@@ -567,7 +572,7 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) ...@@ -567,7 +572,7 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te)
res = PQgetResult(AH->connection); res = PQgetResult(AH->connection);
if (PQresultStatus(res) != PGRES_COMMAND_OK) if (PQresultStatus(res) != PGRES_COMMAND_OK)
warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s", warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s",
te->tag, PQerrorMessage(AH->connection)); tocEntryTag, PQerrorMessage(AH->connection));
PQclear(res); PQclear(res);
AH->pgCopyIn = false; AH->pgCopyIn = false;
...@@ -575,14 +580,18 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te) ...@@ -575,14 +580,18 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te)
} }
void void
StartTransaction(ArchiveHandle *AH) StartTransaction(Archive *AHX)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX;
ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction"); ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");
} }
void void
CommitTransaction(ArchiveHandle *AH) CommitTransaction(Archive *AHX)
{ {
ArchiveHandle *AH = (ArchiveHandle *) AHX;
ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction"); ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");
} }
......
...@@ -8,17 +8,18 @@ ...@@ -8,17 +8,18 @@
#ifndef PG_BACKUP_DB_H #ifndef PG_BACKUP_DB_H
#define PG_BACKUP_DB_H #define PG_BACKUP_DB_H
#include "pg_backup_archiver.h" #include "pg_backup.h"
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen);
extern int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen);
extern void ExecuteSqlStatement(Archive *AHX, const char *query); extern void ExecuteSqlStatement(Archive *AHX, const char *query);
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query, extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
ExecStatusType status); ExecStatusType status);
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te); extern void EndDBCopyMode(Archive *AHX, const char *tocEntryTag);
extern void StartTransaction(ArchiveHandle *AH); extern void StartTransaction(Archive *AHX);
extern void CommitTransaction(ArchiveHandle *AH); extern void CommitTransaction(Archive *AHX);
#endif #endif
...@@ -32,10 +32,11 @@ ...@@ -32,10 +32,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "compress_io.h" #include "compress_io.h"
#include "pg_backup_utils.h"
#include "parallel.h" #include "parallel.h"
#include "pg_backup_utils.h"
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -71,7 +72,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i); ...@@ -71,7 +72,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *); static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH); static void _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt);
static void _ReopenArchive(ArchiveHandle *AH); static void _ReopenArchive(ArchiveHandle *AH);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
...@@ -92,7 +93,7 @@ static char *_MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action ...@@ -92,7 +93,7 @@ static char *_MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action
static int _MasterEndParallelItem(ArchiveHandle *AH, TocEntry *te, static int _MasterEndParallelItem(ArchiveHandle *AH, TocEntry *te,
const char *str, T_Action act); const char *str, T_Action act);
static char *_WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te); static char *_WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te);
static char *_WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te); static char *_WorkerJobDumpDirectory(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te);
static void setFilePath(ArchiveHandle *AH, char *buf, static void setFilePath(ArchiveHandle *AH, char *buf,
const char *relativeFilename); const char *relativeFilename);
...@@ -566,7 +567,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len) ...@@ -566,7 +567,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
* WriteDataChunks to save all DATA & BLOBs. * WriteDataChunks to save all DATA & BLOBs.
*/ */
static void static void
_CloseArchive(ArchiveHandle *AH) _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{ {
lclContext *ctx = (lclContext *) AH->formatData; lclContext *ctx = (lclContext *) AH->formatData;
...@@ -578,7 +579,7 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -578,7 +579,7 @@ _CloseArchive(ArchiveHandle *AH)
setFilePath(AH, fname, "toc.dat"); setFilePath(AH, fname, "toc.dat");
/* this will actually fork the processes for a parallel backup */ /* this will actually fork the processes for a parallel backup */
ctx->pstate = ParallelBackupStart(AH, NULL); ctx->pstate = ParallelBackupStart(AH, dopt, NULL);
/* The TOC is always created uncompressed */ /* The TOC is always created uncompressed */
tocFH = cfopen_write(fname, PG_BINARY_W, 0); tocFH = cfopen_write(fname, PG_BINARY_W, 0);
...@@ -599,7 +600,7 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -599,7 +600,7 @@ _CloseArchive(ArchiveHandle *AH)
if (cfclose(tocFH) != 0) if (cfclose(tocFH) != 0)
exit_horribly(modulename, "could not close TOC file: %s\n", exit_horribly(modulename, "could not close TOC file: %s\n",
strerror(errno)); strerror(errno));
WriteDataChunks(AH, ctx->pstate); WriteDataChunks(AH, dopt, ctx->pstate);
ParallelBackupEnd(AH, ctx->pstate); ParallelBackupEnd(AH, ctx->pstate);
} }
...@@ -790,7 +791,7 @@ _MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action act) ...@@ -790,7 +791,7 @@ _MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action act)
* function of the respective dump format. * function of the respective dump format.
*/ */
static char * static char *
_WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te) _WorkerJobDumpDirectory(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te)
{ {
/* /*
* short fixed-size string + some ID so far, this needs to be malloc'ed * short fixed-size string + some ID so far, this needs to be malloc'ed
...@@ -809,7 +810,7 @@ _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te) ...@@ -809,7 +810,7 @@ _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
* succeed... A failure will be detected by the parent when the child dies * succeed... A failure will be detected by the parent when the child dies
* unexpectedly. * unexpectedly.
*/ */
WriteDataChunksForTocEntry(AH, te); WriteDataChunksForTocEntry(AH, dopt, te);
snprintf(buf, buflen, "OK DUMP %d", te->dumpId); snprintf(buf, buflen, "OK DUMP %d", te->dumpId);
......
...@@ -21,12 +21,10 @@ ...@@ -21,12 +21,10 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "parallel.h"
#include <unistd.h> /* for dup */
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
...@@ -35,7 +33,7 @@ static void _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen); ...@@ -35,7 +33,7 @@ static void _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te); static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i); static int _WriteByte(ArchiveHandle *AH, const int i);
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH); static void _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _StartBlobs(ArchiveHandle *AH, TocEntry *te); static void _StartBlobs(ArchiveHandle *AH, TocEntry *te);
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid); static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid);
...@@ -198,12 +196,16 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt) ...@@ -198,12 +196,16 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
{ {
if (te->dataDumper) if (te->dataDumper)
{ {
DumpOptions *dopt;
AH->currToc = te; AH->currToc = te;
if (strcmp(te->desc, "BLOBS") == 0) if (strcmp(te->desc, "BLOBS") == 0)
_StartBlobs(AH, te); _StartBlobs(AH, te);
(*te->dataDumper) ((Archive *) AH, te->dataDumperArg); dopt = dumpOptionsFromRestoreOptions(ropt);
(*te->dataDumper) ((Archive *) AH, dopt, te->dataDumperArg);
pg_free(dopt);
if (strcmp(te->desc, "BLOBS") == 0) if (strcmp(te->desc, "BLOBS") == 0)
_EndBlobs(AH, te); _EndBlobs(AH, te);
...@@ -227,7 +229,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len) ...@@ -227,7 +229,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
} }
static void static void
_CloseArchive(ArchiveHandle *AH) _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{ {
/* Nothing to do */ /* Nothing to do */
} }
...@@ -27,12 +27,11 @@ ...@@ -27,12 +27,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "pg_backup.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_tar.h" #include "pg_backup_tar.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "parallel.h"
#include "pgtar.h" #include "pgtar.h"
#include <sys/stat.h> #include <sys/stat.h>
...@@ -48,7 +47,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i); ...@@ -48,7 +47,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *); static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len); static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len);
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len); static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len);
static void _CloseArchive(ArchiveHandle *AH); static void _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt);
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt); static void _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te); static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te); static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te);
...@@ -827,7 +826,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len) ...@@ -827,7 +826,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
} }
static void static void
_CloseArchive(ArchiveHandle *AH) _CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{ {
lclContext *ctx = (lclContext *) AH->formatData; lclContext *ctx = (lclContext *) AH->formatData;
TAR_MEMBER *th; TAR_MEMBER *th;
...@@ -850,7 +849,7 @@ _CloseArchive(ArchiveHandle *AH) ...@@ -850,7 +849,7 @@ _CloseArchive(ArchiveHandle *AH)
/* /*
* Now send the data (tables & blobs) * Now send the data (tables & blobs)
*/ */
WriteDataChunks(AH, NULL); WriteDataChunks(AH, dopt, NULL);
/* /*
* Now this format wants to append a script which does a full restore * Now this format wants to append a script which does a full restore
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "parallel.h"
/* Globals exported by this file */ /* Globals exported by this file */
const char *progname = NULL; const char *progname = NULL;
......
...@@ -37,4 +37,8 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0))); ...@@ -37,4 +37,8 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
extern void on_exit_nicely(on_exit_nicely_callback function, void *arg); extern void on_exit_nicely(on_exit_nicely_callback function, void *arg);
extern void exit_nicely(int code) __attribute__((noreturn)); extern void exit_nicely(int code) __attribute__((noreturn));
extern void
exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
#endif /* PG_BACKUP_UTILS_H */ #endif /* PG_BACKUP_UTILS_H */
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include <unistd.h> #include <unistd.h>
...@@ -49,7 +48,6 @@ ...@@ -49,7 +48,6 @@
#include "catalog/pg_cast.h" #include "catalog/pg_cast.h"
#include "catalog/pg_class.h" #include "catalog/pg_class.h"
#include "catalog/pg_default_acl.h" #include "catalog/pg_default_acl.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_largeobject.h" #include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h" #include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
...@@ -57,11 +55,11 @@ ...@@ -57,11 +55,11 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "dumputils.h" #include "dumputils.h"
#include "parallel.h" #include "parallel.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "pg_dump.h"
typedef struct typedef struct
...@@ -81,17 +79,18 @@ typedef struct ...@@ -81,17 +79,18 @@ typedef struct
int objsubid; /* subobject (table column #) */ int objsubid; /* subobject (table column #) */
} SecLabelItem; } SecLabelItem;
typedef enum OidOptions
{
zeroAsOpaque = 1,
zeroAsAny = 2,
zeroAsStar = 4,
zeroAsNone = 8
} OidOptions;
/* global decls */ /* global decls */
bool g_verbose; /* User wants verbose narration of our bool g_verbose; /* User wants verbose narration of our
* activities. */ * activities. */
/* various user-settable parameters */
static bool schemaOnly;
static bool dataOnly;
static int dumpSections; /* bitmask of chosen sections */
static bool aclsSkip;
static const char *lockWaitTimeout;
/* subquery used to convert user ID (eg, datdba) to user name */ /* subquery used to convert user ID (eg, datdba) to user name */
static const char *username_subquery; static const char *username_subquery;
...@@ -116,8 +115,6 @@ static SimpleOidList table_exclude_oids = {NULL, NULL}; ...@@ -116,8 +115,6 @@ static SimpleOidList table_exclude_oids = {NULL, NULL};
static SimpleStringList tabledata_exclude_patterns = {NULL, NULL}; static SimpleStringList tabledata_exclude_patterns = {NULL, NULL};
static SimpleOidList tabledata_exclude_oids = {NULL, NULL}; static SimpleOidList tabledata_exclude_oids = {NULL, NULL};
/* default, if no "inclusion" switches appear, is to dump everything */
static bool include_everything = true;
char g_opaque_type[10]; /* name for the opaque type */ char g_opaque_type[10]; /* name for the opaque type */
...@@ -127,22 +124,9 @@ char g_comment_end[10]; ...@@ -127,22 +124,9 @@ char g_comment_end[10];
static const CatalogId nilCatalogId = {0, 0}; static const CatalogId nilCatalogId = {0, 0};
/* flags for various command-line long options */
static int binary_upgrade = 0;
static int disable_dollar_quoting = 0;
static int dump_inserts = 0;
static int column_inserts = 0;
static int if_exists = 0;
static int no_security_labels = 0;
static int no_synchronized_snapshots = 0;
static int no_unlogged_table_data = 0;
static int serializable_deferrable = 0;
static int enable_row_security = 0;
static void help(const char *progname); static void help(const char *progname);
static void setup_connection(Archive *AH, const char *dumpencoding, static void setup_connection(Archive *AH, DumpOptions *dopt,
char *use_role); const char *dumpencoding, 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(Archive *fout, static void expand_schema_name_patterns(Archive *fout,
SimpleStringList *patterns, SimpleStringList *patterns,
...@@ -151,64 +135,64 @@ static void expand_table_name_patterns(Archive *fout, ...@@ -151,64 +135,64 @@ static void expand_table_name_patterns(Archive *fout,
SimpleStringList *patterns, SimpleStringList *patterns,
SimpleOidList *oids); SimpleOidList *oids);
static NamespaceInfo *findNamespace(Archive *fout, 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, DumpOptions *dopt, TableDataInfo *tdinfo);
static void refreshMatViewData(Archive *fout, TableDataInfo *tdinfo); static void refreshMatViewData(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, DumpOptions *dopt, const char *target,
const char *namespace, const char *owner, const char *namespace, const char *owner,
CatalogId catalogId, int subid, DumpId dumpId); CatalogId catalogId, int subid, DumpId dumpId);
static int findComments(Archive *fout, Oid classoid, Oid objoid, static int findComments(Archive *fout, Oid classoid, Oid objoid,
CommentItem **items); CommentItem **items);
static int collectComments(Archive *fout, CommentItem **items); static int collectComments(Archive *fout, CommentItem **items);
static void dumpSecLabel(Archive *fout, const char *target, static void dumpSecLabel(Archive *fout, DumpOptions *dopt, const char *target,
const char *namespace, const char *owner, const char *namespace, const char *owner,
CatalogId catalogId, int subid, DumpId dumpId); CatalogId catalogId, int subid, DumpId dumpId);
static int findSecLabels(Archive *fout, Oid classoid, Oid objoid, static int findSecLabels(Archive *fout, Oid classoid, Oid objoid,
SecLabelItem **items); SecLabelItem **items);
static int collectSecLabels(Archive *fout, SecLabelItem **items); static int collectSecLabels(Archive *fout, SecLabelItem **items);
static void dumpDumpableObject(Archive *fout, DumpableObject *dobj); static void dumpDumpableObject(Archive *fout, DumpOptions *dopt, DumpableObject *dobj);
static void dumpNamespace(Archive *fout, NamespaceInfo *nspinfo); static void dumpNamespace(Archive *fout, DumpOptions *dopt, NamespaceInfo *nspinfo);
static void dumpExtension(Archive *fout, ExtensionInfo *extinfo); static void dumpExtension(Archive *fout, DumpOptions *dopt, ExtensionInfo *extinfo);
static void dumpType(Archive *fout, TypeInfo *tyinfo); static void dumpType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpBaseType(Archive *fout, TypeInfo *tyinfo); static void dumpBaseType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpEnumType(Archive *fout, TypeInfo *tyinfo); static void dumpEnumType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpRangeType(Archive *fout, TypeInfo *tyinfo); static void dumpRangeType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpDomain(Archive *fout, TypeInfo *tyinfo); static void dumpDomain(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpCompositeType(Archive *fout, TypeInfo *tyinfo); static void dumpCompositeType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo);
static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo); static void dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo);
static void dumpShellType(Archive *fout, ShellTypeInfo *stinfo); static void dumpShellType(Archive *fout, DumpOptions *dopt, ShellTypeInfo *stinfo);
static void dumpProcLang(Archive *fout, ProcLangInfo *plang); static void dumpProcLang(Archive *fout, DumpOptions *dopt, ProcLangInfo *plang);
static void dumpFunc(Archive *fout, FuncInfo *finfo); static void dumpFunc(Archive *fout, DumpOptions *dopt, FuncInfo *finfo);
static void dumpCast(Archive *fout, CastInfo *cast); static void dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast);
static void dumpOpr(Archive *fout, OprInfo *oprinfo); static void dumpOpr(Archive *fout, DumpOptions *dopt, OprInfo *oprinfo);
static void dumpOpclass(Archive *fout, OpclassInfo *opcinfo); static void dumpOpclass(Archive *fout, DumpOptions *dopt, OpclassInfo *opcinfo);
static void dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo); static void dumpOpfamily(Archive *fout, DumpOptions *dopt, OpfamilyInfo *opfinfo);
static void dumpCollation(Archive *fout, CollInfo *convinfo); static void dumpCollation(Archive *fout, DumpOptions *dopt, CollInfo *convinfo);
static void dumpConversion(Archive *fout, ConvInfo *convinfo); static void dumpConversion(Archive *fout, DumpOptions *dopt, ConvInfo *convinfo);
static void dumpRule(Archive *fout, RuleInfo *rinfo); static void dumpRule(Archive *fout, DumpOptions *dopt, RuleInfo *rinfo);
static void dumpAgg(Archive *fout, AggInfo *agginfo); static void dumpAgg(Archive *fout, DumpOptions *dopt, AggInfo *agginfo);
static void dumpTrigger(Archive *fout, TriggerInfo *tginfo); static void dumpTrigger(Archive *fout, DumpOptions *dopt, TriggerInfo *tginfo);
static void dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo); static void dumpEventTrigger(Archive *fout, DumpOptions *dopt, EventTriggerInfo *evtinfo);
static void dumpTable(Archive *fout, TableInfo *tbinfo); static void dumpTable(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo);
static void dumpTableSchema(Archive *fout, TableInfo *tbinfo); static void dumpTableSchema(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo);
static void dumpAttrDef(Archive *fout, AttrDefInfo *adinfo); static void dumpAttrDef(Archive *fout, DumpOptions *dopt, AttrDefInfo *adinfo);
static void dumpSequence(Archive *fout, TableInfo *tbinfo); static void dumpSequence(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo);
static void dumpSequenceData(Archive *fout, TableDataInfo *tdinfo); static void dumpSequenceData(Archive *fout, TableDataInfo *tdinfo);
static void dumpIndex(Archive *fout, IndxInfo *indxinfo); static void dumpIndex(Archive *fout, DumpOptions *dopt, IndxInfo *indxinfo);
static void dumpConstraint(Archive *fout, ConstraintInfo *coninfo); static void dumpConstraint(Archive *fout, DumpOptions *dopt, ConstraintInfo *coninfo);
static void dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo); static void dumpTableConstraintComment(Archive *fout, DumpOptions *dopt, ConstraintInfo *coninfo);
static void dumpTSParser(Archive *fout, TSParserInfo *prsinfo); static void dumpTSParser(Archive *fout, DumpOptions *dopt, TSParserInfo *prsinfo);
static void dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo); static void dumpTSDictionary(Archive *fout, DumpOptions *dopt, TSDictInfo *dictinfo);
static void dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo); static void dumpTSTemplate(Archive *fout, DumpOptions *dopt, TSTemplateInfo *tmplinfo);
static void dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo); static void dumpTSConfig(Archive *fout, DumpOptions *dopt, TSConfigInfo *cfginfo);
static void dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo); static void dumpForeignDataWrapper(Archive *fout, DumpOptions *dopt, FdwInfo *fdwinfo);
static void dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo); static void dumpForeignServer(Archive *fout, DumpOptions *dopt, ForeignServerInfo *srvinfo);
static void dumpUserMappings(Archive *fout, static void dumpUserMappings(Archive *fout,
const char *servername, const char *namespace, const char *servername, const char *namespace,
const char *owner, CatalogId catalogId, DumpId dumpId); const char *owner, CatalogId catalogId, DumpId dumpId);
static void dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo); static void dumpDefaultACL(Archive *fout, DumpOptions *dopt, DefaultACLInfo *daclinfo);
static void dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, static void dumpACL(Archive *fout, DumpOptions *dopt, CatalogId objCatId, DumpId objDumpId,
const char *type, const char *name, const char *subname, const char *type, const char *name, const char *subname,
const char *tag, const char *nspname, const char *owner, const char *tag, const char *nspname, const char *owner,
const char *acls); const char *acls);
...@@ -223,8 +207,8 @@ static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs, ...@@ -223,8 +207,8 @@ static void addBoundaryDependencies(DumpableObject **dobjs, int numObjs,
DumpableObject *boundaryObjs); DumpableObject *boundaryObjs);
static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo); static void getDomainConstraints(Archive *fout, TypeInfo *tyinfo);
static void getTableData(TableInfo *tblinfo, int numTables, bool oids); static void getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids);
static void makeTableDataInfo(TableInfo *tbinfo, bool oids); static void makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids);
static void buildMatViewRefreshDependencies(Archive *fout); static void buildMatViewRefreshDependencies(Archive *fout);
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,
...@@ -246,10 +230,10 @@ static void selectSourceSchema(Archive *fout, const char *schemaName); ...@@ -246,10 +230,10 @@ static void selectSourceSchema(Archive *fout, const char *schemaName);
static char *getFormattedTypeName(Archive *fout, 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 void getBlobs(Archive *fout); static void getBlobs(Archive *fout);
static void dumpBlob(Archive *fout, BlobInfo *binfo); static void dumpBlob(Archive *fout, DumpOptions *dopt, BlobInfo *binfo);
static int dumpBlobs(Archive *fout, void *arg); static int dumpBlobs(Archive *fout, DumpOptions *dopt, void *arg);
static void dumpRowSecurity(Archive *fout, RowSecurityInfo *rsinfo); static void dumpRowSecurity(Archive *fout, DumpOptions *dopt, RowSecurityInfo *rsinfo);
static void dumpDatabase(Archive *AH); static void dumpDatabase(Archive *AH, DumpOptions *dopt);
static void dumpEncoding(Archive *AH); static void dumpEncoding(Archive *AH);
static void dumpStdStrings(Archive *AH); static void dumpStdStrings(Archive *AH);
static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout, static void binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
...@@ -266,7 +250,7 @@ static const char *getAttrName(int attrnum, TableInfo *tblInfo); ...@@ -266,7 +250,7 @@ static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer); static const char *fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer);
static char *get_synchronized_snapshot(Archive *fout); static char *get_synchronized_snapshot(Archive *fout);
static PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query); static PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
static void setupDumpWorker(Archive *AHX, RestoreOptions *ropt); static void setupDumpWorker(Archive *AHX, DumpOptions *dopt, RestoreOptions *ropt);
int int
...@@ -275,39 +259,27 @@ main(int argc, char **argv) ...@@ -275,39 +259,27 @@ main(int argc, char **argv)
int c; int c;
const char *filename = NULL; const char *filename = NULL;
const char *format = "p"; const char *format = "p";
const char *dbname = NULL;
const char *pghost = NULL;
const char *pgport = NULL;
const char *username = NULL;
const char *dumpencoding = NULL;
bool oids = false;
TableInfo *tblinfo; TableInfo *tblinfo;
int numTables; int numTables;
DumpableObject **dobjs; DumpableObject **dobjs;
int numObjs; int numObjs;
DumpableObject *boundaryObjs; DumpableObject *boundaryObjs;
int i; int i;
int optindex;
RestoreOptions *ropt;
Archive *fout; /* the script file */
const char *dumpencoding = NULL;
char *use_role = NULL;
int numWorkers = 1; int numWorkers = 1;
enum trivalue prompt_password = TRI_DEFAULT; trivalue prompt_password = TRI_DEFAULT;
int compressLevel = -1; int compressLevel = -1;
int plainText = 0; int plainText = 0;
int outputClean = 0;
int outputCreateDB = 0;
bool outputBlobs = false;
int outputNoOwner = 0;
char *outputSuperuser = NULL;
char *use_role = NULL;
int optindex;
RestoreOptions *ropt;
ArchiveFormat archiveFormat = archUnknown; ArchiveFormat archiveFormat = archUnknown;
ArchiveMode archiveMode; ArchiveMode archiveMode;
Archive *fout; /* the script file */
static int disable_triggers = 0; DumpOptions *dopt = NewDumpOptions();
static int outputNoTablespaces = 0;
static int use_setsessauth = 0;
static struct option long_options[] = { struct option long_options[] = {
{"data-only", no_argument, NULL, 'a'}, {"data-only", no_argument, NULL, 'a'},
{"blobs", no_argument, NULL, 'b'}, {"blobs", no_argument, NULL, 'b'},
{"clean", no_argument, NULL, 'c'}, {"clean", no_argument, NULL, 'c'},
...@@ -342,25 +314,25 @@ main(int argc, char **argv) ...@@ -342,25 +314,25 @@ main(int argc, char **argv)
/* /*
* the following options don't have an equivalent short option letter * the following options don't have an equivalent short option letter
*/ */
{"attribute-inserts", no_argument, &column_inserts, 1}, {"attribute-inserts", no_argument, &dopt->column_inserts, 1},
{"binary-upgrade", no_argument, &binary_upgrade, 1}, {"binary-upgrade", no_argument, &dopt->binary_upgrade, 1},
{"column-inserts", no_argument, &column_inserts, 1}, {"column-inserts", no_argument, &dopt->column_inserts, 1},
{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1}, {"disable-dollar-quoting", no_argument, &dopt->disable_dollar_quoting, 1},
{"disable-triggers", no_argument, &disable_triggers, 1}, {"disable-triggers", no_argument, &dopt->disable_triggers, 1},
{"enable-row-security", no_argument, &enable_row_security, 1}, {"enable-row-security", no_argument, &dopt->enable_row_security, 1},
{"exclude-table-data", required_argument, NULL, 4}, {"exclude-table-data", required_argument, NULL, 4},
{"if-exists", no_argument, &if_exists, 1}, {"if-exists", no_argument, &dopt->if_exists, 1},
{"inserts", no_argument, &dump_inserts, 1}, {"inserts", no_argument, &dopt->dump_inserts, 1},
{"lock-wait-timeout", required_argument, NULL, 2}, {"lock-wait-timeout", required_argument, NULL, 2},
{"no-tablespaces", no_argument, &outputNoTablespaces, 1}, {"no-tablespaces", no_argument, &dopt->outputNoTablespaces, 1},
{"quote-all-identifiers", no_argument, &quote_all_identifiers, 1}, {"quote-all-identifiers", no_argument, &quote_all_identifiers, 1},
{"role", required_argument, NULL, 3}, {"role", required_argument, NULL, 3},
{"section", required_argument, NULL, 5}, {"section", required_argument, NULL, 5},
{"serializable-deferrable", no_argument, &serializable_deferrable, 1}, {"serializable-deferrable", no_argument, &dopt->serializable_deferrable, 1},
{"use-set-session-authorization", no_argument, &use_setsessauth, 1}, {"use-set-session-authorization", no_argument, &dopt->use_setsessauth, 1},
{"no-security-labels", no_argument, &no_security_labels, 1}, {"no-security-labels", no_argument, &dopt->no_security_labels, 1},
{"no-synchronized-snapshots", no_argument, &no_synchronized_snapshots, 1}, {"no-synchronized-snapshots", no_argument, &dopt->no_synchronized_snapshots, 1},
{"no-unlogged-table-data", no_argument, &no_unlogged_table_data, 1}, {"no-unlogged-table-data", no_argument, &dopt->no_unlogged_table_data, 1},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
...@@ -379,10 +351,6 @@ main(int argc, char **argv) ...@@ -379,10 +351,6 @@ main(int argc, char **argv)
g_comment_end[0] = '\0'; g_comment_end[0] = '\0';
strcpy(g_opaque_type, "opaque"); strcpy(g_opaque_type, "opaque");
dataOnly = schemaOnly = false;
dumpSections = DUMP_UNSECTIONED;
lockWaitTimeout = NULL;
progname = get_progname(argv[0]); progname = get_progname(argv[0]);
/* Set default options based on progname */ /* Set default options based on progname */
...@@ -409,23 +377,23 @@ main(int argc, char **argv) ...@@ -409,23 +377,23 @@ main(int argc, char **argv)
switch (c) switch (c)
{ {
case 'a': /* Dump data only */ case 'a': /* Dump data only */
dataOnly = true; dopt->dataOnly = true;
break; break;
case 'b': /* Dump blobs */ case 'b': /* Dump blobs */
outputBlobs = true; dopt->outputBlobs = true;
break; break;
case 'c': /* clean (i.e., drop) schema prior to create */ case 'c': /* clean (i.e., drop) schema prior to create */
outputClean = 1; dopt->outputClean = 1;
break; break;
case 'C': /* Create DB */ case 'C': /* Create DB */
outputCreateDB = 1; dopt->outputCreateDB = 1;
break; break;
case 'd': /* database name */ case 'd': /* database name */
dbname = pg_strdup(optarg); dopt->dbname = pg_strdup(optarg);
break; break;
case 'E': /* Dump encoding */ case 'E': /* Dump encoding */
...@@ -441,7 +409,7 @@ main(int argc, char **argv) ...@@ -441,7 +409,7 @@ main(int argc, char **argv)
break; break;
case 'h': /* server host */ case 'h': /* server host */
pghost = pg_strdup(optarg); dopt->pghost = pg_strdup(optarg);
break; break;
case 'i': case 'i':
...@@ -454,7 +422,7 @@ main(int argc, char **argv) ...@@ -454,7 +422,7 @@ main(int argc, char **argv)
case 'n': /* include schema(s) */ case 'n': /* include schema(s) */
simple_string_list_append(&schema_include_patterns, optarg); simple_string_list_append(&schema_include_patterns, optarg);
include_everything = false; dopt->include_everything = false;
break; break;
case 'N': /* exclude schema(s) */ case 'N': /* exclude schema(s) */
...@@ -462,15 +430,15 @@ main(int argc, char **argv) ...@@ -462,15 +430,15 @@ main(int argc, char **argv)
break; break;
case 'o': /* Dump oids */ case 'o': /* Dump oids */
oids = true; dopt->oids = true;
break; break;
case 'O': /* Don't reconnect to match owner */ case 'O': /* Don't reconnect to match owner */
outputNoOwner = 1; dopt->outputNoOwner = 1;
break; break;
case 'p': /* server port */ case 'p': /* server port */
pgport = pg_strdup(optarg); dopt->pgport = pg_strdup(optarg);
break; break;
case 'R': case 'R':
...@@ -478,16 +446,16 @@ main(int argc, char **argv) ...@@ -478,16 +446,16 @@ main(int argc, char **argv)
break; break;
case 's': /* dump schema only */ case 's': /* dump schema only */
schemaOnly = true; dopt->schemaOnly = true;
break; break;
case 'S': /* Username for superuser in plain text output */ case 'S': /* Username for superuser in plain text output */
outputSuperuser = pg_strdup(optarg); dopt->outputSuperuser = pg_strdup(optarg);
break; break;
case 't': /* include table(s) */ case 't': /* include table(s) */
simple_string_list_append(&table_include_patterns, optarg); simple_string_list_append(&table_include_patterns, optarg);
include_everything = false; dopt->include_everything = false;
break; break;
case 'T': /* exclude table(s) */ case 'T': /* exclude table(s) */
...@@ -495,7 +463,7 @@ main(int argc, char **argv) ...@@ -495,7 +463,7 @@ main(int argc, char **argv)
break; break;
case 'U': case 'U':
username = pg_strdup(optarg); dopt->username = pg_strdup(optarg);
break; break;
case 'v': /* verbose */ case 'v': /* verbose */
...@@ -511,7 +479,7 @@ main(int argc, char **argv) ...@@ -511,7 +479,7 @@ main(int argc, char **argv)
break; break;
case 'x': /* skip ACL dump */ case 'x': /* skip ACL dump */
aclsSkip = true; dopt->aclsSkip = true;
break; break;
case 'Z': /* Compression Level */ case 'Z': /* Compression Level */
...@@ -523,7 +491,7 @@ main(int argc, char **argv) ...@@ -523,7 +491,7 @@ main(int argc, char **argv)
break; break;
case 2: /* lock-wait-timeout */ case 2: /* lock-wait-timeout */
lockWaitTimeout = pg_strdup(optarg); dopt->lockWaitTimeout = pg_strdup(optarg);
break; break;
case 3: /* SET ROLE */ case 3: /* SET ROLE */
...@@ -535,7 +503,7 @@ main(int argc, char **argv) ...@@ -535,7 +503,7 @@ main(int argc, char **argv)
break; break;
case 5: /* section */ case 5: /* section */
set_dump_section(optarg, &dumpSections); set_dump_section(optarg, &dopt->dumpSections);
break; break;
default: default:
...@@ -548,8 +516,8 @@ main(int argc, char **argv) ...@@ -548,8 +516,8 @@ main(int argc, char **argv)
* Non-option argument specifies database name as long as it wasn't * Non-option argument specifies database name as long as it wasn't
* already specified with -d / --dbname * already specified with -d / --dbname
*/ */
if (optind < argc && dbname == NULL) if (optind < argc && dopt->dbname == NULL)
dbname = argv[optind++]; dopt->dbname = argv[optind++];
/* Complain if any arguments remain */ /* Complain if any arguments remain */
if (optind < argc) if (optind < argc)
...@@ -562,29 +530,29 @@ main(int argc, char **argv) ...@@ -562,29 +530,29 @@ main(int argc, char **argv)
} }
/* --column-inserts implies --inserts */ /* --column-inserts implies --inserts */
if (column_inserts) if (dopt->column_inserts)
dump_inserts = 1; dopt->dump_inserts = 1;
if (dataOnly && schemaOnly) if (dopt->dataOnly && dopt->schemaOnly)
{ {
write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n"); write_msg(NULL, "options -s/--schema-only and -a/--data-only cannot be used together\n");
exit_nicely(1); exit_nicely(1);
} }
if (dataOnly && outputClean) if (dopt->dataOnly && dopt->outputClean)
{ {
write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n"); write_msg(NULL, "options -c/--clean and -a/--data-only cannot be used together\n");
exit_nicely(1); exit_nicely(1);
} }
if (dump_inserts && oids) if (dopt->dump_inserts && dopt->oids)
{ {
write_msg(NULL, "options --inserts/--column-inserts and -o/--oids cannot be used together\n"); write_msg(NULL, "options --inserts/--column-inserts and -o/--oids cannot be used together\n");
write_msg(NULL, "(The INSERT command cannot set OIDs.)\n"); write_msg(NULL, "(The INSERT command cannot set OIDs.)\n");
exit_nicely(1); exit_nicely(1);
} }
if (if_exists && !outputClean) if (dopt->if_exists && !dopt->outputClean)
exit_horribly(NULL, "option --if-exists requires option -c/--clean\n"); exit_horribly(NULL, "option --if-exists requires option -c/--clean\n");
/* Identify archive format to emit */ /* Identify archive format to emit */
...@@ -645,15 +613,15 @@ main(int argc, char **argv) ...@@ -645,15 +613,15 @@ main(int argc, char **argv)
* 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.
*/ */
ConnectDatabase(fout, dbname, pghost, pgport, username, prompt_password); ConnectDatabase(fout, dopt->dbname, dopt->pghost, dopt->pgport, dopt->username, prompt_password);
setup_connection(fout, dumpencoding, use_role); setup_connection(fout, dopt, 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 (fout->remoteVersion < 90100) if (fout->remoteVersion < 90100)
no_security_labels = 1; dopt->no_security_labels = 1;
/* /*
* When running against 9.0 or later, check if we are in recovery mode, * When running against 9.0 or later, check if we are in recovery mode,
...@@ -669,7 +637,7 @@ main(int argc, char **argv) ...@@ -669,7 +637,7 @@ main(int argc, char **argv)
* On hot standby slaves, never try to dump unlogged table data, * On hot standby slaves, never try to dump unlogged table data,
* since it will just throw an error. * since it will just throw an error.
*/ */
no_unlogged_table_data = true; dopt->no_unlogged_table_data = true;
} }
PQclear(res); PQclear(res);
} }
...@@ -684,7 +652,7 @@ main(int argc, char **argv) ...@@ -684,7 +652,7 @@ main(int argc, char **argv)
/* check the version for the synchronized snapshots feature */ /* check the version for the synchronized snapshots feature */
if (numWorkers > 1 && fout->remoteVersion < 90200 if (numWorkers > 1 && fout->remoteVersion < 90200
&& !no_synchronized_snapshots) && !dopt->no_synchronized_snapshots)
exit_horribly(NULL, exit_horribly(NULL,
"Synchronized snapshots are not supported by this server version.\n" "Synchronized snapshots are not supported by this server version.\n"
"Run with --no-synchronized-snapshots instead if you do not need\n" "Run with --no-synchronized-snapshots instead if you do not need\n"
...@@ -734,27 +702,27 @@ main(int argc, char **argv) ...@@ -734,27 +702,27 @@ main(int argc, char **argv)
* Dumping blobs is now default unless we saw an inclusion switch or -s * Dumping blobs is now default unless we saw an inclusion switch or -s
* ... but even if we did see one of these, -b turns it back on. * ... but even if we did see one of these, -b turns it back on.
*/ */
if (include_everything && !schemaOnly) if (dopt->include_everything && !dopt->schemaOnly)
outputBlobs = true; dopt->outputBlobs = true;
/* /*
* 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(fout, &numTables); tblinfo = getSchemaData(fout, dopt, &numTables);
if (fout->remoteVersion < 80400) if (fout->remoteVersion < 80400)
guessConstraintInheritance(tblinfo, numTables); guessConstraintInheritance(tblinfo, numTables);
if (!schemaOnly) if (!dopt->schemaOnly)
{ {
getTableData(tblinfo, numTables, oids); getTableData(dopt, tblinfo, numTables, dopt->oids);
buildMatViewRefreshDependencies(fout); buildMatViewRefreshDependencies(fout);
if (dataOnly) if (dopt->dataOnly)
getTableDataFKConstraints(); getTableDataFKConstraints();
} }
if (outputBlobs) if (dopt->outputBlobs)
getBlobs(fout); getBlobs(fout);
/* /*
...@@ -804,31 +772,39 @@ main(int argc, char **argv) ...@@ -804,31 +772,39 @@ main(int argc, char **argv)
dumpStdStrings(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 (dopt->include_everything && !dopt->dataOnly)
dumpDatabase(fout); dumpDatabase(fout, dopt);
/* Now the rearrangeable objects. */ /* Now the rearrangeable objects. */
for (i = 0; i < numObjs; i++) for (i = 0; i < numObjs; i++)
dumpDumpableObject(fout, dobjs[i]); dumpDumpableObject(fout, dopt, dobjs[i]);
/* /*
* Set up options info to ensure we dump what we want. * Set up options info to ensure we dump what we want.
*/ */
ropt = NewRestoreOptions(); ropt = NewRestoreOptions();
ropt->filename = filename; ropt->filename = filename;
ropt->dropSchema = outputClean;
ropt->dataOnly = dataOnly; /* if you change this list, see dumpOptionsFromRestoreOptions */
ropt->schemaOnly = schemaOnly; ropt->dropSchema = dopt->outputClean;
ropt->if_exists = if_exists; ropt->dataOnly = dopt->dataOnly;
ropt->dumpSections = dumpSections; ropt->schemaOnly = dopt->schemaOnly;
ropt->aclsSkip = aclsSkip; ropt->if_exists = dopt->if_exists;
ropt->superuser = outputSuperuser; ropt->column_inserts = dopt->column_inserts;
ropt->createDB = outputCreateDB; ropt->dumpSections = dopt->dumpSections;
ropt->noOwner = outputNoOwner; ropt->aclsSkip = dopt->aclsSkip;
ropt->noTablespace = outputNoTablespaces; ropt->superuser = dopt->outputSuperuser;
ropt->disable_triggers = disable_triggers; ropt->createDB = dopt->outputCreateDB;
ropt->use_setsessauth = use_setsessauth; ropt->noOwner = dopt->outputNoOwner;
ropt->enable_row_security = enable_row_security; ropt->noTablespace = dopt->outputNoTablespaces;
ropt->disable_triggers = dopt->disable_triggers;
ropt->use_setsessauth = dopt->use_setsessauth;
ropt->disable_dollar_quoting = dopt->disable_dollar_quoting;
ropt->dump_inserts = dopt->dump_inserts;
ropt->no_security_labels = dopt->no_security_labels;
ropt->lockWaitTimeout = dopt->lockWaitTimeout;
ropt->include_everything = dopt->include_everything;
ropt->enable_row_security = dopt->enable_row_security;
if (compressLevel == -1) if (compressLevel == -1)
ropt->compression = 0; ropt->compression = 0;
...@@ -857,7 +833,7 @@ main(int argc, char **argv) ...@@ -857,7 +833,7 @@ main(int argc, char **argv)
if (plainText) if (plainText)
RestoreArchive(fout); RestoreArchive(fout);
CloseArchive(fout); CloseArchive(fout, dopt);
exit_nicely(0); exit_nicely(0);
} }
...@@ -931,7 +907,7 @@ help(const char *progname) ...@@ -931,7 +907,7 @@ help(const char *progname)
} }
static void static void
setup_connection(Archive *AH, const char *dumpencoding, char *use_role) setup_connection(Archive *AH, DumpOptions *dopt, const char *dumpencoding, char *use_role)
{ {
PGconn *conn = GetConnection(AH); PGconn *conn = GetConnection(AH);
const char *std_strings; const char *std_strings;
...@@ -1019,7 +995,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -1019,7 +995,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
ExecuteSqlStatement(AH, "BEGIN"); ExecuteSqlStatement(AH, "BEGIN");
if (AH->remoteVersion >= 90100) if (AH->remoteVersion >= 90100)
{ {
if (serializable_deferrable) if (dopt->serializable_deferrable)
ExecuteSqlStatement(AH, ExecuteSqlStatement(AH,
"SET TRANSACTION ISOLATION LEVEL " "SET TRANSACTION ISOLATION LEVEL "
"SERIALIZABLE, READ ONLY, DEFERRABLE"); "SERIALIZABLE, READ ONLY, DEFERRABLE");
...@@ -1041,7 +1017,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -1041,7 +1017,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
if (AH->numWorkers > 1 && AH->remoteVersion >= 90200 && !no_synchronized_snapshots) if (AH->numWorkers > 1 && AH->remoteVersion >= 90200 && !dopt->no_synchronized_snapshots)
{ {
if (AH->sync_snapshot_id) if (AH->sync_snapshot_id)
{ {
...@@ -1058,7 +1034,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -1058,7 +1034,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
if (AH->remoteVersion >= 90500) if (AH->remoteVersion >= 90500)
{ {
if (enable_row_security) if (dopt->enable_row_security)
ExecuteSqlStatement(AH, "SET row_security TO ON"); ExecuteSqlStatement(AH, "SET row_security TO ON");
else else
ExecuteSqlStatement(AH, "SET row_security TO OFF"); ExecuteSqlStatement(AH, "SET row_security TO OFF");
...@@ -1066,9 +1042,9 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -1066,9 +1042,9 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
} }
static void static void
setupDumpWorker(Archive *AHX, RestoreOptions *ropt) setupDumpWorker(Archive *AHX, DumpOptions *dopt, RestoreOptions *ropt)
{ {
setup_connection(AHX, NULL, NULL); setup_connection(AHX, dopt, NULL, NULL);
} }
static char * static char *
...@@ -1339,12 +1315,12 @@ selectDumpableType(TypeInfo *tyinfo) ...@@ -1339,12 +1315,12 @@ selectDumpableType(TypeInfo *tyinfo)
* and aclsSkip are checked separately. * and aclsSkip are checked separately.
*/ */
static void static void
selectDumpableDefaultACL(DefaultACLInfo *dinfo) selectDumpableDefaultACL(DumpOptions *dopt, DefaultACLInfo *dinfo)
{ {
if (dinfo->dobj.namespace) if (dinfo->dobj.namespace)
dinfo->dobj.dump = dinfo->dobj.namespace->dobj.dump; dinfo->dobj.dump = dinfo->dobj.namespace->dobj.dump;
else else
dinfo->dobj.dump = include_everything; dinfo->dobj.dump = dopt->include_everything;
} }
/* /*
...@@ -1358,12 +1334,12 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo) ...@@ -1358,12 +1334,12 @@ selectDumpableDefaultACL(DefaultACLInfo *dinfo)
* such extensions by their having OIDs in the range reserved for initdb. * such extensions by their having OIDs in the range reserved for initdb.
*/ */
static void static void
selectDumpableExtension(ExtensionInfo *extinfo) selectDumpableExtension(DumpOptions *dopt, ExtensionInfo *extinfo)
{ {
if (binary_upgrade && extinfo->dobj.catId.oid < (Oid) FirstNormalObjectId) if (dopt->binary_upgrade && extinfo->dobj.catId.oid < (Oid) FirstNormalObjectId)
extinfo->dobj.dump = false; extinfo->dobj.dump = false;
else else
extinfo->dobj.dump = include_everything; extinfo->dobj.dump = dopt->include_everything;
} }
/* /*
...@@ -1392,7 +1368,7 @@ selectDumpableObject(DumpableObject *dobj) ...@@ -1392,7 +1368,7 @@ selectDumpableObject(DumpableObject *dobj)
*/ */
static int static int
dumpTableData_copy(Archive *fout, void *dcontext) dumpTableData_copy(Archive *fout, DumpOptions *dopt, void *dcontext)
{ {
TableDataInfo *tdinfo = (TableDataInfo *) dcontext; TableDataInfo *tdinfo = (TableDataInfo *) dcontext;
TableInfo *tbinfo = tdinfo->tdtable; TableInfo *tbinfo = tdinfo->tdtable;
...@@ -1567,7 +1543,7 @@ dumpTableData_copy(Archive *fout, void *dcontext) ...@@ -1567,7 +1543,7 @@ dumpTableData_copy(Archive *fout, void *dcontext)
* E'' strings, or dollar-quoted strings. So don't emit anything like that. * E'' strings, or dollar-quoted strings. So don't emit anything like that.
*/ */
static int static int
dumpTableData_insert(Archive *fout, void *dcontext) dumpTableData_insert(Archive *fout, DumpOptions *dopt, void *dcontext)
{ {
TableDataInfo *tdinfo = (TableDataInfo *) dcontext; TableDataInfo *tdinfo = (TableDataInfo *) dcontext;
TableInfo *tbinfo = tdinfo->tdtable; TableInfo *tbinfo = tdinfo->tdtable;
...@@ -1636,7 +1612,7 @@ dumpTableData_insert(Archive *fout, void *dcontext) ...@@ -1636,7 +1612,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
else else
{ {
/* append the list of column names if required */ /* append the list of column names if required */
if (column_inserts) if (dopt->column_inserts)
{ {
appendPQExpBufferStr(insertStmt, "("); appendPQExpBufferStr(insertStmt, "(");
for (field = 0; field < nfields; field++) for (field = 0; field < nfields; field++)
...@@ -1753,7 +1729,7 @@ dumpTableData_insert(Archive *fout, void *dcontext) ...@@ -1753,7 +1729,7 @@ dumpTableData_insert(Archive *fout, void *dcontext)
* Actually, this just makes an ArchiveEntry for the table contents. * Actually, this just makes an ArchiveEntry for the table contents.
*/ */
static void static void
dumpTableData(Archive *fout, TableDataInfo *tdinfo) dumpTableData(Archive *fout, DumpOptions *dopt, TableDataInfo *tdinfo)
{ {
TableInfo *tbinfo = tdinfo->tdtable; TableInfo *tbinfo = tdinfo->tdtable;
PQExpBuffer copyBuf = createPQExpBuffer(); PQExpBuffer copyBuf = createPQExpBuffer();
...@@ -1761,7 +1737,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo) ...@@ -1761,7 +1737,7 @@ dumpTableData(Archive *fout, TableDataInfo *tdinfo)
DataDumperPtr dumpFn; DataDumperPtr dumpFn;
char *copyStmt; char *copyStmt;
if (!dump_inserts) if (!dopt->dump_inserts)
{ {
/* Dump/restore using COPY */ /* Dump/restore using COPY */
dumpFn = dumpTableData_copy; dumpFn = dumpTableData_copy;
...@@ -1845,14 +1821,14 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo) ...@@ -1845,14 +1821,14 @@ refreshMatViewData(Archive *fout, TableDataInfo *tdinfo)
* set up dumpable objects representing the contents of tables * set up dumpable objects representing the contents of tables
*/ */
static void static void
getTableData(TableInfo *tblinfo, int numTables, bool oids) getTableData(DumpOptions *dopt, TableInfo *tblinfo, int numTables, bool oids)
{ {
int i; int i;
for (i = 0; i < numTables; i++) for (i = 0; i < numTables; i++)
{ {
if (tblinfo[i].dobj.dump) if (tblinfo[i].dobj.dump)
makeTableDataInfo(&(tblinfo[i]), oids); makeTableDataInfo(dopt, &(tblinfo[i]), oids);
} }
} }
...@@ -1863,7 +1839,7 @@ getTableData(TableInfo *tblinfo, int numTables, bool oids) ...@@ -1863,7 +1839,7 @@ getTableData(TableInfo *tblinfo, int numTables, bool oids)
* table data; the "dump" flag in such objects isn't used. * table data; the "dump" flag in such objects isn't used.
*/ */
static void static void
makeTableDataInfo(TableInfo *tbinfo, bool oids) makeTableDataInfo(DumpOptions *dopt, TableInfo *tbinfo, bool oids)
{ {
TableDataInfo *tdinfo; TableDataInfo *tdinfo;
...@@ -1883,7 +1859,7 @@ makeTableDataInfo(TableInfo *tbinfo, bool oids) ...@@ -1883,7 +1859,7 @@ makeTableDataInfo(TableInfo *tbinfo, bool oids)
/* Don't dump data in unlogged tables, if so requested */ /* Don't dump data in unlogged tables, if so requested */
if (tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED && if (tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED &&
no_unlogged_table_data) dopt->no_unlogged_table_data)
return; return;
/* Check that the data is not explicitly excluded */ /* Check that the data is not explicitly excluded */
...@@ -2156,7 +2132,7 @@ guessConstraintInheritance(TableInfo *tblinfo, int numTables) ...@@ -2156,7 +2132,7 @@ guessConstraintInheritance(TableInfo *tblinfo, int numTables)
* dump the database definition * dump the database definition
*/ */
static void static void
dumpDatabase(Archive *fout) dumpDatabase(Archive *fout, DumpOptions *dopt)
{ {
PQExpBuffer dbQry = createPQExpBuffer(); PQExpBuffer dbQry = createPQExpBuffer();
PQExpBuffer delQry = createPQExpBuffer(); PQExpBuffer delQry = createPQExpBuffer();
...@@ -2318,7 +2294,7 @@ dumpDatabase(Archive *fout) ...@@ -2318,7 +2294,7 @@ dumpDatabase(Archive *fout)
fmtId(tablespace)); fmtId(tablespace));
appendPQExpBufferStr(creaQry, ";\n"); appendPQExpBufferStr(creaQry, ";\n");
if (binary_upgrade) if (dopt->binary_upgrade)
{ {
appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid and datminmxid.\n"); appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid and datminmxid.\n");
appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n" appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n"
...@@ -2357,7 +2333,7 @@ dumpDatabase(Archive *fout) ...@@ -2357,7 +2333,7 @@ dumpDatabase(Archive *fout)
* pg_largeobject and pg_largeobject_metadata come from the old system * pg_largeobject and pg_largeobject_metadata come from the old system
* intact, so set their relfrozenxids and relminmxids. * intact, so set their relfrozenxids and relminmxids.
*/ */
if (binary_upgrade) if (dopt->binary_upgrade)
{ {
PGresult *lo_res; PGresult *lo_res;
PQExpBuffer loFrozenQry = createPQExpBuffer(); PQExpBuffer loFrozenQry = createPQExpBuffer();
...@@ -2475,14 +2451,14 @@ dumpDatabase(Archive *fout) ...@@ -2475,14 +2451,14 @@ dumpDatabase(Archive *fout)
{ {
resetPQExpBuffer(dbQry); resetPQExpBuffer(dbQry);
appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname)); appendPQExpBuffer(dbQry, "DATABASE %s", fmtId(datname));
dumpComment(fout, dbQry->data, NULL, "", dumpComment(fout, dopt, 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 && fout->remoteVersion >= 90200) if (!dopt->no_security_labels && fout->remoteVersion >= 90200)
{ {
PQExpBuffer seclabelQry = createPQExpBuffer(); PQExpBuffer seclabelQry = createPQExpBuffer();
...@@ -2503,7 +2479,6 @@ dumpDatabase(Archive *fout) ...@@ -2503,7 +2479,6 @@ dumpDatabase(Archive *fout)
destroyPQExpBuffer(creaQry); destroyPQExpBuffer(creaQry);
} }
/* /*
* dumpEncoding: put the correct encoding into the archive * dumpEncoding: put the correct encoding into the archive
*/ */
...@@ -2643,7 +2618,7 @@ getBlobs(Archive *fout) ...@@ -2643,7 +2618,7 @@ getBlobs(Archive *fout)
* dump the definition (metadata) of the given large object * dump the definition (metadata) of the given large object
*/ */
static void static void
dumpBlob(Archive *fout, BlobInfo *binfo) dumpBlob(Archive *fout, DumpOptions *dopt, BlobInfo *binfo)
{ {
PQExpBuffer cquery = createPQExpBuffer(); PQExpBuffer cquery = createPQExpBuffer();
PQExpBuffer dquery = createPQExpBuffer(); PQExpBuffer dquery = createPQExpBuffer();
...@@ -2670,18 +2645,18 @@ dumpBlob(Archive *fout, BlobInfo *binfo) ...@@ -2670,18 +2645,18 @@ dumpBlob(Archive *fout, 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(fout, cquery->data, dumpComment(fout, dopt, 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(fout, cquery->data, dumpSecLabel(fout, dopt, 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(fout, binfo->dobj.catId, binfo->dobj.dumpId, "LARGE OBJECT", dumpACL(fout, dopt, 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);
...@@ -2694,7 +2669,7 @@ dumpBlob(Archive *fout, BlobInfo *binfo) ...@@ -2694,7 +2669,7 @@ dumpBlob(Archive *fout, BlobInfo *binfo)
* dump the data contents of all large objects * dump the data contents of all large objects
*/ */
static int static int
dumpBlobs(Archive *fout, void *arg) dumpBlobs(Archive *fout, DumpOptions *dopt, void *arg)
{ {
const char *blobQry; const char *blobQry;
const char *blobFetchQry; const char *blobFetchQry;
...@@ -2922,14 +2897,14 @@ getRowSecurity(Archive *fout, TableInfo tblinfo[], int numTables) ...@@ -2922,14 +2897,14 @@ getRowSecurity(Archive *fout, TableInfo tblinfo[], int numTables)
* dump the definition of the given row-security policy * dump the definition of the given row-security policy
*/ */
static void static void
dumpRowSecurity(Archive *fout, RowSecurityInfo *rsinfo) dumpRowSecurity(Archive *fout, DumpOptions *dopt, RowSecurityInfo *rsinfo)
{ {
TableInfo *tbinfo = rsinfo->rstable; TableInfo *tbinfo = rsinfo->rstable;
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer delqry; PQExpBuffer delqry;
const char *cmd; const char *cmd;
if (dataOnly) if (dopt->dataOnly)
return; return;
/* /*
...@@ -3343,7 +3318,7 @@ findNamespace(Archive *fout, Oid nsoid, Oid objoid) ...@@ -3343,7 +3318,7 @@ findNamespace(Archive *fout, 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(Archive *fout, int *numExtensions) getExtensions(Archive *fout, DumpOptions *dopt, int *numExtensions)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -3407,7 +3382,7 @@ getExtensions(Archive *fout, int *numExtensions) ...@@ -3407,7 +3382,7 @@ getExtensions(Archive *fout, int *numExtensions)
extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition)); extinfo[i].extcondition = pg_strdup(PQgetvalue(res, i, i_extcondition));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
selectDumpableExtension(&(extinfo[i])); selectDumpableExtension(dopt, &(extinfo[i]));
} }
PQclear(res); PQclear(res);
...@@ -4158,7 +4133,7 @@ getOpfamilies(Archive *fout, int *numOpfamilies) ...@@ -4158,7 +4133,7 @@ getOpfamilies(Archive *fout, 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(Archive *fout, int *numAggs) getAggregates(Archive *fout, DumpOptions *dopt, int *numAggs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -4197,7 +4172,7 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4197,7 +4172,7 @@ getAggregates(Archive *fout, 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 && fout->remoteVersion >= 90100) if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBufferStr(query, appendPQExpBufferStr(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 "
...@@ -4337,7 +4312,7 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -4337,7 +4312,7 @@ getAggregates(Archive *fout, 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(Archive *fout, int *numFuncs) getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -4394,7 +4369,7 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -4394,7 +4369,7 @@ getFuncs(Archive *fout, int *numFuncs)
"\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 && fout->remoteVersion >= 90100) if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBufferStr(query, appendPQExpBufferStr(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 "
...@@ -4520,7 +4495,7 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -4520,7 +4495,7 @@ getFuncs(Archive *fout, 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(Archive *fout, int *numTables) getTables(Archive *fout, DumpOptions *dopt, int *numTables)
{ {
PGresult *res; PGresult *res;
int ntups; int ntups;
...@@ -5071,7 +5046,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5071,7 +5046,7 @@ getTables(Archive *fout, 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 && fout->remoteVersion >= 70300) if (dopt->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.
...@@ -5082,7 +5057,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5082,7 +5057,7 @@ getTables(Archive *fout, int *numTables)
*/ */
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBufferStr(query, "SET statement_timeout = "); appendPQExpBufferStr(query, "SET statement_timeout = ");
appendStringLiteralConn(query, lockWaitTimeout, GetConnection(fout)); appendStringLiteralConn(query, dopt->lockWaitTimeout, GetConnection(fout));
ExecuteSqlStatement(fout, query->data); ExecuteSqlStatement(fout, query->data);
} }
...@@ -5178,7 +5153,7 @@ getTables(Archive *fout, int *numTables) ...@@ -5178,7 +5153,7 @@ getTables(Archive *fout, int *numTables)
tblinfo[i].dobj.name); tblinfo[i].dobj.name);
} }
if (lockWaitTimeout && fout->remoteVersion >= 70300) if (dopt->lockWaitTimeout && fout->remoteVersion >= 70300)
{ {
ExecuteSqlStatement(fout, "SET statement_timeout = 0"); ExecuteSqlStatement(fout, "SET statement_timeout = 0");
} }
...@@ -6593,7 +6568,7 @@ getCasts(Archive *fout, int *numCasts) ...@@ -6593,7 +6568,7 @@ getCasts(Archive *fout, int *numCasts)
* modifies tblinfo * modifies tblinfo
*/ */
void void
getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) getTableAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tblinfo, int numTables)
{ {
int i, int i,
j; j;
...@@ -6948,7 +6923,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6948,7 +6923,7 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
addObjectDependency(&attrdefs[j].dobj, addObjectDependency(&attrdefs[j].dobj,
tbinfo->dobj.dumpId); tbinfo->dobj.dumpId);
} }
else if (!shouldPrintColumn(tbinfo, adnum - 1)) else if (!shouldPrintColumn(dopt, tbinfo, adnum - 1))
{ {
/* column will be suppressed, print default separately */ /* column will be suppressed, print default separately */
attrdefs[j].separate = true; attrdefs[j].separate = true;
...@@ -7161,9 +7136,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -7161,9 +7136,9 @@ getTableAttrs(Archive *fout, TableInfo *tblinfo, int numTables)
* must be kept in sync with this decision. * must be kept in sync with this decision.
*/ */
bool bool
shouldPrintColumn(TableInfo *tbinfo, int colno) shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno)
{ {
if (binary_upgrade) if (dopt->binary_upgrade)
return true; return true;
return (tbinfo->attislocal[colno] && !tbinfo->attisdropped[colno]); return (tbinfo->attislocal[colno] && !tbinfo->attisdropped[colno]);
} }
...@@ -7709,7 +7684,7 @@ getForeignServers(Archive *fout, int *numForeignServers) ...@@ -7709,7 +7684,7 @@ getForeignServers(Archive *fout, 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(Archive *fout, int *numDefaultACLs) getDefaultACLs(Archive *fout, DumpOptions *dopt, int *numDefaultACLs)
{ {
DefaultACLInfo *daclinfo; DefaultACLInfo *daclinfo;
PQExpBuffer query; PQExpBuffer query;
...@@ -7778,7 +7753,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) ...@@ -7778,7 +7753,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl)); daclinfo[i].defaclacl = pg_strdup(PQgetvalue(res, i, i_defaclacl));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
selectDumpableDefaultACL(&(daclinfo[i])); selectDumpableDefaultACL(dopt, &(daclinfo[i]));
} }
PQclear(res); PQclear(res);
...@@ -7807,7 +7782,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs) ...@@ -7807,7 +7782,7 @@ getDefaultACLs(Archive *fout, int *numDefaultACLs)
* calling ArchiveEntry() for the specified object. * calling ArchiveEntry() for the specified object.
*/ */
static void static void
dumpComment(Archive *fout, const char *target, dumpComment(Archive *fout, DumpOptions *dopt, const char *target,
const char *namespace, const char *owner, const char *namespace, const char *owner,
CatalogId catalogId, int subid, DumpId dumpId) CatalogId catalogId, int subid, DumpId dumpId)
{ {
...@@ -7817,12 +7792,12 @@ dumpComment(Archive *fout, const char *target, ...@@ -7817,12 +7792,12 @@ dumpComment(Archive *fout, const char *target,
/* Comments are schema not data ... except blob comments are data */ /* Comments are schema not data ... except blob comments are data */
if (strncmp(target, "LARGE OBJECT ", 13) != 0) if (strncmp(target, "LARGE OBJECT ", 13) != 0)
{ {
if (dataOnly) if (dopt->dataOnly)
return; return;
} }
else else
{ {
if (schemaOnly) if (dopt->schemaOnly)
return; return;
} }
...@@ -7871,7 +7846,7 @@ dumpComment(Archive *fout, const char *target, ...@@ -7871,7 +7846,7 @@ dumpComment(Archive *fout, const char *target,
* and its columns. * and its columns.
*/ */
static void static void
dumpTableComment(Archive *fout, TableInfo *tbinfo, dumpTableComment(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo,
const char *reltypename) const char *reltypename)
{ {
CommentItem *comments; CommentItem *comments;
...@@ -7880,7 +7855,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, ...@@ -7880,7 +7855,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
PQExpBuffer target; PQExpBuffer target;
/* Comments are SCHEMA not data */ /* Comments are SCHEMA not data */
if (dataOnly) if (dopt->dataOnly)
return; return;
/* Search for comments associated with relation, using table */ /* Search for comments associated with relation, using table */
...@@ -8125,108 +8100,108 @@ collectComments(Archive *fout, CommentItem **items) ...@@ -8125,108 +8100,108 @@ collectComments(Archive *fout, CommentItem **items)
* ArchiveEntries (TOC objects) for each object to be dumped. * ArchiveEntries (TOC objects) for each object to be dumped.
*/ */
static void static void
dumpDumpableObject(Archive *fout, DumpableObject *dobj) dumpDumpableObject(Archive *fout, DumpOptions *dopt, DumpableObject *dobj)
{ {
switch (dobj->objType) switch (dobj->objType)
{ {
case DO_NAMESPACE: case DO_NAMESPACE:
dumpNamespace(fout, (NamespaceInfo *) dobj); dumpNamespace(fout, dopt, (NamespaceInfo *) dobj);
break; break;
case DO_EXTENSION: case DO_EXTENSION:
dumpExtension(fout, (ExtensionInfo *) dobj); dumpExtension(fout, dopt, (ExtensionInfo *) dobj);
break; break;
case DO_TYPE: case DO_TYPE:
dumpType(fout, (TypeInfo *) dobj); dumpType(fout, dopt, (TypeInfo *) dobj);
break; break;
case DO_SHELL_TYPE: case DO_SHELL_TYPE:
dumpShellType(fout, (ShellTypeInfo *) dobj); dumpShellType(fout, dopt, (ShellTypeInfo *) dobj);
break; break;
case DO_FUNC: case DO_FUNC:
dumpFunc(fout, (FuncInfo *) dobj); dumpFunc(fout, dopt, (FuncInfo *) dobj);
break; break;
case DO_AGG: case DO_AGG:
dumpAgg(fout, (AggInfo *) dobj); dumpAgg(fout, dopt, (AggInfo *) dobj);
break; break;
case DO_OPERATOR: case DO_OPERATOR:
dumpOpr(fout, (OprInfo *) dobj); dumpOpr(fout, dopt, (OprInfo *) dobj);
break; break;
case DO_OPCLASS: case DO_OPCLASS:
dumpOpclass(fout, (OpclassInfo *) dobj); dumpOpclass(fout, dopt, (OpclassInfo *) dobj);
break; break;
case DO_OPFAMILY: case DO_OPFAMILY:
dumpOpfamily(fout, (OpfamilyInfo *) dobj); dumpOpfamily(fout, dopt, (OpfamilyInfo *) dobj);
break; break;
case DO_COLLATION: case DO_COLLATION:
dumpCollation(fout, (CollInfo *) dobj); dumpCollation(fout, dopt, (CollInfo *) dobj);
break; break;
case DO_CONVERSION: case DO_CONVERSION:
dumpConversion(fout, (ConvInfo *) dobj); dumpConversion(fout, dopt, (ConvInfo *) dobj);
break; break;
case DO_TABLE: case DO_TABLE:
dumpTable(fout, (TableInfo *) dobj); dumpTable(fout, dopt, (TableInfo *) dobj);
break; break;
case DO_ATTRDEF: case DO_ATTRDEF:
dumpAttrDef(fout, (AttrDefInfo *) dobj); dumpAttrDef(fout, dopt, (AttrDefInfo *) dobj);
break; break;
case DO_INDEX: case DO_INDEX:
dumpIndex(fout, (IndxInfo *) dobj); dumpIndex(fout, dopt, (IndxInfo *) dobj);
break; break;
case DO_REFRESH_MATVIEW: case DO_REFRESH_MATVIEW:
refreshMatViewData(fout, (TableDataInfo *) dobj); refreshMatViewData(fout, (TableDataInfo *) dobj);
break; break;
case DO_RULE: case DO_RULE:
dumpRule(fout, (RuleInfo *) dobj); dumpRule(fout, dopt, (RuleInfo *) dobj);
break; break;
case DO_TRIGGER: case DO_TRIGGER:
dumpTrigger(fout, (TriggerInfo *) dobj); dumpTrigger(fout, dopt, (TriggerInfo *) dobj);
break; break;
case DO_EVENT_TRIGGER: case DO_EVENT_TRIGGER:
dumpEventTrigger(fout, (EventTriggerInfo *) dobj); dumpEventTrigger(fout, dopt, (EventTriggerInfo *) dobj);
break; break;
case DO_CONSTRAINT: case DO_CONSTRAINT:
dumpConstraint(fout, (ConstraintInfo *) dobj); dumpConstraint(fout, dopt, (ConstraintInfo *) dobj);
break; break;
case DO_FK_CONSTRAINT: case DO_FK_CONSTRAINT:
dumpConstraint(fout, (ConstraintInfo *) dobj); dumpConstraint(fout, dopt, (ConstraintInfo *) dobj);
break; break;
case DO_PROCLANG: case DO_PROCLANG:
dumpProcLang(fout, (ProcLangInfo *) dobj); dumpProcLang(fout, dopt, (ProcLangInfo *) dobj);
break; break;
case DO_CAST: case DO_CAST:
dumpCast(fout, (CastInfo *) dobj); dumpCast(fout, dopt, (CastInfo *) dobj);
break; break;
case DO_TABLE_DATA: case DO_TABLE_DATA:
if (((TableDataInfo *) dobj)->tdtable->relkind == RELKIND_SEQUENCE) if (((TableDataInfo *) dobj)->tdtable->relkind == RELKIND_SEQUENCE)
dumpSequenceData(fout, (TableDataInfo *) dobj); dumpSequenceData(fout, (TableDataInfo *) dobj);
else else
dumpTableData(fout, (TableDataInfo *) dobj); dumpTableData(fout, dopt, (TableDataInfo *) dobj);
break; break;
case DO_DUMMY_TYPE: case DO_DUMMY_TYPE:
/* table rowtypes and array types are never dumped separately */ /* table rowtypes and array types are never dumped separately */
break; break;
case DO_TSPARSER: case DO_TSPARSER:
dumpTSParser(fout, (TSParserInfo *) dobj); dumpTSParser(fout, dopt, (TSParserInfo *) dobj);
break; break;
case DO_TSDICT: case DO_TSDICT:
dumpTSDictionary(fout, (TSDictInfo *) dobj); dumpTSDictionary(fout, dopt, (TSDictInfo *) dobj);
break; break;
case DO_TSTEMPLATE: case DO_TSTEMPLATE:
dumpTSTemplate(fout, (TSTemplateInfo *) dobj); dumpTSTemplate(fout, dopt, (TSTemplateInfo *) dobj);
break; break;
case DO_TSCONFIG: case DO_TSCONFIG:
dumpTSConfig(fout, (TSConfigInfo *) dobj); dumpTSConfig(fout, dopt, (TSConfigInfo *) dobj);
break; break;
case DO_FDW: case DO_FDW:
dumpForeignDataWrapper(fout, (FdwInfo *) dobj); dumpForeignDataWrapper(fout, dopt, (FdwInfo *) dobj);
break; break;
case DO_FOREIGN_SERVER: case DO_FOREIGN_SERVER:
dumpForeignServer(fout, (ForeignServerInfo *) dobj); dumpForeignServer(fout, dopt, (ForeignServerInfo *) dobj);
break; break;
case DO_DEFAULT_ACL: case DO_DEFAULT_ACL:
dumpDefaultACL(fout, (DefaultACLInfo *) dobj); dumpDefaultACL(fout, dopt, (DefaultACLInfo *) dobj);
break; break;
case DO_BLOB: case DO_BLOB:
dumpBlob(fout, (BlobInfo *) dobj); dumpBlob(fout, dopt, (BlobInfo *) dobj);
break; break;
case DO_BLOB_DATA: case DO_BLOB_DATA:
ArchiveEntry(fout, dobj->catId, dobj->dumpId, ArchiveEntry(fout, dobj->catId, dobj->dumpId,
...@@ -8237,7 +8212,7 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj) ...@@ -8237,7 +8212,7 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
dumpBlobs, NULL); dumpBlobs, NULL);
break; break;
case DO_ROW_SECURITY: case DO_ROW_SECURITY:
dumpRowSecurity(fout, (RowSecurityInfo *) dobj); dumpRowSecurity(fout, dopt, (RowSecurityInfo *) dobj);
break; break;
case DO_PRE_DATA_BOUNDARY: case DO_PRE_DATA_BOUNDARY:
case DO_POST_DATA_BOUNDARY: case DO_POST_DATA_BOUNDARY:
...@@ -8251,7 +8226,7 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj) ...@@ -8251,7 +8226,7 @@ dumpDumpableObject(Archive *fout, DumpableObject *dobj)
* writes out to fout the queries to recreate a user-defined namespace * writes out to fout the queries to recreate a user-defined namespace
*/ */
static void static void
dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) dumpNamespace(Archive *fout, DumpOptions *dopt, NamespaceInfo *nspinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -8259,7 +8234,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) ...@@ -8259,7 +8234,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
char *qnspname; char *qnspname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!nspinfo->dobj.dump || dataOnly) if (!nspinfo->dobj.dump || dopt->dataOnly)
return; return;
/* don't dump dummy namespace from pre-7.3 source */ /* don't dump dummy namespace from pre-7.3 source */
...@@ -8278,7 +8253,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) ...@@ -8278,7 +8253,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
appendPQExpBuffer(labelq, "SCHEMA %s", qnspname); appendPQExpBuffer(labelq, "SCHEMA %s", qnspname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &nspinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &nspinfo->dobj, labelq->data);
ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId, ArchiveEntry(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId,
...@@ -8291,14 +8266,14 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) ...@@ -8291,14 +8266,14 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
NULL, NULL); NULL, NULL);
/* Dump Schema Comments and Security Labels */ /* Dump Schema Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, nspinfo->rolname, NULL, nspinfo->rolname,
nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId); nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
NULL, nspinfo->rolname, NULL, nspinfo->rolname,
nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId); nspinfo->dobj.catId, 0, nspinfo->dobj.dumpId);
dumpACL(fout, nspinfo->dobj.catId, nspinfo->dobj.dumpId, "SCHEMA", dumpACL(fout, dopt, nspinfo->dobj.catId, nspinfo->dobj.dumpId, "SCHEMA",
qnspname, NULL, nspinfo->dobj.name, NULL, qnspname, NULL, nspinfo->dobj.name, NULL,
nspinfo->rolname, nspinfo->nspacl); nspinfo->rolname, nspinfo->nspacl);
...@@ -8314,7 +8289,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo) ...@@ -8314,7 +8289,7 @@ dumpNamespace(Archive *fout, NamespaceInfo *nspinfo)
* writes out to fout the queries to recreate an extension * writes out to fout the queries to recreate an extension
*/ */
static void static void
dumpExtension(Archive *fout, ExtensionInfo *extinfo) dumpExtension(Archive *fout, DumpOptions *dopt, ExtensionInfo *extinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -8322,7 +8297,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8322,7 +8297,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
char *qextname; char *qextname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!extinfo->dobj.dump || dataOnly) if (!extinfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -8333,7 +8308,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8333,7 +8308,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname); appendPQExpBuffer(delq, "DROP EXTENSION %s;\n", qextname);
if (!binary_upgrade) if (!dopt->binary_upgrade)
{ {
/* /*
* In a regular dump, we use IF NOT EXISTS so that there isn't a * In a regular dump, we use IF NOT EXISTS so that there isn't a
...@@ -8419,10 +8394,10 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8419,10 +8394,10 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
NULL, NULL); NULL, NULL);
/* Dump Extension Comments and Security Labels */ /* Dump Extension Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, "", NULL, "",
extinfo->dobj.catId, 0, extinfo->dobj.dumpId); extinfo->dobj.catId, 0, extinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
NULL, "", NULL, "",
extinfo->dobj.catId, 0, extinfo->dobj.dumpId); extinfo->dobj.catId, 0, extinfo->dobj.dumpId);
...@@ -8438,23 +8413,23 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8438,23 +8413,23 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
* writes out to fout the queries to recreate a user-defined type * writes out to fout the queries to recreate a user-defined type
*/ */
static void static void
dumpType(Archive *fout, TypeInfo *tyinfo) dumpType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!tyinfo->dobj.dump || dataOnly) if (!tyinfo->dobj.dump || dopt->dataOnly)
return; return;
/* Dump out in proper style */ /* Dump out in proper style */
if (tyinfo->typtype == TYPTYPE_BASE) if (tyinfo->typtype == TYPTYPE_BASE)
dumpBaseType(fout, tyinfo); dumpBaseType(fout, dopt, tyinfo);
else if (tyinfo->typtype == TYPTYPE_DOMAIN) else if (tyinfo->typtype == TYPTYPE_DOMAIN)
dumpDomain(fout, tyinfo); dumpDomain(fout, dopt, tyinfo);
else if (tyinfo->typtype == TYPTYPE_COMPOSITE) else if (tyinfo->typtype == TYPTYPE_COMPOSITE)
dumpCompositeType(fout, tyinfo); dumpCompositeType(fout, dopt, tyinfo);
else if (tyinfo->typtype == TYPTYPE_ENUM) else if (tyinfo->typtype == TYPTYPE_ENUM)
dumpEnumType(fout, tyinfo); dumpEnumType(fout, dopt, tyinfo);
else if (tyinfo->typtype == TYPTYPE_RANGE) else if (tyinfo->typtype == TYPTYPE_RANGE)
dumpRangeType(fout, tyinfo); dumpRangeType(fout, dopt, tyinfo);
else else
write_msg(NULL, "WARNING: typtype of data type \"%s\" appears to be invalid\n", write_msg(NULL, "WARNING: typtype of data type \"%s\" appears to be invalid\n",
tyinfo->dobj.name); tyinfo->dobj.name);
...@@ -8465,7 +8440,7 @@ dumpType(Archive *fout, TypeInfo *tyinfo) ...@@ -8465,7 +8440,7 @@ dumpType(Archive *fout, TypeInfo *tyinfo)
* writes out to fout the queries to recreate a user-defined enum type * writes out to fout the queries to recreate a user-defined enum type
*/ */
static void static void
dumpEnumType(Archive *fout, TypeInfo *tyinfo) dumpEnumType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -8510,14 +8485,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8510,14 +8485,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
qtypname); qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
appendPQExpBuffer(q, "CREATE TYPE %s AS ENUM (", appendPQExpBuffer(q, "CREATE TYPE %s AS ENUM (",
qtypname); qtypname);
if (!binary_upgrade) if (!dopt->binary_upgrade)
{ {
/* Labels with server-assigned oids */ /* Labels with server-assigned oids */
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
...@@ -8532,7 +8507,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8532,7 +8507,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBufferStr(q, "\n);\n"); appendPQExpBufferStr(q, "\n);\n");
if (binary_upgrade) if (dopt->binary_upgrade)
{ {
/* Labels with dump-assigned (preserved) oids */ /* Labels with dump-assigned (preserved) oids */
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
...@@ -8556,7 +8531,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8556,7 +8531,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
...@@ -8570,14 +8545,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8570,14 +8545,14 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
NULL, NULL); NULL, NULL);
/* Dump Type Comments and Security Labels */ /* Dump Type Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", dumpACL(fout, dopt, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name, qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name, tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl); tyinfo->rolname, tyinfo->typacl);
...@@ -8594,7 +8569,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8594,7 +8569,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
* writes out to fout the queries to recreate a user-defined range type * writes out to fout the queries to recreate a user-defined range type
*/ */
static void static void
dumpRangeType(Archive *fout, TypeInfo *tyinfo) dumpRangeType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -8640,7 +8615,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8640,7 +8615,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
qtypname); qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, binary_upgrade_set_type_oids_by_type_oid(fout,
q, tyinfo->dobj.catId.oid); q, tyinfo->dobj.catId.oid);
...@@ -8688,7 +8663,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8688,7 +8663,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
...@@ -8702,14 +8677,14 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8702,14 +8677,14 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
NULL, NULL); NULL, NULL);
/* Dump Type Comments and Security Labels */ /* Dump Type Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", dumpACL(fout, dopt, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name, qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name, tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl); tyinfo->rolname, tyinfo->typacl);
...@@ -8726,7 +8701,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8726,7 +8701,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
* writes out to fout the queries to recreate a user-defined base type * writes out to fout the queries to recreate a user-defined base type
*/ */
static void static void
dumpBaseType(Archive *fout, TypeInfo *tyinfo) dumpBaseType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -8980,7 +8955,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8980,7 +8955,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
qtypname); qtypname);
/* We might already have a shell type, but setting pg_type_oid is harmless */ /* We might already have a shell type, but setting pg_type_oid is harmless */
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
...@@ -9078,7 +9053,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -9078,7 +9053,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
...@@ -9092,14 +9067,14 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -9092,14 +9067,14 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
NULL, NULL); NULL, NULL);
/* Dump Type Comments and Security Labels */ /* Dump Type Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", dumpACL(fout, dopt, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name, qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name, tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl); tyinfo->rolname, tyinfo->typacl);
...@@ -9116,7 +9091,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -9116,7 +9091,7 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
* writes out to fout the queries to recreate a user-defined domain * writes out to fout the queries to recreate a user-defined domain
*/ */
static void static void
dumpDomain(Archive *fout, TypeInfo *tyinfo) dumpDomain(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -9176,7 +9151,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -9176,7 +9151,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
typdefault = NULL; typdefault = NULL;
typcollation = atooid(PQgetvalue(res, 0, PQfnumber(res, "typcollation"))); typcollation = atooid(PQgetvalue(res, 0, PQfnumber(res, "typcollation")));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
tyinfo->dobj.catId.oid); tyinfo->dobj.catId.oid);
...@@ -9240,7 +9215,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -9240,7 +9215,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(labelq, "DOMAIN %s", qtypname); appendPQExpBuffer(labelq, "DOMAIN %s", qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
...@@ -9254,14 +9229,14 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -9254,14 +9229,14 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
NULL, NULL); NULL, NULL);
/* Dump Domain Comments and Security Labels */ /* Dump Domain Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", dumpACL(fout, dopt, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name, qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name, tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl); tyinfo->rolname, tyinfo->typacl);
...@@ -9278,7 +9253,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -9278,7 +9253,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
* composite type * composite type
*/ */
static void static void
dumpCompositeType(Archive *fout, TypeInfo *tyinfo) dumpCompositeType(Archive *fout, DumpOptions *dopt, TypeInfo *tyinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer dropped = createPQExpBuffer(); PQExpBuffer dropped = createPQExpBuffer();
...@@ -9355,7 +9330,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9355,7 +9330,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
i_attcollation = PQfnumber(res, "attcollation"); i_attcollation = PQfnumber(res, "attcollation");
i_typrelid = PQfnumber(res, "typrelid"); i_typrelid = PQfnumber(res, "typrelid");
if (binary_upgrade) if (dopt->binary_upgrade)
{ {
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid)); Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
...@@ -9386,7 +9361,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9386,7 +9361,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't'); attisdropped = (PQgetvalue(res, i, i_attisdropped)[0] == 't');
attcollation = atooid(PQgetvalue(res, i, i_attcollation)); attcollation = atooid(PQgetvalue(res, i, i_attcollation));
if (attisdropped && !binary_upgrade) if (attisdropped && !dopt->binary_upgrade)
continue; continue;
/* Format properly if not first attr */ /* Format properly if not first attr */
...@@ -9454,7 +9429,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9454,7 +9429,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tyinfo->dobj, labelq->data);
ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, ArchiveEntry(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId,
...@@ -9469,14 +9444,14 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9469,14 +9444,14 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
/* Dump Type Comments and Security Labels */ /* Dump Type Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tyinfo->dobj.namespace->dobj.name, tyinfo->rolname, tyinfo->dobj.namespace->dobj.name, tyinfo->rolname,
tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId); tyinfo->dobj.catId, 0, tyinfo->dobj.dumpId);
dumpACL(fout, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE", dumpACL(fout, dopt, tyinfo->dobj.catId, tyinfo->dobj.dumpId, "TYPE",
qtypname, NULL, tyinfo->dobj.name, qtypname, NULL, tyinfo->dobj.name,
tyinfo->dobj.namespace->dobj.name, tyinfo->dobj.namespace->dobj.name,
tyinfo->rolname, tyinfo->typacl); tyinfo->rolname, tyinfo->typacl);
...@@ -9607,12 +9582,12 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo) ...@@ -9607,12 +9582,12 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
* We dump a shell definition in advance of the I/O functions for the type. * We dump a shell definition in advance of the I/O functions for the type.
*/ */
static void static void
dumpShellType(Archive *fout, ShellTypeInfo *stinfo) dumpShellType(Archive *fout, DumpOptions *dopt, ShellTypeInfo *stinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!stinfo->dobj.dump || dataOnly) if (!stinfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -9626,7 +9601,7 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo) ...@@ -9626,7 +9601,7 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo)
* after it's filled in, otherwise the backend complains. * after it's filled in, otherwise the backend complains.
*/ */
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_type_oid(fout, q, binary_upgrade_set_type_oids_by_type_oid(fout, q,
stinfo->baseType->dobj.catId.oid); stinfo->baseType->dobj.catId.oid);
...@@ -9662,12 +9637,12 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo) ...@@ -9662,12 +9637,12 @@ dumpShellType(Archive *fout, ShellTypeInfo *stinfo)
* That case isn't checked here either. * That case isn't checked here either.
*/ */
static bool static bool
shouldDumpProcLangs(void) shouldDumpProcLangs(DumpOptions *dopt)
{ {
if (!include_everything) if (!dopt->include_everything)
return false; return false;
/* And they're schema not data */ /* And they're schema not data */
if (dataOnly) if (dopt->dataOnly)
return false; return false;
return true; return true;
} }
...@@ -9678,7 +9653,7 @@ shouldDumpProcLangs(void) ...@@ -9678,7 +9653,7 @@ shouldDumpProcLangs(void)
* procedural language * procedural language
*/ */
static void static void
dumpProcLang(Archive *fout, ProcLangInfo *plang) dumpProcLang(Archive *fout, DumpOptions *dopt, ProcLangInfo *plang)
{ {
PQExpBuffer defqry; PQExpBuffer defqry;
PQExpBuffer delqry; PQExpBuffer delqry;
...@@ -9691,7 +9666,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9691,7 +9666,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
FuncInfo *validatorInfo = NULL; FuncInfo *validatorInfo = NULL;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!plang->dobj.dump || dataOnly) if (!plang->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -9737,7 +9712,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9737,7 +9712,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
if (!plang->dobj.ext_member) if (!plang->dobj.ext_member)
{ {
if (!useParams && !shouldDumpProcLangs()) if (!useParams && !shouldDumpProcLangs(dopt))
return; return;
} }
...@@ -9804,7 +9779,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9804,7 +9779,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname); appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(defqry, &plang->dobj, labelq->data); binary_upgrade_extension_member(defqry, &plang->dobj, labelq->data);
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId, ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
...@@ -9816,15 +9791,15 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9816,15 +9791,15 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
NULL, NULL); NULL, NULL);
/* Dump Proc Lang Comments and Security Labels */ /* Dump Proc Lang Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, "", NULL, "",
plang->dobj.catId, 0, plang->dobj.dumpId); plang->dobj.catId, 0, plang->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
NULL, "", NULL, "",
plang->dobj.catId, 0, plang->dobj.dumpId); plang->dobj.catId, 0, plang->dobj.dumpId);
if (plang->lanpltrusted) if (plang->lanpltrusted)
dumpACL(fout, plang->dobj.catId, plang->dobj.dumpId, "LANGUAGE", dumpACL(fout, dopt, plang->dobj.catId, plang->dobj.dumpId, "LANGUAGE",
qlanname, NULL, plang->dobj.name, qlanname, NULL, plang->dobj.name,
lanschema, lanschema,
plang->lanowner, plang->lanacl); plang->lanowner, plang->lanacl);
...@@ -9971,7 +9946,7 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes) ...@@ -9971,7 +9946,7 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
* dump out one function * dump out one function
*/ */
static void static void
dumpFunc(Archive *fout, FuncInfo *finfo) dumpFunc(Archive *fout, DumpOptions *dopt, FuncInfo *finfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -10010,7 +9985,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10010,7 +9985,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
int i; int i;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!finfo->dobj.dump || dataOnly) if (!finfo->dobj.dump || dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -10203,7 +10178,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10203,7 +10178,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
* where we have bin, use dollar quoting if allowed and src * where we have bin, use dollar quoting if allowed and src
* contains quote or backslash; else use regular quoting. * contains quote or backslash; else use regular quoting.
*/ */
if (disable_dollar_quoting || if (dopt->disable_dollar_quoting ||
(strchr(prosrc, '\'') == NULL && strchr(prosrc, '\\') == NULL)) (strchr(prosrc, '\'') == NULL && strchr(prosrc, '\\') == NULL))
appendStringLiteralAH(asPart, prosrc, fout); appendStringLiteralAH(asPart, prosrc, fout);
else else
...@@ -10216,7 +10191,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10216,7 +10191,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
{ {
appendPQExpBufferStr(asPart, "AS "); appendPQExpBufferStr(asPart, "AS ");
/* with no bin, dollar quote src unconditionally if allowed */ /* with no bin, dollar quote src unconditionally if allowed */
if (disable_dollar_quoting) if (dopt->disable_dollar_quoting)
appendStringLiteralAH(asPart, prosrc, fout); appendStringLiteralAH(asPart, prosrc, fout);
else else
appendStringLiteralDQ(asPart, prosrc, NULL); appendStringLiteralDQ(asPart, prosrc, NULL);
...@@ -10392,7 +10367,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10392,7 +10367,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
appendPQExpBuffer(labelq, "FUNCTION %s", funcsig); appendPQExpBuffer(labelq, "FUNCTION %s", funcsig);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &finfo->dobj, labelq->data); binary_upgrade_extension_member(q, &finfo->dobj, labelq->data);
ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId, ArchiveEntry(fout, finfo->dobj.catId, finfo->dobj.dumpId,
...@@ -10406,14 +10381,14 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10406,14 +10381,14 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
NULL, NULL); NULL, NULL);
/* Dump Function Comments and Security Labels */ /* Dump Function Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
finfo->dobj.namespace->dobj.name, finfo->rolname, finfo->dobj.namespace->dobj.name, finfo->rolname,
finfo->dobj.catId, 0, finfo->dobj.dumpId); finfo->dobj.catId, 0, finfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
finfo->dobj.namespace->dobj.name, finfo->rolname, finfo->dobj.namespace->dobj.name, finfo->rolname,
finfo->dobj.catId, 0, finfo->dobj.dumpId); finfo->dobj.catId, 0, finfo->dobj.dumpId);
dumpACL(fout, finfo->dobj.catId, finfo->dobj.dumpId, "FUNCTION", dumpACL(fout, dopt, finfo->dobj.catId, finfo->dobj.dumpId, "FUNCTION",
funcsig, NULL, funcsig_tag, funcsig, NULL, funcsig_tag,
finfo->dobj.namespace->dobj.name, finfo->dobj.namespace->dobj.name,
finfo->rolname, finfo->proacl); finfo->rolname, finfo->proacl);
...@@ -10444,7 +10419,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10444,7 +10419,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
* Dump a user-defined cast * Dump a user-defined cast
*/ */
static void static void
dumpCast(Archive *fout, CastInfo *cast) dumpCast(Archive *fout, DumpOptions *dopt, CastInfo *cast)
{ {
PQExpBuffer defqry; PQExpBuffer defqry;
PQExpBuffer delqry; PQExpBuffer delqry;
...@@ -10452,7 +10427,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10452,7 +10427,7 @@ dumpCast(Archive *fout, CastInfo *cast)
FuncInfo *funcInfo = NULL; FuncInfo *funcInfo = NULL;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!cast->dobj.dump || dataOnly) if (!cast->dobj.dump || dopt->dataOnly)
return; return;
/* Cannot dump if we don't have the cast function's info */ /* Cannot dump if we don't have the cast function's info */
...@@ -10566,7 +10541,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10566,7 +10541,7 @@ dumpCast(Archive *fout, CastInfo *cast)
getFormattedTypeName(fout, cast->castsource, zeroAsNone), getFormattedTypeName(fout, cast->castsource, zeroAsNone),
getFormattedTypeName(fout, cast->casttarget, zeroAsNone)); getFormattedTypeName(fout, cast->casttarget, zeroAsNone));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data); binary_upgrade_extension_member(defqry, &cast->dobj, labelq->data);
ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId, ArchiveEntry(fout, cast->dobj.catId, cast->dobj.dumpId,
...@@ -10578,7 +10553,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10578,7 +10553,7 @@ dumpCast(Archive *fout, CastInfo *cast)
NULL, NULL); NULL, NULL);
/* Dump Cast Comments */ /* Dump Cast Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, "", NULL, "",
cast->dobj.catId, 0, cast->dobj.dumpId); cast->dobj.catId, 0, cast->dobj.dumpId);
...@@ -10592,7 +10567,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10592,7 +10567,7 @@ dumpCast(Archive *fout, CastInfo *cast)
* write out a single operator definition * write out a single operator definition
*/ */
static void static void
dumpOpr(Archive *fout, OprInfo *oprinfo) dumpOpr(Archive *fout, DumpOptions *dopt, OprInfo *oprinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -10626,7 +10601,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10626,7 +10601,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
char *oprref; char *oprref;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!oprinfo->dobj.dump || dataOnly) if (!oprinfo->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -10816,7 +10791,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10816,7 +10791,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
appendPQExpBuffer(labelq, "OPERATOR %s", oprid->data); appendPQExpBuffer(labelq, "OPERATOR %s", oprid->data);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &oprinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &oprinfo->dobj, labelq->data);
ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId, ArchiveEntry(fout, oprinfo->dobj.catId, oprinfo->dobj.dumpId,
...@@ -10830,7 +10805,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10830,7 +10805,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
NULL, NULL); NULL, NULL);
/* Dump Operator Comments */ /* Dump Operator Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
oprinfo->dobj.namespace->dobj.name, oprinfo->rolname, oprinfo->dobj.namespace->dobj.name, oprinfo->rolname,
oprinfo->dobj.catId, 0, oprinfo->dobj.dumpId); oprinfo->dobj.catId, 0, oprinfo->dobj.dumpId);
...@@ -10980,7 +10955,7 @@ convertTSFunction(Archive *fout, Oid funcOid) ...@@ -10980,7 +10955,7 @@ convertTSFunction(Archive *fout, Oid funcOid)
* write out a single operator class definition * write out a single operator class definition
*/ */
static void static void
dumpOpclass(Archive *fout, OpclassInfo *opcinfo) dumpOpclass(Archive *fout, DumpOptions *dopt, OpclassInfo *opcinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -11024,7 +10999,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -11024,7 +10999,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
int i; int i;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!opcinfo->dobj.dump || dataOnly) if (!opcinfo->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -11324,7 +11299,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -11324,7 +11299,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
appendPQExpBuffer(labelq, " USING %s", appendPQExpBuffer(labelq, " USING %s",
fmtId(amname)); fmtId(amname));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &opcinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &opcinfo->dobj, labelq->data);
ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId, ArchiveEntry(fout, opcinfo->dobj.catId, opcinfo->dobj.dumpId,
...@@ -11338,7 +11313,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -11338,7 +11313,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
NULL, NULL); NULL, NULL);
/* Dump Operator Class Comments */ /* Dump Operator Class Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, opcinfo->rolname, NULL, opcinfo->rolname,
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId); opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
...@@ -11357,7 +11332,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -11357,7 +11332,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
* specific opclass within the opfamily. * specific opclass within the opfamily.
*/ */
static void static void
dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) dumpOpfamily(Archive *fout, DumpOptions *dopt, OpfamilyInfo *opfinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -11391,7 +11366,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11391,7 +11366,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
int i; int i;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!opfinfo->dobj.dump || dataOnly) if (!opfinfo->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -11637,7 +11612,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11637,7 +11612,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
appendPQExpBuffer(labelq, " USING %s", appendPQExpBuffer(labelq, " USING %s",
fmtId(amname)); fmtId(amname));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &opfinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &opfinfo->dobj, labelq->data);
ArchiveEntry(fout, opfinfo->dobj.catId, opfinfo->dobj.dumpId, ArchiveEntry(fout, opfinfo->dobj.catId, opfinfo->dobj.dumpId,
...@@ -11651,7 +11626,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11651,7 +11626,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
NULL, NULL); NULL, NULL);
/* Dump Operator Family Comments */ /* Dump Operator Family Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, opfinfo->rolname, NULL, opfinfo->rolname,
opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId); opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
...@@ -11669,7 +11644,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11669,7 +11644,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
* write out a single collation definition * write out a single collation definition
*/ */
static void static void
dumpCollation(Archive *fout, CollInfo *collinfo) dumpCollation(Archive *fout, DumpOptions *dopt, CollInfo *collinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -11682,7 +11657,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -11682,7 +11657,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
const char *collctype; const char *collctype;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!collinfo->dobj.dump || dataOnly) if (!collinfo->dobj.dump || dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -11726,7 +11701,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -11726,7 +11701,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name)); appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &collinfo->dobj, labelq->data);
ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId, ArchiveEntry(fout, collinfo->dobj.catId, collinfo->dobj.dumpId,
...@@ -11740,7 +11715,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -11740,7 +11715,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
NULL, NULL); NULL, NULL);
/* Dump Collation Comments */ /* Dump Collation Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
collinfo->dobj.namespace->dobj.name, collinfo->rolname, collinfo->dobj.namespace->dobj.name, collinfo->rolname,
collinfo->dobj.catId, 0, collinfo->dobj.dumpId); collinfo->dobj.catId, 0, collinfo->dobj.dumpId);
...@@ -11757,7 +11732,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -11757,7 +11732,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
* write out a single conversion definition * write out a single conversion definition
*/ */
static void static void
dumpConversion(Archive *fout, ConvInfo *convinfo) dumpConversion(Archive *fout, DumpOptions *dopt, ConvInfo *convinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -11774,7 +11749,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -11774,7 +11749,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
bool condefault; bool condefault;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!convinfo->dobj.dump || dataOnly) if (!convinfo->dobj.dump || dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -11825,7 +11800,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -11825,7 +11800,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name)); appendPQExpBuffer(labelq, "CONVERSION %s", fmtId(convinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &convinfo->dobj, labelq->data);
ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId, ArchiveEntry(fout, convinfo->dobj.catId, convinfo->dobj.dumpId,
...@@ -11839,7 +11814,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -11839,7 +11814,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
NULL, NULL); NULL, NULL);
/* Dump Conversion Comments */ /* Dump Conversion Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
convinfo->dobj.namespace->dobj.name, convinfo->rolname, convinfo->dobj.namespace->dobj.name, convinfo->rolname,
convinfo->dobj.catId, 0, convinfo->dobj.dumpId); convinfo->dobj.catId, 0, convinfo->dobj.dumpId);
...@@ -11896,7 +11871,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -11896,7 +11871,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
* write out a single aggregate definition * write out a single aggregate definition
*/ */
static void static void
dumpAgg(Archive *fout, AggInfo *agginfo) dumpAgg(Archive *fout, DumpOptions *dopt, AggInfo *agginfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer q; PQExpBuffer q;
...@@ -11942,7 +11917,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11942,7 +11917,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
bool convertok; bool convertok;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!agginfo->aggfn.dobj.dump || dataOnly) if (!agginfo->aggfn.dobj.dump || dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -12221,7 +12196,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -12221,7 +12196,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig); appendPQExpBuffer(labelq, "AGGREGATE %s", aggsig);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data); binary_upgrade_extension_member(q, &agginfo->aggfn.dobj, labelq->data);
ArchiveEntry(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId, ArchiveEntry(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
...@@ -12235,10 +12210,10 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -12235,10 +12210,10 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
NULL, NULL); NULL, NULL);
/* Dump Aggregate Comments */ /* Dump Aggregate Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname, agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname,
agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId); agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname, agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.rolname,
agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId); agginfo->aggfn.dobj.catId, 0, agginfo->aggfn.dobj.dumpId);
...@@ -12253,7 +12228,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -12253,7 +12228,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
aggsig = format_function_signature(fout, &agginfo->aggfn, true); aggsig = format_function_signature(fout, &agginfo->aggfn, true);
aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false); aggsig_tag = format_function_signature(fout, &agginfo->aggfn, false);
dumpACL(fout, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId, dumpACL(fout, dopt, agginfo->aggfn.dobj.catId, agginfo->aggfn.dobj.dumpId,
"FUNCTION", "FUNCTION",
aggsig, NULL, aggsig_tag, aggsig, NULL, aggsig_tag,
agginfo->aggfn.dobj.namespace->dobj.name, agginfo->aggfn.dobj.namespace->dobj.name,
...@@ -12278,14 +12253,14 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -12278,14 +12253,14 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
* write out a single text search parser * write out a single text search parser
*/ */
static void static void
dumpTSParser(Archive *fout, TSParserInfo *prsinfo) dumpTSParser(Archive *fout, DumpOptions *dopt, TSParserInfo *prsinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
PQExpBuffer labelq; PQExpBuffer labelq;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!prsinfo->dobj.dump || dataOnly) if (!prsinfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12321,7 +12296,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) ...@@ -12321,7 +12296,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
appendPQExpBuffer(labelq, "TEXT SEARCH PARSER %s", appendPQExpBuffer(labelq, "TEXT SEARCH PARSER %s",
fmtId(prsinfo->dobj.name)); fmtId(prsinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &prsinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &prsinfo->dobj, labelq->data);
ArchiveEntry(fout, prsinfo->dobj.catId, prsinfo->dobj.dumpId, ArchiveEntry(fout, prsinfo->dobj.catId, prsinfo->dobj.dumpId,
...@@ -12335,7 +12310,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) ...@@ -12335,7 +12310,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
NULL, NULL); NULL, NULL);
/* Dump Parser Comments */ /* Dump Parser Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, "", NULL, "",
prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId); prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
...@@ -12349,7 +12324,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) ...@@ -12349,7 +12324,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
* write out a single text search dictionary * write out a single text search dictionary
*/ */
static void static void
dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) dumpTSDictionary(Archive *fout, DumpOptions *dopt, TSDictInfo *dictinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -12360,7 +12335,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -12360,7 +12335,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
char *tmplname; char *tmplname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!dictinfo->dobj.dump || dataOnly) if (!dictinfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12408,7 +12383,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -12408,7 +12383,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
appendPQExpBuffer(labelq, "TEXT SEARCH DICTIONARY %s", appendPQExpBuffer(labelq, "TEXT SEARCH DICTIONARY %s",
fmtId(dictinfo->dobj.name)); fmtId(dictinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &dictinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &dictinfo->dobj, labelq->data);
ArchiveEntry(fout, dictinfo->dobj.catId, dictinfo->dobj.dumpId, ArchiveEntry(fout, dictinfo->dobj.catId, dictinfo->dobj.dumpId,
...@@ -12422,7 +12397,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -12422,7 +12397,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
NULL, NULL); NULL, NULL);
/* Dump Dictionary Comments */ /* Dump Dictionary Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, dictinfo->rolname, NULL, dictinfo->rolname,
dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId); dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
...@@ -12437,14 +12412,14 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -12437,14 +12412,14 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
* write out a single text search template * write out a single text search template
*/ */
static void static void
dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) dumpTSTemplate(Archive *fout, DumpOptions *dopt, TSTemplateInfo *tmplinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
PQExpBuffer labelq; PQExpBuffer labelq;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!tmplinfo->dobj.dump || dataOnly) if (!tmplinfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12474,7 +12449,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) ...@@ -12474,7 +12449,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
appendPQExpBuffer(labelq, "TEXT SEARCH TEMPLATE %s", appendPQExpBuffer(labelq, "TEXT SEARCH TEMPLATE %s",
fmtId(tmplinfo->dobj.name)); fmtId(tmplinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tmplinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tmplinfo->dobj, labelq->data);
ArchiveEntry(fout, tmplinfo->dobj.catId, tmplinfo->dobj.dumpId, ArchiveEntry(fout, tmplinfo->dobj.catId, tmplinfo->dobj.dumpId,
...@@ -12488,7 +12463,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) ...@@ -12488,7 +12463,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
NULL, NULL); NULL, NULL);
/* Dump Template Comments */ /* Dump Template Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, "", NULL, "",
tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId); tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
...@@ -12502,7 +12477,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) ...@@ -12502,7 +12477,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
* write out a single text search configuration * write out a single text search configuration
*/ */
static void static void
dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) dumpTSConfig(Archive *fout, DumpOptions *dopt, TSConfigInfo *cfginfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -12517,7 +12492,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12517,7 +12492,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
int i_dictname; int i_dictname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!cfginfo->dobj.dump || dataOnly) if (!cfginfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12602,7 +12577,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12602,7 +12577,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
appendPQExpBuffer(labelq, "TEXT SEARCH CONFIGURATION %s", appendPQExpBuffer(labelq, "TEXT SEARCH CONFIGURATION %s",
fmtId(cfginfo->dobj.name)); fmtId(cfginfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &cfginfo->dobj, labelq->data); binary_upgrade_extension_member(q, &cfginfo->dobj, labelq->data);
ArchiveEntry(fout, cfginfo->dobj.catId, cfginfo->dobj.dumpId, ArchiveEntry(fout, cfginfo->dobj.catId, cfginfo->dobj.dumpId,
...@@ -12616,7 +12591,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12616,7 +12591,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
NULL, NULL); NULL, NULL);
/* Dump Configuration Comments */ /* Dump Configuration Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, cfginfo->rolname, NULL, cfginfo->rolname,
cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId); cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
...@@ -12631,7 +12606,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12631,7 +12606,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
* write out a single foreign-data wrapper definition * write out a single foreign-data wrapper definition
*/ */
static void static void
dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) dumpForeignDataWrapper(Archive *fout, DumpOptions *dopt, FdwInfo *fdwinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -12639,7 +12614,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12639,7 +12614,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
char *qfdwname; char *qfdwname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!fdwinfo->dobj.dump || dataOnly) if (!fdwinfo->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -12647,7 +12622,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12647,7 +12622,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
* field. Otherwise omit them if we are only dumping some specific object. * field. Otherwise omit them if we are only dumping some specific object.
*/ */
if (!fdwinfo->dobj.ext_member) if (!fdwinfo->dobj.ext_member)
if (!include_everything) if (!dopt->include_everything)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12676,7 +12651,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12676,7 +12651,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
appendPQExpBuffer(labelq, "FOREIGN DATA WRAPPER %s", appendPQExpBuffer(labelq, "FOREIGN DATA WRAPPER %s",
qfdwname); qfdwname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &fdwinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &fdwinfo->dobj, labelq->data);
ArchiveEntry(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId, ArchiveEntry(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
...@@ -12690,14 +12665,14 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12690,14 +12665,14 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
NULL, NULL); NULL, NULL);
/* Handle the ACL */ /* Handle the ACL */
dumpACL(fout, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId, dumpACL(fout, dopt, fdwinfo->dobj.catId, fdwinfo->dobj.dumpId,
"FOREIGN DATA WRAPPER", "FOREIGN DATA WRAPPER",
qfdwname, NULL, fdwinfo->dobj.name, qfdwname, NULL, fdwinfo->dobj.name,
NULL, fdwinfo->rolname, NULL, fdwinfo->rolname,
fdwinfo->fdwacl); fdwinfo->fdwacl);
/* Dump Foreign Data Wrapper Comments */ /* Dump Foreign Data Wrapper Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, fdwinfo->rolname, NULL, fdwinfo->rolname,
fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId); fdwinfo->dobj.catId, 0, fdwinfo->dobj.dumpId);
...@@ -12713,7 +12688,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12713,7 +12688,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
* write out a foreign server definition * write out a foreign server definition
*/ */
static void static void
dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) dumpForeignServer(Archive *fout, DumpOptions *dopt, ForeignServerInfo *srvinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
...@@ -12724,7 +12699,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -12724,7 +12699,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
char *fdwname; char *fdwname;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!srvinfo->dobj.dump || dataOnly || !include_everything) if (!srvinfo->dobj.dump || dopt->dataOnly || !dopt->include_everything)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12768,7 +12743,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -12768,7 +12743,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
appendPQExpBuffer(labelq, "SERVER %s", qsrvname); appendPQExpBuffer(labelq, "SERVER %s", qsrvname);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &srvinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &srvinfo->dobj, labelq->data);
ArchiveEntry(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId, ArchiveEntry(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
...@@ -12782,7 +12757,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -12782,7 +12757,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
NULL, NULL); NULL, NULL);
/* Handle the ACL */ /* Handle the ACL */
dumpACL(fout, srvinfo->dobj.catId, srvinfo->dobj.dumpId, dumpACL(fout, dopt, srvinfo->dobj.catId, srvinfo->dobj.dumpId,
"FOREIGN SERVER", "FOREIGN SERVER",
qsrvname, NULL, srvinfo->dobj.name, qsrvname, NULL, srvinfo->dobj.name,
NULL, srvinfo->rolname, NULL, srvinfo->rolname,
...@@ -12795,7 +12770,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -12795,7 +12770,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
srvinfo->dobj.catId, srvinfo->dobj.dumpId); srvinfo->dobj.catId, srvinfo->dobj.dumpId);
/* Dump Foreign Server Comments */ /* Dump Foreign Server Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, srvinfo->rolname, NULL, srvinfo->rolname,
srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId); srvinfo->dobj.catId, 0, srvinfo->dobj.dumpId);
...@@ -12911,14 +12886,14 @@ dumpUserMappings(Archive *fout, ...@@ -12911,14 +12886,14 @@ dumpUserMappings(Archive *fout,
* Write out default privileges information * Write out default privileges information
*/ */
static void static void
dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) dumpDefaultACL(Archive *fout, DumpOptions *dopt, DefaultACLInfo *daclinfo)
{ {
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer tag; PQExpBuffer tag;
const char *type; const char *type;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!daclinfo->dobj.dump || dataOnly || aclsSkip) if (!daclinfo->dobj.dump || dopt->dataOnly || dopt->aclsSkip)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -12991,7 +12966,7 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo) ...@@ -12991,7 +12966,7 @@ dumpDefaultACL(Archive *fout, DefaultACLInfo *daclinfo)
*---------- *----------
*/ */
static void static void
dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, dumpACL(Archive *fout, DumpOptions *dopt, CatalogId objCatId, DumpId objDumpId,
const char *type, const char *name, const char *subname, const char *type, const char *name, const char *subname,
const char *tag, const char *nspname, const char *owner, const char *tag, const char *nspname, const char *owner,
const char *acls) const char *acls)
...@@ -12999,11 +12974,11 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, ...@@ -12999,11 +12974,11 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
PQExpBuffer sql; PQExpBuffer sql;
/* Do nothing if ACL dump is not enabled */ /* Do nothing if ACL dump is not enabled */
if (aclsSkip) if (dopt->aclsSkip)
return; return;
/* --data-only skips ACLs *except* BLOB ACLs */ /* --data-only skips ACLs *except* BLOB ACLs */
if (dataOnly && strcmp(type, "LARGE OBJECT") != 0) if (dopt->dataOnly && strcmp(type, "LARGE OBJECT") != 0)
return; return;
sql = createPQExpBuffer(); sql = createPQExpBuffer();
...@@ -13046,7 +13021,7 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId, ...@@ -13046,7 +13021,7 @@ dumpACL(Archive *fout, CatalogId objCatId, DumpId objDumpId,
* calling ArchiveEntry() for the specified object. * calling ArchiveEntry() for the specified object.
*/ */
static void static void
dumpSecLabel(Archive *fout, const char *target, dumpSecLabel(Archive *fout, DumpOptions *dopt, const char *target,
const char *namespace, const char *owner, const char *namespace, const char *owner,
CatalogId catalogId, int subid, DumpId dumpId) CatalogId catalogId, int subid, DumpId dumpId)
{ {
...@@ -13056,18 +13031,18 @@ dumpSecLabel(Archive *fout, const char *target, ...@@ -13056,18 +13031,18 @@ dumpSecLabel(Archive *fout, const char *target,
PQExpBuffer query; PQExpBuffer query;
/* do nothing, if --no-security-labels is supplied */ /* do nothing, if --no-security-labels is supplied */
if (no_security_labels) if (dopt->no_security_labels)
return; return;
/* Comments are schema not data ... except blob comments are data */ /* Comments are schema not data ... except blob comments are data */
if (strncmp(target, "LARGE OBJECT ", 13) != 0) if (strncmp(target, "LARGE OBJECT ", 13) != 0)
{ {
if (dataOnly) if (dopt->dataOnly)
return; return;
} }
else else
{ {
if (schemaOnly) if (dopt->schemaOnly)
return; return;
} }
...@@ -13110,7 +13085,7 @@ dumpSecLabel(Archive *fout, const char *target, ...@@ -13110,7 +13085,7 @@ dumpSecLabel(Archive *fout, const char *target,
* and its columns. * and its columns.
*/ */
static void static void
dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename) dumpTableSecLabel(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo, const char *reltypename)
{ {
SecLabelItem *labels; SecLabelItem *labels;
int nlabels; int nlabels;
...@@ -13119,11 +13094,11 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename) ...@@ -13119,11 +13094,11 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
PQExpBuffer target; PQExpBuffer target;
/* do nothing, if --no-security-labels is supplied */ /* do nothing, if --no-security-labels is supplied */
if (no_security_labels) if (dopt->no_security_labels)
return; return;
/* SecLabel are SCHEMA not data */ /* SecLabel are SCHEMA not data */
if (dataOnly) if (dopt->dataOnly)
return; return;
/* Search for comments associated with relation, using table */ /* Search for comments associated with relation, using table */
...@@ -13331,20 +13306,20 @@ collectSecLabels(Archive *fout, SecLabelItem **items) ...@@ -13331,20 +13306,20 @@ collectSecLabels(Archive *fout, SecLabelItem **items)
* write out to fout the declarations (not data) of a user-defined table * write out to fout the declarations (not data) of a user-defined table
*/ */
static void static void
dumpTable(Archive *fout, TableInfo *tbinfo) dumpTable(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo)
{ {
if (tbinfo->dobj.dump && !dataOnly) if (tbinfo->dobj.dump && !dopt->dataOnly)
{ {
char *namecopy; char *namecopy;
if (tbinfo->relkind == RELKIND_SEQUENCE) if (tbinfo->relkind == RELKIND_SEQUENCE)
dumpSequence(fout, tbinfo); dumpSequence(fout, dopt, tbinfo);
else else
dumpTableSchema(fout, tbinfo); dumpTableSchema(fout, dopt, tbinfo);
/* Handle the ACL here */ /* Handle the ACL here */
namecopy = pg_strdup(fmtId(tbinfo->dobj.name)); namecopy = pg_strdup(fmtId(tbinfo->dobj.name));
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, dumpACL(fout, dopt, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
(tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" : (tbinfo->relkind == RELKIND_SEQUENCE) ? "SEQUENCE" :
"TABLE", "TABLE",
namecopy, NULL, tbinfo->dobj.name, namecopy, NULL, tbinfo->dobj.name,
...@@ -13379,7 +13354,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo) ...@@ -13379,7 +13354,7 @@ dumpTable(Archive *fout, TableInfo *tbinfo)
attnamecopy = pg_strdup(fmtId(attname)); attnamecopy = pg_strdup(fmtId(attname));
acltag = psprintf("%s.%s", tbinfo->dobj.name, attname); acltag = psprintf("%s.%s", tbinfo->dobj.name, attname);
/* Column's GRANT type is always TABLE */ /* Column's GRANT type is always TABLE */
dumpACL(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE", dumpACL(fout, dopt, tbinfo->dobj.catId, tbinfo->dobj.dumpId, "TABLE",
namecopy, attnamecopy, acltag, namecopy, attnamecopy, acltag,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
attacl); attacl);
...@@ -13456,7 +13431,7 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo) ...@@ -13456,7 +13431,7 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo)
* write the declaration (not data) of one user-defined table or view * write the declaration (not data) of one user-defined table or view
*/ */
static void static void
dumpTableSchema(Archive *fout, TableInfo *tbinfo) dumpTableSchema(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo)
{ {
PQExpBuffer q = createPQExpBuffer(); PQExpBuffer q = createPQExpBuffer();
PQExpBuffer delq = createPQExpBuffer(); PQExpBuffer delq = createPQExpBuffer();
...@@ -13474,7 +13449,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13474,7 +13449,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name); selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_type_oids_by_rel_oid(fout, q, binary_upgrade_set_type_oids_by_rel_oid(fout, q,
tbinfo->dobj.catId.oid); tbinfo->dobj.catId.oid);
...@@ -13494,7 +13469,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13494,7 +13469,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_pg_class_oids(fout, q, binary_upgrade_set_pg_class_oids(fout, q,
tbinfo->dobj.catId.oid, false); tbinfo->dobj.catId.oid, false);
...@@ -13574,7 +13549,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13574,7 +13549,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBuffer(labelq, "%s %s", reltypename, appendPQExpBuffer(labelq, "%s %s", reltypename,
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_pg_class_oids(fout, q, binary_upgrade_set_pg_class_oids(fout, q,
tbinfo->dobj.catId.oid, false); tbinfo->dobj.catId.oid, false);
...@@ -13588,7 +13563,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13588,7 +13563,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* Attach to type, if reloftype; except in case of a binary upgrade, * Attach to type, if reloftype; except in case of a binary upgrade,
* we dump the table normally and attach it to the type afterward. * we dump the table normally and attach it to the type afterward.
*/ */
if (tbinfo->reloftype && !binary_upgrade) if (tbinfo->reloftype && !dopt->binary_upgrade)
appendPQExpBuffer(q, " OF %s", tbinfo->reloftype); appendPQExpBuffer(q, " OF %s", tbinfo->reloftype);
if (tbinfo->relkind != RELKIND_MATVIEW) if (tbinfo->relkind != RELKIND_MATVIEW)
...@@ -13603,7 +13578,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13603,7 +13578,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* columns, and then fix up the dropped and nonlocal cases * columns, and then fix up the dropped and nonlocal cases
* below. * below.
*/ */
if (shouldPrintColumn(tbinfo, j)) if (shouldPrintColumn(dopt, tbinfo, j))
{ {
/* /*
* Default value --- suppress if to be printed separately. * Default value --- suppress if to be printed separately.
...@@ -13617,11 +13592,11 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13617,11 +13592,11 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
*/ */
bool has_notnull = (tbinfo->notnull[j] && bool has_notnull = (tbinfo->notnull[j] &&
(!tbinfo->inhNotNull[j] || (!tbinfo->inhNotNull[j] ||
binary_upgrade)); dopt->binary_upgrade));
/* Skip column if fully defined by reloftype */ /* Skip column if fully defined by reloftype */
if (tbinfo->reloftype && if (tbinfo->reloftype &&
!has_default && !has_notnull && !binary_upgrade) !has_default && !has_notnull && !dopt->binary_upgrade)
continue; continue;
/* Format properly if not first attr */ /* Format properly if not first attr */
...@@ -13649,7 +13624,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13649,7 +13624,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
} }
/* Attribute type */ /* Attribute type */
if (tbinfo->reloftype && !binary_upgrade) if (tbinfo->reloftype && !dopt->binary_upgrade)
{ {
appendPQExpBufferStr(q, " WITH OPTIONS"); appendPQExpBufferStr(q, " WITH OPTIONS");
} }
...@@ -13714,7 +13689,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13714,7 +13689,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (actual_atts) if (actual_atts)
appendPQExpBufferStr(q, "\n)"); appendPQExpBufferStr(q, "\n)");
else if (!(tbinfo->reloftype && !binary_upgrade)) else if (!(tbinfo->reloftype && !dopt->binary_upgrade))
{ {
/* /*
* We must have a parenthesized attribute list, even though * We must have a parenthesized attribute list, even though
...@@ -13723,7 +13698,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13723,7 +13698,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
appendPQExpBufferStr(q, " (\n)"); appendPQExpBufferStr(q, " (\n)");
} }
if (numParents > 0 && !binary_upgrade) if (numParents > 0 && !dopt->binary_upgrade)
{ {
appendPQExpBufferStr(q, "\nINHERITS ("); appendPQExpBufferStr(q, "\nINHERITS (");
for (k = 0; k < numParents; k++) for (k = 0; k < numParents; k++)
...@@ -13796,7 +13771,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13796,7 +13771,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* attislocal correctly, plus fix up any inherited CHECK constraints. * attislocal correctly, plus fix up any inherited CHECK constraints.
* Analogously, we set up typed tables using ALTER TABLE / OF here. * Analogously, we set up typed tables using ALTER TABLE / OF here.
*/ */
if (binary_upgrade && (tbinfo->relkind == RELKIND_RELATION || if (dopt->binary_upgrade && (tbinfo->relkind == RELKIND_RELATION ||
tbinfo->relkind == RELKIND_FOREIGN_TABLE)) tbinfo->relkind == RELKIND_FOREIGN_TABLE))
{ {
for (j = 0; j < tbinfo->numatts; j++) for (j = 0; j < tbinfo->numatts; j++)
...@@ -13912,7 +13887,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13912,7 +13887,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* REFRESH MATERIALIZED VIEW since it's possible that some underlying * REFRESH MATERIALIZED VIEW since it's possible that some underlying
* matview is not populated even though this matview is. * matview is not populated even though this matview is.
*/ */
if (binary_upgrade && tbinfo->relkind == RELKIND_MATVIEW && if (dopt->binary_upgrade && tbinfo->relkind == RELKIND_MATVIEW &&
tbinfo->relispopulated) tbinfo->relispopulated)
{ {
appendPQExpBufferStr(q, "\n-- For binary upgrade, mark materialized view as populated\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, mark materialized view as populated\n");
...@@ -13938,7 +13913,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13938,7 +13913,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* it is NOT NULL and did not inherit that property from a parent, * it is NOT NULL and did not inherit that property from a parent,
* we have to mark it separately. * we have to mark it separately.
*/ */
if (!shouldPrintColumn(tbinfo, j) && if (!shouldPrintColumn(dopt, tbinfo, j) &&
tbinfo->notnull[j] && !tbinfo->inhNotNull[j]) tbinfo->notnull[j] && !tbinfo->inhNotNull[j])
{ {
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
...@@ -14052,7 +14027,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -14052,7 +14027,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
} }
} }
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(q, &tbinfo->dobj, labelq->data); binary_upgrade_extension_member(q, &tbinfo->dobj, labelq->data);
ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId, ArchiveEntry(fout, tbinfo->dobj.catId, tbinfo->dobj.dumpId,
...@@ -14069,10 +14044,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -14069,10 +14044,10 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
/* Dump Table Comments */ /* Dump Table Comments */
dumpTableComment(fout, tbinfo, reltypename); dumpTableComment(fout, dopt, tbinfo, reltypename);
/* Dump Table Security Labels */ /* Dump Table Security Labels */
dumpTableSecLabel(fout, tbinfo, reltypename); dumpTableSecLabel(fout, dopt, tbinfo, reltypename);
/* Dump comments on inlined table constraints */ /* Dump comments on inlined table constraints */
for (j = 0; j < tbinfo->ncheck; j++) for (j = 0; j < tbinfo->ncheck; j++)
...@@ -14082,7 +14057,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -14082,7 +14057,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (constr->separate || !constr->conislocal) if (constr->separate || !constr->conislocal)
continue; continue;
dumpTableConstraintComment(fout, constr); dumpTableConstraintComment(fout, dopt, constr);
} }
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
...@@ -14094,7 +14069,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -14094,7 +14069,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* dumpAttrDef --- dump an attribute's default-value declaration * dumpAttrDef --- dump an attribute's default-value declaration
*/ */
static void static void
dumpAttrDef(Archive *fout, AttrDefInfo *adinfo) dumpAttrDef(Archive *fout, DumpOptions *dopt, AttrDefInfo *adinfo)
{ {
TableInfo *tbinfo = adinfo->adtable; TableInfo *tbinfo = adinfo->adtable;
int adnum = adinfo->adnum; int adnum = adinfo->adnum;
...@@ -14102,7 +14077,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo) ...@@ -14102,7 +14077,7 @@ dumpAttrDef(Archive *fout, AttrDefInfo *adinfo)
PQExpBuffer delq; PQExpBuffer delq;
/* Skip if table definition not to be dumped */ /* Skip if table definition not to be dumped */
if (!tbinfo->dobj.dump || dataOnly) if (!tbinfo->dobj.dump || dopt->dataOnly)
return; return;
/* Skip if not "separate"; it was dumped in the table's definition */ /* Skip if not "separate"; it was dumped in the table's definition */
...@@ -14181,7 +14156,7 @@ getAttrName(int attrnum, TableInfo *tblInfo) ...@@ -14181,7 +14156,7 @@ getAttrName(int attrnum, TableInfo *tblInfo)
* write out to fout a user-defined index * write out to fout a user-defined index
*/ */
static void static void
dumpIndex(Archive *fout, IndxInfo *indxinfo) dumpIndex(Archive *fout, DumpOptions *dopt, IndxInfo *indxinfo)
{ {
TableInfo *tbinfo = indxinfo->indextable; TableInfo *tbinfo = indxinfo->indextable;
bool is_constraint = (indxinfo->indexconstraint != 0); bool is_constraint = (indxinfo->indexconstraint != 0);
...@@ -14189,7 +14164,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) ...@@ -14189,7 +14164,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
PQExpBuffer delq; PQExpBuffer delq;
PQExpBuffer labelq; PQExpBuffer labelq;
if (dataOnly) if (dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -14208,7 +14183,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) ...@@ -14208,7 +14183,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
*/ */
if (!is_constraint) if (!is_constraint)
{ {
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_pg_class_oids(fout, q, binary_upgrade_set_pg_class_oids(fout, q,
indxinfo->dobj.catId.oid, true); indxinfo->dobj.catId.oid, true);
...@@ -14254,7 +14229,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) ...@@ -14254,7 +14229,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
} }
/* Dump Index Comments */ /* Dump Index Comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname, tbinfo->rolname,
indxinfo->dobj.catId, 0, indxinfo->dobj.catId, 0,
...@@ -14271,14 +14246,14 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo) ...@@ -14271,14 +14246,14 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
* write out to fout a user-defined constraint * write out to fout a user-defined constraint
*/ */
static void static void
dumpConstraint(Archive *fout, ConstraintInfo *coninfo) dumpConstraint(Archive *fout, DumpOptions *dopt, ConstraintInfo *coninfo)
{ {
TableInfo *tbinfo = coninfo->contable; TableInfo *tbinfo = coninfo->contable;
PQExpBuffer q; PQExpBuffer q;
PQExpBuffer delq; PQExpBuffer delq;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!coninfo->dobj.dump || dataOnly) if (!coninfo->dobj.dump || dopt->dataOnly)
return; return;
q = createPQExpBuffer(); q = createPQExpBuffer();
...@@ -14298,7 +14273,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -14298,7 +14273,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
exit_horribly(NULL, "missing index for constraint \"%s\"\n", exit_horribly(NULL, "missing index for constraint \"%s\"\n",
coninfo->dobj.name); coninfo->dobj.name);
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_set_pg_class_oids(fout, q, binary_upgrade_set_pg_class_oids(fout, q,
indxinfo->dobj.catId.oid, true); indxinfo->dobj.catId.oid, true);
...@@ -14488,7 +14463,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -14488,7 +14463,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
/* Dump Constraint Comments --- only works for table constraints */ /* Dump Constraint Comments --- only works for table constraints */
if (tbinfo && coninfo->separate) if (tbinfo && coninfo->separate)
dumpTableConstraintComment(fout, coninfo); dumpTableConstraintComment(fout, dopt, coninfo);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
destroyPQExpBuffer(delq); destroyPQExpBuffer(delq);
...@@ -14502,7 +14477,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -14502,7 +14477,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
* or as a separate ALTER command. * or as a separate ALTER command.
*/ */
static void static void
dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) dumpTableConstraintComment(Archive *fout, DumpOptions *dopt, ConstraintInfo *coninfo)
{ {
TableInfo *tbinfo = coninfo->contable; TableInfo *tbinfo = coninfo->contable;
PQExpBuffer labelq = createPQExpBuffer(); PQExpBuffer labelq = createPQExpBuffer();
...@@ -14511,7 +14486,7 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo) ...@@ -14511,7 +14486,7 @@ dumpTableConstraintComment(Archive *fout, ConstraintInfo *coninfo)
fmtId(coninfo->dobj.name)); fmtId(coninfo->dobj.name));
appendPQExpBuffer(labelq, "ON %s", appendPQExpBuffer(labelq, "ON %s",
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname, tbinfo->rolname,
coninfo->dobj.catId, 0, coninfo->dobj.catId, 0,
...@@ -14571,7 +14546,7 @@ findLastBuiltinOid_V70(Archive *fout) ...@@ -14571,7 +14546,7 @@ findLastBuiltinOid_V70(Archive *fout)
* write the declaration (not data) of one user-defined sequence * write the declaration (not data) of one user-defined sequence
*/ */
static void static void
dumpSequence(Archive *fout, TableInfo *tbinfo) dumpSequence(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo)
{ {
PGresult *res; PGresult *res;
char *startv, char *startv,
...@@ -14667,7 +14642,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) ...@@ -14667,7 +14642,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
resetPQExpBuffer(query); resetPQExpBuffer(query);
if (binary_upgrade) if (dopt->binary_upgrade)
{ {
binary_upgrade_set_pg_class_oids(fout, query, binary_upgrade_set_pg_class_oids(fout, query,
tbinfo->dobj.catId.oid, false); tbinfo->dobj.catId.oid, false);
...@@ -14704,7 +14679,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) ...@@ -14704,7 +14679,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
/* binary_upgrade: no need to clear TOAST table oid */ /* binary_upgrade: no need to clear TOAST table oid */
if (binary_upgrade) if (dopt->binary_upgrade)
binary_upgrade_extension_member(query, &tbinfo->dobj, binary_upgrade_extension_member(query, &tbinfo->dobj,
labelq->data); labelq->data);
...@@ -14757,10 +14732,10 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) ...@@ -14757,10 +14732,10 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
} }
/* Dump Sequence Comments and Security Labels */ /* Dump Sequence Comments and Security Labels */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId); tbinfo->dobj.catId, 0, tbinfo->dobj.dumpId);
...@@ -14831,7 +14806,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) ...@@ -14831,7 +14806,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo)
* write the declaration of one user-defined table trigger * write the declaration of one user-defined table trigger
*/ */
static void static void
dumpTrigger(Archive *fout, TriggerInfo *tginfo) dumpTrigger(Archive *fout, DumpOptions *dopt, TriggerInfo *tginfo)
{ {
TableInfo *tbinfo = tginfo->tgtable; TableInfo *tbinfo = tginfo->tgtable;
PQExpBuffer query; PQExpBuffer query;
...@@ -14846,7 +14821,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14846,7 +14821,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
* we needn't check dobj.dump because TriggerInfo wouldn't have been * we needn't check dobj.dump because TriggerInfo wouldn't have been
* created in the first place for non-dumpable triggers * created in the first place for non-dumpable triggers
*/ */
if (dataOnly) if (dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -15027,7 +15002,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -15027,7 +15002,7 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
NULL, 0, NULL, 0,
NULL, NULL); NULL, NULL);
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->rolname, tbinfo->dobj.namespace->dobj.name, tbinfo->rolname,
tginfo->dobj.catId, 0, tginfo->dobj.dumpId); tginfo->dobj.catId, 0, tginfo->dobj.dumpId);
...@@ -15041,13 +15016,13 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -15041,13 +15016,13 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
* write the declaration of one user-defined event trigger * write the declaration of one user-defined event trigger
*/ */
static void static void
dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) dumpEventTrigger(Archive *fout, DumpOptions *dopt, EventTriggerInfo *evtinfo)
{ {
PQExpBuffer query; PQExpBuffer query;
PQExpBuffer labelq; PQExpBuffer labelq;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!evtinfo->dobj.dump || dataOnly) if (!evtinfo->dobj.dump || dopt->dataOnly)
return; return;
query = createPQExpBuffer(); query = createPQExpBuffer();
...@@ -15099,7 +15074,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -15099,7 +15074,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
"EVENT TRIGGER", SECTION_POST_DATA, "EVENT TRIGGER", SECTION_POST_DATA,
query->data, "", NULL, NULL, 0, NULL, NULL); query->data, "", NULL, NULL, 0, NULL, NULL);
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
NULL, NULL, NULL, NULL,
evtinfo->dobj.catId, 0, evtinfo->dobj.dumpId); evtinfo->dobj.catId, 0, evtinfo->dobj.dumpId);
...@@ -15112,7 +15087,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -15112,7 +15087,7 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
* Dump a rule * Dump a rule
*/ */
static void static void
dumpRule(Archive *fout, RuleInfo *rinfo) dumpRule(Archive *fout, DumpOptions *dopt, RuleInfo *rinfo)
{ {
TableInfo *tbinfo = rinfo->ruletable; TableInfo *tbinfo = rinfo->ruletable;
PQExpBuffer query; PQExpBuffer query;
...@@ -15122,7 +15097,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -15122,7 +15097,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
PGresult *res; PGresult *res;
/* Skip if not to be dumped */ /* Skip if not to be dumped */
if (!rinfo->dobj.dump || dataOnly) if (!rinfo->dobj.dump || dopt->dataOnly)
return; return;
/* /*
...@@ -15227,7 +15202,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -15227,7 +15202,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
NULL, NULL); NULL, NULL);
/* Dump rule comments */ /* Dump rule comments */
dumpComment(fout, labelq->data, dumpComment(fout, dopt, labelq->data,
tbinfo->dobj.namespace->dobj.name, tbinfo->dobj.namespace->dobj.name,
tbinfo->rolname, tbinfo->rolname,
rinfo->dobj.catId, 0, rinfo->dobj.dumpId); rinfo->dobj.catId, 0, rinfo->dobj.dumpId);
...@@ -15244,7 +15219,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo) ...@@ -15244,7 +15219,7 @@ dumpRule(Archive *fout, RuleInfo *rinfo)
* getExtensionMembership --- obtain extension membership data * getExtensionMembership --- obtain extension membership data
*/ */
void void
getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], getExtensionMembership(Archive *fout, DumpOptions *dopt, ExtensionInfo extinfo[],
int numExtensions) int numExtensions)
{ {
PQExpBuffer query; PQExpBuffer query;
...@@ -15341,7 +15316,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], ...@@ -15341,7 +15316,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
* idea is to exactly reproduce the database contents rather than * idea is to exactly reproduce the database contents rather than
* replace the extension contents with something different. * replace the extension contents with something different.
*/ */
if (!binary_upgrade) if (!dopt->binary_upgrade)
dobj->dump = false; dobj->dump = false;
else else
dobj->dump = refdobj->dump; dobj->dump = refdobj->dump;
...@@ -15420,7 +15395,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], ...@@ -15420,7 +15395,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
* of the --oids setting. This is because row filtering * of the --oids setting. This is because row filtering
* conditions aren't compatible with dumping OIDs. * conditions aren't compatible with dumping OIDs.
*/ */
makeTableDataInfo(configtbl, false); makeTableDataInfo(dopt, configtbl, false);
if (configtbl->dataObj != NULL) if (configtbl->dataObj != NULL)
{ {
if (strlen(extconditionarray[j]) > 0) if (strlen(extconditionarray[j]) > 0)
......
...@@ -14,50 +14,14 @@ ...@@ -14,50 +14,14 @@
#ifndef PG_DUMP_H #ifndef PG_DUMP_H
#define PG_DUMP_H #define PG_DUMP_H
#include "postgres_fe.h" #include "pg_backup.h"
/*
* pg_dump uses two different mechanisms for identifying database objects:
*
* CatalogId represents an object by the tableoid and oid of its defining
* entry in the system catalogs. We need this to interpret pg_depend entries,
* for instance.
*
* DumpId is a simple sequential integer counter assigned as dumpable objects
* are identified during a pg_dump run. We use DumpId internally in preference
* to CatalogId for two reasons: it's more compact, and we can assign DumpIds
* to "objects" that don't have a separate CatalogId. For example, it is
* convenient to consider a table, its data, and its ACL as three separate
* dumpable "objects" with distinct DumpIds --- this lets us reason about the
* order in which to dump these things.
*/
typedef struct
{
Oid tableoid;
Oid oid;
} CatalogId;
typedef int DumpId;
/*
* Data structures for simple lists of OIDs and strings. The support for
* these is very primitive compared to the backend's List facilities, but
* it's all we need in pg_dump.
*/
typedef struct SimpleOidListCell
{
struct SimpleOidListCell *next;
Oid val;
} SimpleOidListCell;
typedef struct SimpleOidList
{
SimpleOidListCell *head;
SimpleOidListCell *tail;
} SimpleOidList;
#define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
#define oideq(x,y) ( (x) == (y) )
#define oidle(x,y) ( (x) <= (y) )
#define oidge(x,y) ( (x) >= (y) )
#define oidzero(x) ( (x) == 0 )
/* /*
* The data structures used to store system catalog information. Every * The data structures used to store system catalog information. Every
...@@ -519,18 +483,7 @@ extern char g_opaque_type[10]; /* name for the opaque type */ ...@@ -519,18 +483,7 @@ extern char g_opaque_type[10]; /* name for the opaque type */
* common utility functions * common utility functions
*/ */
struct Archive; extern TableInfo *getSchemaData(Archive *, DumpOptions *dopt, int *numTablesPtr);
typedef struct Archive Archive;
extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
typedef enum _OidOptions
{
zeroAsOpaque = 1,
zeroAsAny = 2,
zeroAsStar = 4,
zeroAsNone = 8
} OidOptions;
extern void AssignDumpId(DumpableObject *dobj); extern void AssignDumpId(DumpableObject *dobj);
extern DumpId createDumpId(void); extern DumpId createDumpId(void);
...@@ -564,16 +517,16 @@ extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs); ...@@ -564,16 +517,16 @@ extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
* version specific routines * version specific routines
*/ */
extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces); extern NamespaceInfo *getNamespaces(Archive *fout, int *numNamespaces);
extern ExtensionInfo *getExtensions(Archive *fout, int *numExtensions); extern ExtensionInfo *getExtensions(Archive *fout, DumpOptions *dopt, int *numExtensions);
extern TypeInfo *getTypes(Archive *fout, int *numTypes); extern TypeInfo *getTypes(Archive *fout, int *numTypes);
extern FuncInfo *getFuncs(Archive *fout, int *numFuncs); extern FuncInfo *getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs);
extern AggInfo *getAggregates(Archive *fout, int *numAggregates); extern AggInfo *getAggregates(Archive *fout, DumpOptions *dopt, int *numAggregates);
extern OprInfo *getOperators(Archive *fout, int *numOperators); extern OprInfo *getOperators(Archive *fout, int *numOperators);
extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses); extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies); extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
extern CollInfo *getCollations(Archive *fout, int *numCollations); extern CollInfo *getCollations(Archive *fout, int *numCollations);
extern ConvInfo *getConversions(Archive *fout, int *numConversions); extern ConvInfo *getConversions(Archive *fout, int *numConversions);
extern TableInfo *getTables(Archive *fout, int *numTables); extern TableInfo *getTables(Archive *fout, DumpOptions *dopt, int *numTables);
extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables); extern void getOwnedSeqs(Archive *fout, TableInfo tblinfo[], int numTables);
extern InhInfo *getInherits(Archive *fout, int *numInherits); extern InhInfo *getInherits(Archive *fout, int *numInherits);
extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables); extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
...@@ -582,8 +535,8 @@ extern RuleInfo *getRules(Archive *fout, int *numRules); ...@@ -582,8 +535,8 @@ extern RuleInfo *getRules(Archive *fout, int *numRules);
extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables); extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs); extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
extern CastInfo *getCasts(Archive *fout, int *numCasts); extern CastInfo *getCasts(Archive *fout, int *numCasts);
extern void getTableAttrs(Archive *fout, TableInfo *tbinfo, int numTables); extern void getTableAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo, int numTables);
extern bool shouldPrintColumn(TableInfo *tbinfo, int colno); extern bool shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno);
extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers); extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts); extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates); extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
...@@ -592,8 +545,8 @@ extern FdwInfo *getForeignDataWrappers(Archive *fout, ...@@ -592,8 +545,8 @@ extern FdwInfo *getForeignDataWrappers(Archive *fout,
int *numForeignDataWrappers); int *numForeignDataWrappers);
extern ForeignServerInfo *getForeignServers(Archive *fout, extern ForeignServerInfo *getForeignServers(Archive *fout,
int *numForeignServers); int *numForeignServers);
extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs); extern DefaultACLInfo *getDefaultACLs(Archive *fout, DumpOptions *dopt, int *numDefaultACLs);
extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], extern void getExtensionMembership(Archive *fout, DumpOptions *dopt, ExtensionInfo extinfo[],
int numExtensions); int numExtensions);
extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers); extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
extern void getRowSecurity(Archive *fout, TableInfo tblinfo[], int numTables); extern void getRowSecurity(Archive *fout, TableInfo tblinfo[], int numTables);
......
...@@ -13,9 +13,11 @@ ...@@ -13,9 +13,11 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "parallel.h" #include "pg_dump.h"
/* translator: this is a module name */ /* translator: this is a module name */
static const char *modulename = gettext_noop("sorter"); static const char *modulename = gettext_noop("sorter");
......
...@@ -57,7 +57,7 @@ static void buildShSecLabels(PGconn *conn, const char *catalog_name, ...@@ -57,7 +57,7 @@ static void buildShSecLabels(PGconn *conn, const char *catalog_name,
uint32 objectId, PQExpBuffer buffer, uint32 objectId, PQExpBuffer buffer,
const char *target, const char *objname); const char *target, const char *objname);
static PGconn *connectDatabase(const char *dbname, const char *connstr, const char *pghost, const char *pgport, static PGconn *connectDatabase(const char *dbname, const char *connstr, const char *pghost, const char *pgport,
const char *pguser, enum trivalue prompt_password, bool fail_on_error); const char *pguser, trivalue prompt_password, bool fail_on_error);
static char *constructConnStr(const char **keywords, const char **values); static char *constructConnStr(const char **keywords, const char **values);
static PGresult *executeQuery(PGconn *conn, const char *query); static PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(PGconn *conn, const char *query); static void executeCommand(PGconn *conn, const char *query);
...@@ -138,7 +138,7 @@ main(int argc, char *argv[]) ...@@ -138,7 +138,7 @@ main(int argc, char *argv[])
char *pguser = NULL; char *pguser = NULL;
char *pgdb = NULL; char *pgdb = NULL;
char *use_role = NULL; char *use_role = NULL;
enum trivalue prompt_password = TRI_DEFAULT; trivalue prompt_password = TRI_DEFAULT;
bool data_only = false; bool data_only = false;
bool globals_only = false; bool globals_only = false;
bool output_clean = false; bool output_clean = false;
...@@ -1765,7 +1765,7 @@ buildShSecLabels(PGconn *conn, const char *catalog_name, uint32 objectId, ...@@ -1765,7 +1765,7 @@ buildShSecLabels(PGconn *conn, const char *catalog_name, uint32 objectId,
static PGconn * static PGconn *
connectDatabase(const char *dbname, const char *connection_string, connectDatabase(const char *dbname, const char *connection_string,
const char *pghost, const char *pgport, const char *pguser, const char *pghost, const char *pgport, const char *pguser,
enum trivalue prompt_password, bool fail_on_error) trivalue prompt_password, bool fail_on_error)
{ {
PGconn *conn; PGconn *conn;
bool new_pass; bool new_pass;
......
...@@ -38,12 +38,13 @@ ...@@ -38,12 +38,13 @@
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres_fe.h"
#include "getopt_long.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "dumputils.h" #include "dumputils.h"
#include "parallel.h" #include "parallel.h"
#include "getopt_long.h" #include "pg_backup_utils.h"
#include <ctype.h> #include <ctype.h>
...@@ -423,7 +424,7 @@ main(int argc, char **argv) ...@@ -423,7 +424,7 @@ main(int argc, char **argv)
/* AH may be freed in CloseArchive? */ /* AH may be freed in CloseArchive? */
exit_code = AH->n_errors ? 1 : 0; exit_code = AH->n_errors ? 1 : 0;
CloseArchive(AH); CloseArchive(AH, NULL);
return exit_code; return exit_code;
} }
......
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