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
This commit is contained in:
Alvaro Herrera 2014-10-14 15:00:55 -03:00
parent e0d97d77bf
commit 0eea8047bf
22 changed files with 758 additions and 675 deletions

View File

@ -13,8 +13,11 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "pg_dump.h"
#include <ctype.h>
@ -64,7 +67,7 @@ static DumpableObject **nspinfoindex;
static void flagInhTables(TableInfo *tbinfo, int numTables,
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,
Size objSize);
static int DOCatalogIdCompare(const void *p1, const void *p2);
@ -78,7 +81,7 @@ static int strInArray(const char *pattern, char **arr, int arr_size);
* Collect information about all potentially dumpable objects
*/
TableInfo *
getSchemaData(Archive *fout, int *numTablesPtr)
getSchemaData(Archive *fout, DumpOptions *dopt, int *numTablesPtr)
{
ExtensionInfo *extinfo;
InhInfo *inhinfo;
@ -114,7 +117,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
*/
if (g_verbose)
write_msg(NULL, "reading user-defined tables\n");
tblinfo = getTables(fout, &numTables);
tblinfo = getTables(fout, dopt, &numTables);
tblinfoindex = buildIndexArray(tblinfo, numTables, sizeof(TableInfo));
/* Do this after we've built tblinfoindex */
@ -122,11 +125,11 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose)
write_msg(NULL, "reading extensions\n");
extinfo = getExtensions(fout, &numExtensions);
extinfo = getExtensions(fout, dopt, &numExtensions);
if (g_verbose)
write_msg(NULL, "reading user-defined functions\n");
funinfo = getFuncs(fout, &numFuncs);
funinfo = getFuncs(fout, dopt, &numFuncs);
funinfoindex = buildIndexArray(funinfo, numFuncs, sizeof(FuncInfo));
/* this must be after getTables and getFuncs */
@ -142,7 +145,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose)
write_msg(NULL, "reading user-defined aggregate functions\n");
getAggregates(fout, &numAggregates);
getAggregates(fout, dopt, &numAggregates);
if (g_verbose)
write_msg(NULL, "reading user-defined operators\n");
@ -183,7 +186,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose)
write_msg(NULL, "reading default privileges\n");
getDefaultACLs(fout, &numDefaultACLs);
getDefaultACLs(fout, dopt, &numDefaultACLs);
if (g_verbose)
write_msg(NULL, "reading user-defined collations\n");
@ -213,7 +216,7 @@ getSchemaData(Archive *fout, int *numTablesPtr)
*/
if (g_verbose)
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 */
if (g_verbose)
@ -222,11 +225,11 @@ getSchemaData(Archive *fout, int *numTablesPtr)
if (g_verbose)
write_msg(NULL, "reading column info for interesting tables\n");
getTableAttrs(fout, tblinfo, numTables);
getTableAttrs(fout, dopt, tblinfo, numTables);
if (g_verbose)
write_msg(NULL, "flagging inherited columns in subtables\n");
flagInhAttrs(tblinfo, numTables);
flagInhAttrs(dopt, tblinfo, numTables);
if (g_verbose)
write_msg(NULL, "reading indexes\n");
@ -307,7 +310,7 @@ flagInhTables(TableInfo *tblinfo, int numTables,
* modifies tblinfo
*/
static void
flagInhAttrs(TableInfo *tblinfo, int numTables)
flagInhAttrs(DumpOptions *dopt, TableInfo *tblinfo, int numTables)
{
int i,
j,
@ -384,7 +387,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables)
attrDef->adef_expr = pg_strdup("NULL");
/* Will column be dumped explicitly? */
if (shouldPrintColumn(tbinfo, j))
if (shouldPrintColumn(dopt, tbinfo, j))
{
attrDef->separate = false;
/* No dependency needed: NULL cannot have dependencies */

View File

@ -51,10 +51,11 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "compress_io.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include "pg_backup_utils.h"
/*----------------------
* Compressor API

View File

@ -15,7 +15,6 @@
#ifndef __COMPRESS_IO__
#define __COMPRESS_IO__
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
/* Initial buffer sizes used in zlib compression. */

View File

@ -12,13 +12,29 @@
*
*-------------------------------------------------------------------------
*/
#ifndef DUMPUTILS_H
#define DUMPUTILS_H
#include "libpq-fe.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
{
struct SimpleStringListCell *next;
@ -31,6 +47,7 @@ typedef struct SimpleStringList
SimpleStringListCell *tail;
} SimpleStringList;
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
extern int quote_all_identifiers;
extern PQExpBuffer (*getLocalPQExpBuffer) (void);

View File

@ -18,8 +18,8 @@
#include "postgres_fe.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include "pg_backup_utils.h"
#ifndef WIN32
#include <sys/types.h>
@ -89,11 +89,12 @@ static void WaitForTerminatingWorkers(ParallelState *pstate);
static void sigTermHandler(int signum);
#endif
static void SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
DumpOptions *dopt,
RestoreOptions *ropt);
static bool HasEveryWorkerTerminated(ParallelState *pstate);
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 void sendMessageToMaster(int pipefd[2], const char *str);
static int select_loop(int maxFd, fd_set *workerset);
@ -436,6 +437,7 @@ sigTermHandler(int signum)
*/
static void
SetupWorker(ArchiveHandle *AH, int pipefd[2], int worker,
DumpOptions *dopt,
RestoreOptions *ropt)
{
/*
@ -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
* brought down because of an error.
*/
(AH->SetupWorkerPtr) ((Archive *) AH, ropt);
(AH->SetupWorkerPtr) ((Archive *) AH, dopt, ropt);
Assert(AH->connection != NULL);
WaitForCommands(AH, pipefd);
WaitForCommands(AH, dopt, pipefd);
closesocket(pipefd[PIPE_READ]);
closesocket(pipefd[PIPE_WRITE]);
@ -481,7 +483,7 @@ init_spawned_worker_win32(WorkerInfo *wi)
* of threads while it does a fork() on Unix.
*/
ParallelState *
ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt)
ParallelBackupStart(ArchiveHandle *AH, DumpOptions *dopt, RestoreOptions *ropt)
{
ParallelState *pstate;
int i;
@ -598,7 +600,7 @@ ParallelBackupStart(ArchiveHandle *AH, RestoreOptions *ropt)
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);
}
@ -856,7 +858,7 @@ lockTableNoWait(ArchiveHandle *AH, TocEntry *te)
* exit.
*/
static void
WaitForCommands(ArchiveHandle *AH, int pipefd[2])
WaitForCommands(ArchiveHandle *AH, DumpOptions *dopt, int pipefd[2])
{
char *command;
DumpId dumpId;
@ -896,7 +898,7 @@ WaitForCommands(ArchiveHandle *AH, int pipefd[2])
* The message we return here has been pg_malloc()ed and we are
* responsible for free()ing it.
*/
str = (AH->WorkerJobDumpPtr) (AH, te);
str = (AH->WorkerJobDumpPtr) (AH, dopt, te);
Assert(AH->connection != NULL);
sendMessageToMaster(pipefd, str);
free(str);

View File

@ -19,10 +19,7 @@
#ifndef PG_DUMP_PARALLEL_H
#define PG_DUMP_PARALLEL_H
#include "pg_backup_db.h"
struct _archiveHandle;
struct _tocEntry;
#include "pg_backup_archiver.h"
typedef enum
{
@ -35,8 +32,8 @@ typedef enum
/* Arguments needed for a worker process */
typedef struct ParallelArgs
{
struct _archiveHandle *AH;
struct _tocEntry *te;
ArchiveHandle *AH;
TocEntry *te;
} ParallelArgs;
/* State for each parallel activity slot */
@ -74,22 +71,19 @@ extern void init_parallel_dump_utils(void);
extern int GetIdleWorker(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 void EnsureIdleWorker(struct _archiveHandle * AH, ParallelState *pstate);
extern void EnsureWorkersFinished(struct _archiveHandle * AH, ParallelState *pstate);
extern void EnsureIdleWorker(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);
extern void DispatchJobForTocEntry(struct _archiveHandle * AH,
extern void DispatchJobForTocEntry(ArchiveHandle *AH,
ParallelState *pstate,
struct _tocEntry * te, T_Action act);
extern void ParallelBackupEnd(struct _archiveHandle * AH, ParallelState *pstate);
TocEntry *te, T_Action act);
extern void ParallelBackupEnd(ArchiveHandle *AH, ParallelState *pstate);
extern void checkAborting(struct _archiveHandle * AH);
extern void
exit_horribly(const char *modulename, const char *fmt,...)
__attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3), noreturn));
extern void checkAborting(ArchiveHandle *AH);
#endif /* PG_DUMP_PARALLEL_H */

View File

@ -23,27 +23,16 @@
#ifndef PG_BACKUP_H
#define PG_BACKUP_H
#include "postgres_fe.h"
#include "pg_dump.h"
#include "dumputils.h"
#include "libpq-fe.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
#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
typedef enum trivalue
{
TRI_DEFAULT,
TRI_NO,
TRI_YES
};
} trivalue;
typedef enum _archiveFormat
{
@ -73,7 +62,7 @@ typedef enum _teSection
* We may want to have some more user-readable data, but in the mean
* time this gives us some abstraction and type checking.
*/
struct Archive
typedef struct Archive
{
int verbose;
char *remoteVersionStr; /* server's version string */
@ -96,9 +85,7 @@ struct Archive
int n_errors; /* number of errors (if no die) */
/* The rest is private */
};
typedef int (*DataDumperPtr) (Archive *AH, void *userArg);
} Archive;
typedef struct _restoreOptions
{
@ -109,17 +96,24 @@ typedef struct _restoreOptions
* restore */
int use_setsessauth;/* Use SET SESSION AUTHORIZATION commands
* instead of OWNER TO */
int no_security_labels; /* Skip security label entries */
char *superuser; /* Username to use as superuser */
char *use_role; /* Issue SET ROLE to this */
int dropSchema;
int disable_dollar_quoting;
int dump_inserts;
int column_inserts;
int if_exists;
int no_security_labels; /* Skip security label entries */
const char *filename;
int dataOnly;
int schemaOnly;
int dumpSections;
int verbose;
int aclsSkip;
const char *lockWaitTimeout;
int include_everything;
int tocSummary;
char *tocFile;
int format;
@ -142,7 +136,7 @@ typedef struct _restoreOptions
char *pghost;
char *username;
int noDataForFailedTables;
enum trivalue promptPassword;
trivalue promptPassword;
int exit_on_error;
int compression;
int suppressDumpWarnings; /* Suppress output of WARNING entries
@ -153,7 +147,76 @@ typedef struct _restoreOptions
int enable_row_security;
} 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.
@ -164,7 +227,7 @@ extern void ConnectDatabase(Archive *AH,
const char *pghost,
const char *pgport,
const char *username,
enum trivalue prompt_password);
trivalue prompt_password);
extern void DisconnectDatabase(Archive *AHX);
extern PGconn *GetConnection(Archive *AHX);
@ -186,7 +249,7 @@ extern void WriteData(Archive *AH, const void *data, size_t dLen);
extern int StartBlob(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);
@ -205,6 +268,9 @@ extern void PrintTOCSummary(Archive *AH, RestoreOptions *ropt);
extern RestoreOptions *NewRestoreOptions(void);
extern DumpOptions *NewDumpOptions(void);
extern DumpOptions *dumpOptionsFromRestoreOptions(RestoreOptions *ropt);
/* Rearrange and filter TOC entries */
extern void SortTocFromFile(Archive *AHX, RestoreOptions *ropt);

View File

@ -19,10 +19,12 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "parallel.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include <ctype.h>
#include <fcntl.h>
@ -106,6 +108,61 @@ static void reduce_dependencies(ArchiveHandle *AH, TocEntry *te,
static void mark_create_done(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.
*
@ -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.
*/
static void
setupRestoreWorker(Archive *AHX, RestoreOptions *ropt)
setupRestoreWorker(Archive *AHX, DumpOptions *dopt, RestoreOptions *ropt)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
@ -152,12 +209,12 @@ OpenArchive(const char *FileSpec, const ArchiveFormat fmt)
/* Public */
void
CloseArchive(Archive *AHX)
CloseArchive(Archive *AHX, DumpOptions *dopt)
{
int res = 0;
ArchiveHandle *AH = (ArchiveHandle *) AHX;
(*AH->ClosePtr) (AH);
(*AH->ClosePtr) (AH, dopt);
/* Close the output */
if (AH->gzOut)
@ -368,7 +425,7 @@ RestoreArchive(Archive *AHX)
if (ropt->single_txn)
{
if (AH->connection)
StartTransaction(AH);
StartTransaction(AHX);
else
ahprintf(AH, "BEGIN;\n\n");
}
@ -548,7 +605,7 @@ RestoreArchive(Archive *AHX)
Assert(AH->connection == NULL);
/* ParallelBackupStart() will actually fork the processes */
pstate = ParallelBackupStart(AH, ropt);
pstate = ParallelBackupStart(AH, NULL, ropt);
restore_toc_entries_parallel(AH, pstate, &pending_list);
ParallelBackupEnd(AH, pstate);
@ -586,7 +643,7 @@ RestoreArchive(Archive *AHX)
if (ropt->single_txn)
{
if (AH->connection)
CommitTransaction(AH);
CommitTransaction(AHX);
else
ahprintf(AH, "COMMIT;\n\n");
}
@ -767,7 +824,7 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
* Parallel restore is always talking directly to a
* 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
@ -798,12 +855,12 @@ restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
*/
if (AH->outputKind == OUTPUT_COPYDATA &&
RestoringToDB(AH))
EndDBCopyMode(AH, te);
EndDBCopyMode(&AH->public, te->tag);
AH->outputKind = OUTPUT_SQLCMDS;
/* close out the transaction started above */
if (is_parallel && te->created)
CommitTransaction(AH);
CommitTransaction(&AH->public);
_enableTriggersIfNecessary(AH, te, ropt);
}
@ -1099,7 +1156,7 @@ StartRestoreBlobs(ArchiveHandle *AH)
if (!AH->ropt->single_txn)
{
if (AH->connection)
StartTransaction(AH);
StartTransaction(&AH->public);
else
ahprintf(AH, "BEGIN;\n\n");
}
@ -1116,7 +1173,7 @@ EndRestoreBlobs(ArchiveHandle *AH)
if (!AH->ropt->single_txn)
{
if (AH->connection)
CommitTransaction(AH);
CommitTransaction(&AH->public);
else
ahprintf(AH, "COMMIT;\n\n");
}
@ -1573,7 +1630,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
* connected then send it to the DB.
*/
if (RestoringToDB(AH))
bytes_written = ExecuteSqlCommandBuf(AH, (const char *) ptr, size * nmemb);
bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
else
bytes_written = fwrite(ptr, size, nmemb, AH->OF) * size;
}
@ -2240,7 +2297,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
}
void
WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
WriteDataChunks(ArchiveHandle *AH, DumpOptions *dopt, ParallelState *pstate)
{
TocEntry *te;
@ -2263,13 +2320,13 @@ WriteDataChunks(ArchiveHandle *AH, ParallelState *pstate)
DispatchJobForTocEntry(AH, pstate, te, ACT_DUMP);
}
else
WriteDataChunksForTocEntry(AH, te);
WriteDataChunksForTocEntry(AH, dopt, te);
}
EnsureWorkersFinished(AH, pstate);
}
void
WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
WriteDataChunksForTocEntry(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te)
{
StartDataPtr startPtr;
EndDataPtr endPtr;
@ -2293,7 +2350,7 @@ WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
/*
* 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)
(*endPtr) (AH, te);

View File

@ -21,11 +21,9 @@
*
*-------------------------------------------------------------------------
*/
#ifndef __PG_BACKUP_ARCHIVE__
#define __PG_BACKUP_ARCHIVE__
#include "postgres_fe.h"
#include <time.h>
@ -111,9 +109,8 @@ typedef z_stream *z_streamp;
#define WORKER_INHIBIT_DATA 11
#define WORKER_IGNORED_ERRORS 12
struct _archiveHandle;
struct _tocEntry;
struct _restoreList;
typedef struct _archiveHandle ArchiveHandle;
typedef struct _tocEntry TocEntry;
struct ParallelArgs;
struct ParallelState;
@ -139,40 +136,40 @@ typedef enum T_Action
ACT_RESTORE
} T_Action;
typedef void (*ClosePtr) (struct _archiveHandle * AH);
typedef void (*ReopenPtr) (struct _archiveHandle * AH);
typedef void (*ArchiveEntryPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*ClosePtr) (ArchiveHandle *AH, DumpOptions *dopt);
typedef void (*ReopenPtr) (ArchiveHandle *AH);
typedef void (*ArchiveEntryPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*WriteDataPtr) (struct _archiveHandle * AH, const void *data, size_t dLen);
typedef void (*EndDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*StartDataPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*WriteDataPtr) (ArchiveHandle *AH, const void *data, size_t dLen);
typedef void (*EndDataPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*StartBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid);
typedef void (*EndBlobPtr) (struct _archiveHandle * AH, struct _tocEntry * te, Oid oid);
typedef void (*EndBlobsPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*StartBlobsPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*StartBlobPtr) (ArchiveHandle *AH, TocEntry *te, Oid oid);
typedef void (*EndBlobPtr) (ArchiveHandle *AH, TocEntry *te, Oid oid);
typedef void (*EndBlobsPtr) (ArchiveHandle *AH, TocEntry *te);
typedef int (*WriteBytePtr) (struct _archiveHandle * AH, const int i);
typedef int (*ReadBytePtr) (struct _archiveHandle * AH);
typedef void (*WriteBufPtr) (struct _archiveHandle * AH, const void *c, size_t len);
typedef void (*ReadBufPtr) (struct _archiveHandle * AH, void *buf, size_t len);
typedef void (*SaveArchivePtr) (struct _archiveHandle * AH);
typedef void (*WriteExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*ReadExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*PrintExtraTocPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef void (*PrintTocDataPtr) (struct _archiveHandle * AH, struct _tocEntry * te, RestoreOptions *ropt);
typedef int (*WriteBytePtr) (ArchiveHandle *AH, const int i);
typedef int (*ReadBytePtr) (ArchiveHandle *AH);
typedef void (*WriteBufPtr) (ArchiveHandle *AH, const void *c, size_t len);
typedef void (*ReadBufPtr) (ArchiveHandle *AH, void *buf, size_t len);
typedef void (*SaveArchivePtr) (ArchiveHandle *AH);
typedef void (*WriteExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*ReadExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*PrintExtraTocPtr) (ArchiveHandle *AH, TocEntry *te);
typedef void (*PrintTocDataPtr) (ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
typedef void (*ClonePtr) (struct _archiveHandle * AH);
typedef void (*DeClonePtr) (struct _archiveHandle * AH);
typedef void (*ClonePtr) (ArchiveHandle *AH);
typedef void (*DeClonePtr) (ArchiveHandle *AH);
typedef char *(*WorkerJobRestorePtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef char *(*WorkerJobDumpPtr) (struct _archiveHandle * AH, struct _tocEntry * te);
typedef char *(*MasterStartParallelItemPtr) (struct _archiveHandle * AH, struct _tocEntry * te,
typedef char *(*WorkerJobRestorePtr) (ArchiveHandle *AH, TocEntry *te);
typedef char *(*WorkerJobDumpPtr) (ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te);
typedef char *(*MasterStartParallelItemPtr) (ArchiveHandle *AH, TocEntry *te,
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);
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
{
@ -210,7 +207,7 @@ typedef enum
REQ_SPECIAL = 0x04 /* for special TOC entries */
} teReqs;
typedef struct _archiveHandle
struct _archiveHandle
{
Archive public; /* Public part of archive */
char vmaj; /* Version of file */
@ -284,7 +281,7 @@ typedef struct _archiveHandle
/* Stuff for direct DB connection */
char *archdbname; /* DB name *read* from archive */
enum trivalue promptPassword;
trivalue promptPassword;
char *savedPassword; /* password for ropt->username, if known */
char *use_role;
PGconn *connection;
@ -336,9 +333,9 @@ typedef struct _archiveHandle
ArchiverStage lastErrorStage;
struct _tocEntry *currentTE;
struct _tocEntry *lastErrorTE;
} ArchiveHandle;
};
typedef struct _tocEntry
struct _tocEntry
{
struct _tocEntry *prev;
struct _tocEntry *next;
@ -376,7 +373,7 @@ typedef struct _tocEntry
int nRevDeps; /* number of such dependencies */
DumpId *lockDeps; /* dumpIds of objects this one needs lock on */
int nLockDeps; /* number of such dependencies */
} TocEntry;
};
extern int parallel_restore(struct ParallelArgs *args);
extern void on_exit_close_archive(Archive *AHX);
@ -389,8 +386,8 @@ extern void WriteHead(ArchiveHandle *AH);
extern void ReadHead(ArchiveHandle *AH);
extern void WriteToc(ArchiveHandle *AH);
extern void ReadToc(ArchiveHandle *AH);
extern void WriteDataChunks(ArchiveHandle *AH, struct ParallelState *pstate);
extern void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te);
extern void WriteDataChunks(ArchiveHandle *AH, DumpOptions *dopt, struct ParallelState *pstate);
extern void WriteDataChunksForTocEntry(ArchiveHandle *AH, DumpOptions *dopt, TocEntry *te);
extern ArchiveHandle *CloneArchive(ArchiveHandle *AH);
extern void DeCloneArchive(ArchiveHandle *AH);

View File

@ -23,6 +23,7 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "compress_io.h"
#include "parallel.h"
@ -41,7 +42,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const 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 _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
@ -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
* 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
* WriteToc to save the TOC entries
* WriteDataChunks to save all DATA & BLOBs.
*
*/
static void
_CloseArchive(ArchiveHandle *AH)
_CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{
lclContext *ctx = (lclContext *) AH->formatData;
pgoff_t tpos;
@ -709,7 +710,7 @@ _CloseArchive(ArchiveHandle *AH)
strerror(errno));
WriteToc(AH);
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

View File

@ -9,11 +9,12 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "dumputils.h"
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
#include "pg_backup_utils.h"
#include "dumputils.h"
#include "parallel.h"
#include <unistd.h>
#include <ctype.h>
@ -217,7 +218,7 @@ ConnectDatabase(Archive *AHX,
const char *pghost,
const char *pgport,
const char *username,
enum trivalue prompt_password)
trivalue prompt_password)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
char *password = AH->savedPassword;
@ -500,8 +501,10 @@ ExecuteSimpleCommands(ArchiveHandle *AH, const char *buf, size_t bufLen)
* Implement ahwrite() for direct-to-DB restore
*/
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)
{
/*
@ -553,8 +556,10 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLen)
* Terminate a COPY operation during direct-to-DB restore
*/
void
EndDBCopyMode(ArchiveHandle *AH, TocEntry *te)
EndDBCopyMode(Archive *AHX, const char *tocEntryTag)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
if (AH->pgCopyIn)
{
PGresult *res;
@ -567,7 +572,7 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te)
res = PQgetResult(AH->connection);
if (PQresultStatus(res) != PGRES_COMMAND_OK)
warn_or_exit_horribly(AH, modulename, "COPY failed for table \"%s\": %s",
te->tag, PQerrorMessage(AH->connection));
tocEntryTag, PQerrorMessage(AH->connection));
PQclear(res);
AH->pgCopyIn = false;
@ -575,14 +580,18 @@ EndDBCopyMode(ArchiveHandle *AH, TocEntry *te)
}
void
StartTransaction(ArchiveHandle *AH)
StartTransaction(Archive *AHX)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
ExecuteSqlCommand(AH, "BEGIN", "could not start database transaction");
}
void
CommitTransaction(ArchiveHandle *AH)
CommitTransaction(Archive *AHX)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
ExecuteSqlCommand(AH, "COMMIT", "could not commit database transaction");
}

View File

@ -8,17 +8,18 @@
#ifndef 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 PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
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 CommitTransaction(ArchiveHandle *AH);
extern void StartTransaction(Archive *AHX);
extern void CommitTransaction(Archive *AHX);
#endif

View File

@ -32,10 +32,11 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "compress_io.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include "pg_backup_utils.h"
#include <dirent.h>
#include <sys/stat.h>
@ -71,7 +72,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const 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 _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt);
@ -92,7 +93,7 @@ static char *_MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action
static int _MasterEndParallelItem(ArchiveHandle *AH, TocEntry *te,
const char *str, T_Action act);
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,
const char *relativeFilename);
@ -566,7 +567,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
* WriteDataChunks to save all DATA & BLOBs.
*/
static void
_CloseArchive(ArchiveHandle *AH)
_CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{
lclContext *ctx = (lclContext *) AH->formatData;
@ -578,7 +579,7 @@ _CloseArchive(ArchiveHandle *AH)
setFilePath(AH, fname, "toc.dat");
/* 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 */
tocFH = cfopen_write(fname, PG_BINARY_W, 0);
@ -599,7 +600,7 @@ _CloseArchive(ArchiveHandle *AH)
if (cfclose(tocFH) != 0)
exit_horribly(modulename, "could not close TOC file: %s\n",
strerror(errno));
WriteDataChunks(AH, ctx->pstate);
WriteDataChunks(AH, dopt, ctx->pstate);
ParallelBackupEnd(AH, ctx->pstate);
}
@ -790,7 +791,7 @@ _MasterStartParallelItem(ArchiveHandle *AH, TocEntry *te, T_Action act)
* function of the respective dump format.
*/
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
@ -809,7 +810,7 @@ _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
* succeed... A failure will be detected by the parent when the child dies
* unexpectedly.
*/
WriteDataChunksForTocEntry(AH, te);
WriteDataChunksForTocEntry(AH, dopt, te);
snprintf(buf, buflen, "OK DUMP %d", te->dumpId);

View File

@ -21,12 +21,10 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include <unistd.h> /* for dup */
#include "libpq/libpq-fs.h"
@ -35,7 +33,7 @@ static void _WriteBlobData(ArchiveHandle *AH, const void *data, size_t dLen);
static void _EndData(ArchiveHandle *AH, TocEntry *te);
static int _WriteByte(ArchiveHandle *AH, const int i);
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 _StartBlobs(ArchiveHandle *AH, TocEntry *te);
static void _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid);
@ -198,12 +196,16 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
{
if (te->dataDumper)
{
DumpOptions *dopt;
AH->currToc = te;
if (strcmp(te->desc, "BLOBS") == 0)
_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)
_EndBlobs(AH, te);
@ -227,7 +229,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
}
static void
_CloseArchive(ArchiveHandle *AH)
_CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{
/* Nothing to do */
}

View File

@ -27,12 +27,11 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include "pg_backup_tar.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include "pgtar.h"
#include <sys/stat.h>
@ -48,7 +47,7 @@ static int _WriteByte(ArchiveHandle *AH, const int i);
static int _ReadByte(ArchiveHandle *);
static void _WriteBuf(ArchiveHandle *AH, const 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 _WriteExtraToc(ArchiveHandle *AH, TocEntry *te);
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te);
@ -827,7 +826,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
}
static void
_CloseArchive(ArchiveHandle *AH)
_CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
{
lclContext *ctx = (lclContext *) AH->formatData;
TAR_MEMBER *th;
@ -850,7 +849,7 @@ _CloseArchive(ArchiveHandle *AH)
/*
* 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

View File

@ -14,7 +14,6 @@
#include "postgres_fe.h"
#include "pg_backup_utils.h"
#include "parallel.h"
/* Globals exported by this file */
const char *progname = NULL;

View File

@ -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 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 */

File diff suppressed because it is too large Load Diff

View File

@ -14,50 +14,14 @@
#ifndef 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
@ -519,18 +483,7 @@ extern char g_opaque_type[10]; /* name for the opaque type */
* common utility functions
*/
struct Archive;
typedef struct Archive Archive;
extern TableInfo *getSchemaData(Archive *, int *numTablesPtr);
typedef enum _OidOptions
{
zeroAsOpaque = 1,
zeroAsAny = 2,
zeroAsStar = 4,
zeroAsNone = 8
} OidOptions;
extern TableInfo *getSchemaData(Archive *, DumpOptions *dopt, int *numTablesPtr);
extern void AssignDumpId(DumpableObject *dobj);
extern DumpId createDumpId(void);
@ -564,16 +517,16 @@ extern void sortDataAndIndexObjectsBySize(DumpableObject **objs, int numObjs);
* version specific routines
*/
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 FuncInfo *getFuncs(Archive *fout, int *numFuncs);
extern AggInfo *getAggregates(Archive *fout, int *numAggregates);
extern FuncInfo *getFuncs(Archive *fout, DumpOptions *dopt, int *numFuncs);
extern AggInfo *getAggregates(Archive *fout, DumpOptions *dopt, int *numAggregates);
extern OprInfo *getOperators(Archive *fout, int *numOperators);
extern OpclassInfo *getOpclasses(Archive *fout, int *numOpclasses);
extern OpfamilyInfo *getOpfamilies(Archive *fout, int *numOpfamilies);
extern CollInfo *getCollations(Archive *fout, int *numCollations);
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 InhInfo *getInherits(Archive *fout, int *numInherits);
extern void getIndexes(Archive *fout, TableInfo tblinfo[], int numTables);
@ -582,8 +535,8 @@ extern RuleInfo *getRules(Archive *fout, int *numRules);
extern void getTriggers(Archive *fout, TableInfo tblinfo[], int numTables);
extern ProcLangInfo *getProcLangs(Archive *fout, int *numProcLangs);
extern CastInfo *getCasts(Archive *fout, int *numCasts);
extern void getTableAttrs(Archive *fout, TableInfo *tbinfo, int numTables);
extern bool shouldPrintColumn(TableInfo *tbinfo, int colno);
extern void getTableAttrs(Archive *fout, DumpOptions *dopt, TableInfo *tbinfo, int numTables);
extern bool shouldPrintColumn(DumpOptions *dopt, TableInfo *tbinfo, int colno);
extern TSParserInfo *getTSParsers(Archive *fout, int *numTSParsers);
extern TSDictInfo *getTSDictionaries(Archive *fout, int *numTSDicts);
extern TSTemplateInfo *getTSTemplates(Archive *fout, int *numTSTemplates);
@ -592,8 +545,8 @@ extern FdwInfo *getForeignDataWrappers(Archive *fout,
int *numForeignDataWrappers);
extern ForeignServerInfo *getForeignServers(Archive *fout,
int *numForeignServers);
extern DefaultACLInfo *getDefaultACLs(Archive *fout, int *numDefaultACLs);
extern void getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
extern DefaultACLInfo *getDefaultACLs(Archive *fout, DumpOptions *dopt, int *numDefaultACLs);
extern void getExtensionMembership(Archive *fout, DumpOptions *dopt, ExtensionInfo extinfo[],
int numExtensions);
extern EventTriggerInfo *getEventTriggers(Archive *fout, int *numEventTriggers);
extern void getRowSecurity(Archive *fout, TableInfo tblinfo[], int numTables);

View File

@ -13,9 +13,11 @@
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
#include "parallel.h"
#include "pg_dump.h"
/* translator: this is a module name */
static const char *modulename = gettext_noop("sorter");

View File

@ -57,7 +57,7 @@ static void buildShSecLabels(PGconn *conn, const char *catalog_name,
uint32 objectId, PQExpBuffer buffer,
const char *target, const char *objname);
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 PGresult *executeQuery(PGconn *conn, const char *query);
static void executeCommand(PGconn *conn, const char *query);
@ -138,7 +138,7 @@ main(int argc, char *argv[])
char *pguser = NULL;
char *pgdb = NULL;
char *use_role = NULL;
enum trivalue prompt_password = TRI_DEFAULT;
trivalue prompt_password = TRI_DEFAULT;
bool data_only = false;
bool globals_only = false;
bool output_clean = false;
@ -1765,7 +1765,7 @@ buildShSecLabels(PGconn *conn, const char *catalog_name, uint32 objectId,
static PGconn *
connectDatabase(const char *dbname, const char *connection_string,
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;
bool new_pass;

View File

@ -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 "parallel.h"
#include "getopt_long.h"
#include "pg_backup_utils.h"
#include <ctype.h>
@ -423,7 +424,7 @@ main(int argc, char **argv)
/* AH may be freed in CloseArchive? */
exit_code = AH->n_errors ? 1 : 0;
CloseArchive(AH);
CloseArchive(AH, NULL);
return exit_code;
}