mirror of
https://github.com/postgres/postgres.git
synced 2025-04-20 00:42:27 +03:00
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:
parent
e0d97d77bf
commit
0eea8047bf
@ -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;
|
|||||||
|
|
||||||
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);
|
|||||||
* 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)
|
|||||||
*/
|
*/
|
||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
|
|
||||||
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)
|
|||||||
*/
|
*/
|
||||||
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)
|
|||||||
|
|
||||||
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,
|
|||||||
* 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)
|
|||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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 @@
|
|||||||
#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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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
|
|||||||
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 @@
|
|||||||
|
|
||||||
#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);
|
|||||||
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)
|
|||||||
*/
|
*/
|
||||||
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,
|
|||||||
* 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)
|
|||||||
* 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)
|
|||||||
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)
|
|||||||
* 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])
|
|||||||
* 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 @@
|
|||||||
#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
|
|||||||
/* 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);
|
|||||||
|
|
||||||
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 checkAborting(ArchiveHandle *AH);
|
||||||
|
|
||||||
extern void
|
|
||||||
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 @@
|
|||||||
#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
|
|||||||
* 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
|
|||||||
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
|
|||||||
* 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
|
|||||||
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
|
|||||||
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,
|
|||||||
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);
|
|||||||
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);
|
|||||||
|
|
||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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,
|
|||||||
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);
|
|||||||
* 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)
|
|||||||
|
|
||||||
/* 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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
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,
|
|||||||
* 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,
|
|||||||
*/
|
*/
|
||||||
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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
* 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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
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)
|
|||||||
/*
|
/*
|
||||||
* 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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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;
|
|||||||
#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
|
|||||||
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
|
|||||||
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
|
|||||||
|
|
||||||
/* 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
|
|||||||
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
|
|||||||
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);
|
|||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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);
|
|||||||
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)
|
|||||||
* 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)
|
|||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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,
|
|||||||
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)
|
|||||||
* 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)
|
|||||||
* 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)
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 @@
|
|||||||
#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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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);
|
|||||||
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
|
|||||||
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)
|
|||||||
* 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)
|
|||||||
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)
|
|||||||
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)
|
|||||||
* 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)
|
|||||||
* 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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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);
|
|||||||
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)
|
|||||||
{
|
{
|
||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_CloseArchive(ArchiveHandle *AH)
|
_CloseArchive(ArchiveHandle *AH, DumpOptions *dopt)
|
||||||
{
|
{
|
||||||
/* Nothing to do */
|
/* Nothing to do */
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|||||||
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)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
|||||||
/*
|
/*
|
||||||
* 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 @@
|
|||||||
#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)));
|
|||||||
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 */
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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 */
|
|||||||
* 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);
|
|||||||
* 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);
|
|||||||
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,
|
|||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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,
|
|||||||
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[])
|
|||||||
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,
|
|||||||
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 @@
|
|||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
#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)
|
|||||||
/* 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;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user