PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pg_backup_archiver.h File Reference
#include <time.h>
#include "libpq-fe.h"
#include "pg_backup.h"
#include "pqexpbuffer.h"
Include dependency graph for pg_backup_archiver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sqlparseInfo
 
struct  _archiveHandle
 
struct  _tocEntry
 
struct  _archiveOpts
 

Macros

#define LOBBUFSIZE   16384
 
#define BLK_DATA   1
 
#define BLK_BLOBS   3
 
#define MAKE_ARCHIVE_VERSION(major, minor, rev)   (((major) * 256 + (minor)) * 256 + (rev))
 
#define ARCHIVE_MAJOR(version)   (((version) >> 16) & 255)
 
#define ARCHIVE_MINOR(version)   (((version) >> 8) & 255)
 
#define ARCHIVE_REV(version)   (((version) ) & 255)
 
#define K_VERS_1_0   MAKE_ARCHIVE_VERSION(1, 0, 0)
 
#define K_VERS_1_2   MAKE_ARCHIVE_VERSION(1, 2, 0) /* Allow No ZLIB */
 
#define K_VERS_1_3   MAKE_ARCHIVE_VERSION(1, 3, 0) /* BLOBS */
 
#define K_VERS_1_4   MAKE_ARCHIVE_VERSION(1, 4, 0) /* Date & name in header */
 
#define K_VERS_1_5   MAKE_ARCHIVE_VERSION(1, 5, 0) /* Handle dependencies */
 
#define K_VERS_1_6   MAKE_ARCHIVE_VERSION(1, 6, 0) /* Schema field in TOCs */
 
#define K_VERS_1_7
 
#define K_VERS_1_8
 
#define K_VERS_1_9
 
#define K_VERS_1_10   MAKE_ARCHIVE_VERSION(1, 10, 0) /* add tablespace */
 
#define K_VERS_1_11
 
#define K_VERS_1_12
 
#define K_VERS_1_13
 
#define K_VERS_1_14   MAKE_ARCHIVE_VERSION(1, 14, 0) /* add tableam */
 
#define K_VERS_1_15
 
#define K_VERS_1_16
 
#define K_VERS_MAJOR   1
 
#define K_VERS_MINOR   16
 
#define K_VERS_REV   0
 
#define K_VERS_SELF   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV)
 
#define K_VERS_MAX   MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)
 
#define K_OFFSET_POS_NOT_SET   1
 
#define K_OFFSET_POS_SET   2
 
#define K_OFFSET_NO_DATA   3
 
#define WORKER_OK   0
 
#define WORKER_CREATE_DONE   10
 
#define WORKER_INHIBIT_DATA   11
 
#define WORKER_IGNORED_ERRORS   12
 
#define READ_ERROR_EXIT(fd)
 
#define WRITE_ERROR_EXIT
 
#define RESTORE_PASS_LAST   RESTORE_PASS_POST_ACL
 
#define REQ_SCHEMA   0x01 /* want schema */
 
#define REQ_DATA   0x02 /* want data */
 
#define REQ_STATS   0x04
 
#define REQ_SPECIAL   0x08 /* for special TOC entries */
 
#define ARCHIVE_OPTS(...)   &(ArchiveOpts){__VA_ARGS__}
 
#define appendStringLiteralAHX(buf, str, AH)    appendStringLiteral(buf, str, (AH)->public.encoding, (AH)->public.std_strings)
 
#define appendByteaLiteralAHX(buf, str, len, AH)    appendByteaLiteral(buf, str, len, (AH)->public.std_strings)
 

Typedefs

typedef struct _archiveHandle ArchiveHandle
 
typedef struct _tocEntry TocEntry
 
typedef enum T_Action T_Action
 
typedef void(* ClosePtrType) (ArchiveHandle *AH)
 
typedef void(* ReopenPtrType) (ArchiveHandle *AH)
 
typedef void(* ArchiveEntryPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartDataPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* WriteDataPtrType) (ArchiveHandle *AH, const void *data, size_t dLen)
 
typedef void(* EndDataPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartLOsPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* StartLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)
 
typedef void(* EndLOsPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WriteBytePtrType) (ArchiveHandle *AH, const int i)
 
typedef int(* ReadBytePtrType) (ArchiveHandle *AH)
 
typedef void(* WriteBufPtrType) (ArchiveHandle *AH, const void *c, size_t len)
 
typedef void(* ReadBufPtrType) (ArchiveHandle *AH, void *buf, size_t len)
 
typedef void(* WriteExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* ReadExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrintTocDataPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef void(* PrepParallelRestorePtrType) (ArchiveHandle *AH)
 
typedef void(* ClonePtrType) (ArchiveHandle *AH)
 
typedef void(* DeClonePtrType) (ArchiveHandle *AH)
 
typedef int(* WorkerJobDumpPtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef int(* WorkerJobRestorePtrType) (ArchiveHandle *AH, TocEntry *te)
 
typedef size_t(* CustomOutPtrType) (ArchiveHandle *AH, const void *buf, size_t len)
 
typedef char *(* DefnDumperPtr) (Archive *AH, const void *userArg, const TocEntry *te)
 
typedef int(* DataDumperPtr) (Archive *AH, const void *userArg)
 
typedef void struct _archiveOpts ArchiveOpts
 

Enumerations

enum  T_Action { ACT_DUMP , ACT_RESTORE }
 
enum  sqlparseState { SQL_SCAN = 0 , SQL_IN_SINGLE_QUOTE , SQL_IN_DOUBLE_QUOTE }
 
enum  ArchiverStage { STAGE_NONE = 0 , STAGE_INITIALIZING , STAGE_PROCESSING , STAGE_FINALIZING }
 
enum  ArchiverOutput { OUTPUT_SQLCMDS = 0 , OUTPUT_COPYDATA , OUTPUT_OTHERDATA }
 
enum  RestorePass { RESTORE_PASS_MAIN = 0 , RESTORE_PASS_ACL , RESTORE_PASS_POST_ACL }
 

Functions

int parallel_restore (ArchiveHandle *AH, TocEntry *te)
 
void on_exit_close_archive (Archive *AHX)
 
void replace_on_exit_close_archive (Archive *AHX)
 
void warn_or_exit_horribly (ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2
 
TocEntryArchiveEntry (Archive *AHX, CatalogId catalogId, DumpId dumpId, ArchiveOpts *opts)
 
void WriteHead (ArchiveHandle *AH)
 
void ReadHead (ArchiveHandle *AH)
 
void WriteToc (ArchiveHandle *AH)
 
void ReadToc (ArchiveHandle *AH)
 
void WriteDataChunks (ArchiveHandle *AH, struct ParallelState *pstate)
 
void WriteDataChunksForTocEntry (ArchiveHandle *AH, TocEntry *te)
 
ArchiveHandleCloneArchive (ArchiveHandle *AH)
 
void DeCloneArchive (ArchiveHandle *AH)
 
int TocIDRequired (ArchiveHandle *AH, DumpId id)
 
TocEntrygetTocEntryByDumpId (ArchiveHandle *AH, DumpId id)
 
bool checkSeek (FILE *fp)
 
size_t WriteInt (ArchiveHandle *AH, int i)
 
int ReadInt (ArchiveHandle *AH)
 
charReadStr (ArchiveHandle *AH)
 
size_t WriteStr (ArchiveHandle *AH, const char *c)
 
int ReadOffset (ArchiveHandle *, pgoff_t *)
 
size_t WriteOffset (ArchiveHandle *, pgoff_t, int)
 
void StartRestoreLOs (ArchiveHandle *AH)
 
void StartRestoreLO (ArchiveHandle *AH, Oid oid, bool drop)
 
void EndRestoreLO (ArchiveHandle *AH, Oid oid)
 
void EndRestoreLOs (ArchiveHandle *AH)
 
void InitArchiveFmt_Custom (ArchiveHandle *AH)
 
void InitArchiveFmt_Null (ArchiveHandle *AH)
 
void InitArchiveFmt_Directory (ArchiveHandle *AH)
 
void InitArchiveFmt_Tar (ArchiveHandle *AH)
 
bool isValidTarHeader (char *header)
 
void ReconnectToServer (ArchiveHandle *AH, const char *dbname)
 
void IssueCommandPerBlob (ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
 
void IssueACLPerBlob (ArchiveHandle *AH, TocEntry *te)
 
void DropLOIfExists (ArchiveHandle *AH, Oid oid)
 
void ahwrite (const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
 
int ahprintf (ArchiveHandle *AH, const char *fmt,...) pg_attribute_printf(2
 

Macro Definition Documentation

◆ appendByteaLiteralAHX

#define appendByteaLiteralAHX (   buf,
  str,
  len,
  AH 
)     appendByteaLiteral(buf, str, len, (AH)->public.std_strings)

Definition at line 432 of file pg_backup_archiver.h.

◆ appendStringLiteralAHX

#define appendStringLiteralAHX (   buf,
  str,
  AH 
)     appendStringLiteral(buf, str, (AH)->public.encoding, (AH)->public.std_strings)

Definition at line 429 of file pg_backup_archiver.h.

◆ ARCHIVE_MAJOR

#define ARCHIVE_MAJOR (   version)    (((version) >> 16) & 255)

Definition at line 42 of file pg_backup_archiver.h.

◆ ARCHIVE_MINOR

#define ARCHIVE_MINOR (   version)    (((version) >> 8) & 255)

Definition at line 43 of file pg_backup_archiver.h.

◆ ARCHIVE_OPTS

#define ARCHIVE_OPTS (   ...)    &(ArchiveOpts){__VA_ARGS__}

Definition at line 411 of file pg_backup_archiver.h.

◆ ARCHIVE_REV

#define ARCHIVE_REV (   version)    (((version) ) & 255)

Definition at line 44 of file pg_backup_archiver.h.

◆ BLK_BLOBS

#define BLK_BLOBS   3

Definition at line 37 of file pg_backup_archiver.h.

◆ BLK_DATA

#define BLK_DATA   1

Definition at line 36 of file pg_backup_archiver.h.

◆ K_OFFSET_NO_DATA

#define K_OFFSET_NO_DATA   3

Definition at line 77 of file pg_backup_archiver.h.

◆ K_OFFSET_POS_NOT_SET

#define K_OFFSET_POS_NOT_SET   1

Definition at line 75 of file pg_backup_archiver.h.

◆ K_OFFSET_POS_SET

#define K_OFFSET_POS_SET   2

Definition at line 76 of file pg_backup_archiver.h.

◆ K_VERS_1_0

#define K_VERS_1_0   MAKE_ARCHIVE_VERSION(1, 0, 0)

Definition at line 47 of file pg_backup_archiver.h.

◆ K_VERS_1_10

#define K_VERS_1_10   MAKE_ARCHIVE_VERSION(1, 10, 0) /* add tablespace */

Definition at line 56 of file pg_backup_archiver.h.

◆ K_VERS_1_11

#define K_VERS_1_11
Value:
MAKE_ARCHIVE_VERSION(1, 11, 0) /* add toc section
* indicator */
#define MAKE_ARCHIVE_VERSION(major, minor, rev)

Definition at line 57 of file pg_backup_archiver.h.

◆ K_VERS_1_12

#define K_VERS_1_12
Value:
MAKE_ARCHIVE_VERSION(1, 12, 0) /* add separate BLOB
* entries */

Definition at line 58 of file pg_backup_archiver.h.

◆ K_VERS_1_13

#define K_VERS_1_13
Value:
MAKE_ARCHIVE_VERSION(1, 13, 0) /* change search_path
* behavior */

Definition at line 59 of file pg_backup_archiver.h.

◆ K_VERS_1_14

#define K_VERS_1_14   MAKE_ARCHIVE_VERSION(1, 14, 0) /* add tableam */

Definition at line 60 of file pg_backup_archiver.h.

◆ K_VERS_1_15

#define K_VERS_1_15
Value:
MAKE_ARCHIVE_VERSION(1, 15, 0) /* add
* compression_algorithm
* in header */

Definition at line 61 of file pg_backup_archiver.h.

◆ K_VERS_1_16

#define K_VERS_1_16
Value:
MAKE_ARCHIVE_VERSION(1, 16, 0) /* BLOB METADATA entries
* and multiple BLOBS,
* relkind */

Definition at line 62 of file pg_backup_archiver.h.

◆ K_VERS_1_2

#define K_VERS_1_2   MAKE_ARCHIVE_VERSION(1, 2, 0) /* Allow No ZLIB */

Definition at line 48 of file pg_backup_archiver.h.

◆ K_VERS_1_3

#define K_VERS_1_3   MAKE_ARCHIVE_VERSION(1, 3, 0) /* BLOBS */

Definition at line 49 of file pg_backup_archiver.h.

◆ K_VERS_1_4

#define K_VERS_1_4   MAKE_ARCHIVE_VERSION(1, 4, 0) /* Date & name in header */

Definition at line 50 of file pg_backup_archiver.h.

◆ K_VERS_1_5

#define K_VERS_1_5   MAKE_ARCHIVE_VERSION(1, 5, 0) /* Handle dependencies */

Definition at line 51 of file pg_backup_archiver.h.

◆ K_VERS_1_6

#define K_VERS_1_6   MAKE_ARCHIVE_VERSION(1, 6, 0) /* Schema field in TOCs */

Definition at line 52 of file pg_backup_archiver.h.

◆ K_VERS_1_7

#define K_VERS_1_7
Value:
MAKE_ARCHIVE_VERSION(1, 7, 0) /* File Offset size in
* header */

Definition at line 53 of file pg_backup_archiver.h.

◆ K_VERS_1_8

#define K_VERS_1_8
Value:
MAKE_ARCHIVE_VERSION(1, 8, 0) /* change interpretation
* of ID numbers and
* dependencies */

Definition at line 54 of file pg_backup_archiver.h.

◆ K_VERS_1_9

#define K_VERS_1_9
Value:
MAKE_ARCHIVE_VERSION(1, 9, 0) /* add default_with_oids
* tracking */

Definition at line 55 of file pg_backup_archiver.h.

◆ K_VERS_MAJOR

#define K_VERS_MAJOR   1

Definition at line 65 of file pg_backup_archiver.h.

◆ K_VERS_MAX

Definition at line 71 of file pg_backup_archiver.h.

◆ K_VERS_MINOR

#define K_VERS_MINOR   16

Definition at line 66 of file pg_backup_archiver.h.

◆ K_VERS_REV

#define K_VERS_REV   0

Definition at line 67 of file pg_backup_archiver.h.

◆ K_VERS_SELF

Definition at line 68 of file pg_backup_archiver.h.

◆ LOBBUFSIZE

#define LOBBUFSIZE   16384

Definition at line 33 of file pg_backup_archiver.h.

◆ MAKE_ARCHIVE_VERSION

#define MAKE_ARCHIVE_VERSION (   major,
  minor,
  rev 
)    (((major) * 256 + (minor)) * 256 + (rev))

Definition at line 40 of file pg_backup_archiver.h.

◆ READ_ERROR_EXIT

#define READ_ERROR_EXIT (   fd)
Value:
do { \
pg_fatal("could not read from input file: end of file"); \
pg_fatal("could not read from input file: %m"); \
} while (0)
static int fd(const char *x, int i)
static int fb(int x)

Definition at line 92 of file pg_backup_archiver.h.

◆ REQ_DATA

#define REQ_DATA   0x02 /* want data */

Definition at line 200 of file pg_backup_archiver.h.

◆ REQ_SCHEMA

#define REQ_SCHEMA   0x01 /* want schema */

Definition at line 199 of file pg_backup_archiver.h.

◆ REQ_SPECIAL

#define REQ_SPECIAL   0x08 /* for special TOC entries */

Definition at line 202 of file pg_backup_archiver.h.

◆ REQ_STATS

#define REQ_STATS   0x04

Definition at line 201 of file pg_backup_archiver.h.

◆ RESTORE_PASS_LAST

#define RESTORE_PASS_LAST   RESTORE_PASS_POST_ACL

Definition at line 196 of file pg_backup_archiver.h.

◆ WORKER_CREATE_DONE

#define WORKER_CREATE_DONE   10

Definition at line 84 of file pg_backup_archiver.h.

◆ WORKER_IGNORED_ERRORS

#define WORKER_IGNORED_ERRORS   12

Definition at line 86 of file pg_backup_archiver.h.

◆ WORKER_INHIBIT_DATA

#define WORKER_INHIBIT_DATA   11

Definition at line 85 of file pg_backup_archiver.h.

◆ WORKER_OK

#define WORKER_OK   0

Definition at line 83 of file pg_backup_archiver.h.

◆ WRITE_ERROR_EXIT

#define WRITE_ERROR_EXIT
Value:
do { \
pg_fatal("could not write to output file: %m"); \
} while (0)

Definition at line 100 of file pg_backup_archiver.h.

Typedef Documentation

◆ ArchiveEntryPtrType

typedef void(* ArchiveEntryPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 113 of file pg_backup_archiver.h.

◆ ArchiveHandle

Definition at line 88 of file pg_backup_archiver.h.

◆ ArchiveOpts

◆ ClonePtrType

typedef void(* ClonePtrType) (ArchiveHandle *AH)

Definition at line 134 of file pg_backup_archiver.h.

◆ ClosePtrType

typedef void(* ClosePtrType) (ArchiveHandle *AH)

Definition at line 111 of file pg_backup_archiver.h.

◆ CustomOutPtrType

typedef size_t(* CustomOutPtrType) (ArchiveHandle *AH, const void *buf, size_t len)

Definition at line 140 of file pg_backup_archiver.h.

◆ DataDumperPtr

typedef int(* DataDumperPtr) (Archive *AH, const void *userArg)

Definition at line 335 of file pg_backup_archiver.h.

◆ DeClonePtrType

typedef void(* DeClonePtrType) (ArchiveHandle *AH)

Definition at line 135 of file pg_backup_archiver.h.

◆ DefnDumperPtr

typedef char *(* DefnDumperPtr) (Archive *AH, const void *userArg, const TocEntry *te)

Definition at line 334 of file pg_backup_archiver.h.

◆ EndDataPtrType

typedef void(* EndDataPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 117 of file pg_backup_archiver.h.

◆ EndLOPtrType

typedef void(* EndLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)

Definition at line 121 of file pg_backup_archiver.h.

◆ EndLOsPtrType

typedef void(* EndLOsPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 122 of file pg_backup_archiver.h.

◆ PrepParallelRestorePtrType

typedef void(* PrepParallelRestorePtrType) (ArchiveHandle *AH)

Definition at line 133 of file pg_backup_archiver.h.

◆ PrintExtraTocPtrType

typedef void(* PrintExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 130 of file pg_backup_archiver.h.

◆ PrintTocDataPtrType

typedef void(* PrintTocDataPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 131 of file pg_backup_archiver.h.

◆ ReadBufPtrType

typedef void(* ReadBufPtrType) (ArchiveHandle *AH, void *buf, size_t len)

Definition at line 127 of file pg_backup_archiver.h.

◆ ReadBytePtrType

typedef int(* ReadBytePtrType) (ArchiveHandle *AH)

Definition at line 125 of file pg_backup_archiver.h.

◆ ReadExtraTocPtrType

typedef void(* ReadExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 129 of file pg_backup_archiver.h.

◆ ReopenPtrType

typedef void(* ReopenPtrType) (ArchiveHandle *AH)

Definition at line 112 of file pg_backup_archiver.h.

◆ StartDataPtrType

typedef void(* StartDataPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 115 of file pg_backup_archiver.h.

◆ StartLOPtrType

typedef void(* StartLOPtrType) (ArchiveHandle *AH, TocEntry *te, Oid oid)

Definition at line 120 of file pg_backup_archiver.h.

◆ StartLOsPtrType

typedef void(* StartLOsPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 119 of file pg_backup_archiver.h.

◆ T_Action

◆ TocEntry

Definition at line 89 of file pg_backup_archiver.h.

◆ WorkerJobDumpPtrType

typedef int(* WorkerJobDumpPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 137 of file pg_backup_archiver.h.

◆ WorkerJobRestorePtrType

typedef int(* WorkerJobRestorePtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 138 of file pg_backup_archiver.h.

◆ WriteBufPtrType

typedef void(* WriteBufPtrType) (ArchiveHandle *AH, const void *c, size_t len)

Definition at line 126 of file pg_backup_archiver.h.

◆ WriteBytePtrType

typedef int(* WriteBytePtrType) (ArchiveHandle *AH, const int i)

Definition at line 124 of file pg_backup_archiver.h.

◆ WriteDataPtrType

typedef void(* WriteDataPtrType) (ArchiveHandle *AH, const void *data, size_t dLen)

Definition at line 116 of file pg_backup_archiver.h.

◆ WriteExtraTocPtrType

typedef void(* WriteExtraTocPtrType) (ArchiveHandle *AH, TocEntry *te)

Definition at line 128 of file pg_backup_archiver.h.

Enumeration Type Documentation

◆ ArchiverOutput

Enumerator
OUTPUT_SQLCMDS 
OUTPUT_COPYDATA 
OUTPUT_OTHERDATA 

Definition at line 164 of file pg_backup_archiver.h.

168{
169 STAGE_NONE = 0,
@ STAGE_NONE

◆ ArchiverStage

Enumerator
STAGE_NONE 
STAGE_INITIALIZING 
STAGE_PROCESSING 
STAGE_FINALIZING 

Definition at line 156 of file pg_backup_archiver.h.

161{
162 sqlparseState state; /* see above */

◆ RestorePass

Enumerator
RESTORE_PASS_MAIN 
RESTORE_PASS_ACL 
RESTORE_PASS_POST_ACL 

Definition at line 190 of file pg_backup_archiver.h.

◆ sqlparseState

Enumerator
SQL_SCAN 
SQL_IN_SINGLE_QUOTE 
SQL_IN_DOUBLE_QUOTE 

Definition at line 142 of file pg_backup_archiver.h.

◆ T_Action

Enumerator
ACT_DUMP 
ACT_RESTORE 

Definition at line 105 of file pg_backup_archiver.h.

106 : end of file"); \
107 else \
108 pg_fatal("could not read from input file: %m"); \
109 } while (0)
FILE * input
#define read(a, b, c)
Definition win32.h:13

Function Documentation

◆ ahprintf()

int ahprintf ( ArchiveHandle AH,
const char fmt,
  ... 
)

◆ ahwrite()

void ahwrite ( const void ptr,
size_t  size,
size_t  nmemb,
ArchiveHandle AH 
)

Definition at line 1871 of file pg_backup_archiver.c.

1872{
1873 int bytes_written = 0;
1874
1875 if (AH->writingLO)
1876 {
1877 size_t remaining = size * nmemb;
1878
1879 while (AH->lo_buf_used + remaining > AH->lo_buf_size)
1880 {
1881 size_t avail = AH->lo_buf_size - AH->lo_buf_used;
1882
1883 memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, avail);
1884 ptr = (const char *) ptr + avail;
1885 remaining -= avail;
1886 AH->lo_buf_used += avail;
1887 dump_lo_buf(AH);
1888 }
1889
1890 memcpy((char *) AH->lo_buf + AH->lo_buf_used, ptr, remaining);
1891 AH->lo_buf_used += remaining;
1892
1893 bytes_written = size * nmemb;
1894 }
1895 else if (AH->CustomOutPtr)
1896 bytes_written = AH->CustomOutPtr(AH, ptr, size * nmemb);
1897
1898 /*
1899 * If we're doing a restore, and it's direct to DB, and we're connected
1900 * then send it to the DB.
1901 */
1902 else if (RestoringToDB(AH))
1903 bytes_written = ExecuteSqlCommandBuf(&AH->public, (const char *) ptr, size * nmemb);
1904 else
1905 {
1907
1908 CFH->write_func(ptr, size * nmemb, CFH);
1909 bytes_written = size * nmemb;
1910 }
1911
1912 if (bytes_written != size * nmemb)
1914}
int remaining
Definition informix.c:692
static int RestoringToDB(ArchiveHandle *AH)
static void dump_lo_buf(ArchiveHandle *AH)
#define WRITE_ERROR_EXIT
int ExecuteSqlCommandBuf(Archive *AHX, const char *buf, size_t bufLen)
CustomOutPtrType CustomOutPtr

References _archiveHandle::CustomOutPtr, dump_lo_buf(), ExecuteSqlCommandBuf(), fb(), _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, _archiveHandle::lo_buf_used, _archiveHandle::OF, _archiveHandle::public, remaining, RestoringToDB(), WRITE_ERROR_EXIT, and _archiveHandle::writingLO.

Referenced by _LoadLOs(), _PrintFileData(), _PrintFileData(), _PrintTocData(), _WriteData(), ahprintf(), and ReadDataFromArchiveNone().

◆ ArchiveEntry()

TocEntry * ArchiveEntry ( Archive AHX,
CatalogId  catalogId,
DumpId  dumpId,
ArchiveOpts opts 
)
extern

Definition at line 1259 of file pg_backup_archiver.c.

1261{
1262 ArchiveHandle *AH = (ArchiveHandle *) AHX;
1264
1266
1267 AH->tocCount++;
1268 if (dumpId > AH->maxDumpId)
1269 AH->maxDumpId = dumpId;
1270
1271 newToc->prev = AH->toc->prev;
1272 newToc->next = AH->toc;
1273 AH->toc->prev->next = newToc;
1274 AH->toc->prev = newToc;
1275
1276 newToc->catalogId = catalogId;
1277 newToc->dumpId = dumpId;
1278 newToc->section = opts->section;
1279
1280 newToc->tag = pg_strdup(opts->tag);
1281 newToc->namespace = opts->namespace ? pg_strdup(opts->namespace) : NULL;
1282 newToc->tablespace = opts->tablespace ? pg_strdup(opts->tablespace) : NULL;
1283 newToc->tableam = opts->tableam ? pg_strdup(opts->tableam) : NULL;
1284 newToc->relkind = opts->relkind;
1285 newToc->owner = opts->owner ? pg_strdup(opts->owner) : NULL;
1286 newToc->desc = pg_strdup(opts->description);
1287 newToc->defn = opts->createStmt ? pg_strdup(opts->createStmt) : NULL;
1288 newToc->dropStmt = opts->dropStmt ? pg_strdup(opts->dropStmt) : NULL;
1289 newToc->copyStmt = opts->copyStmt ? pg_strdup(opts->copyStmt) : NULL;
1290
1291 if (opts->nDeps > 0)
1292 {
1293 newToc->dependencies = pg_malloc_array(DumpId, opts->nDeps);
1294 memcpy(newToc->dependencies, opts->deps, opts->nDeps * sizeof(DumpId));
1295 newToc->nDeps = opts->nDeps;
1296 }
1297 else
1298 {
1299 newToc->dependencies = NULL;
1300 newToc->nDeps = 0;
1301 }
1302
1303 newToc->dataDumper = opts->dumpFn;
1304 newToc->dataDumperArg = opts->dumpArg;
1305 newToc->hadDumper = opts->dumpFn ? true : false;
1306
1307 newToc->defnDumper = opts->defnFn;
1308 newToc->defnDumperArg = opts->defnArg;
1309
1310 newToc->formatData = NULL;
1311 newToc->dataLength = 0;
1312
1313 if (AH->ArchiveEntryPtr != NULL)
1314 AH->ArchiveEntryPtr(AH, newToc);
1315
1316 return newToc;
1317}
char * pg_strdup(const char *in)
Definition fe_memutils.c:85
#define pg_malloc_array(type, count)
Definition fe_memutils.h:56
#define pg_malloc0_object(type)
Definition fe_memutils.h:51
return true
Definition isn.c:130
static AmcheckOptions opts
Definition pg_amcheck.c:112
int DumpId
Definition pg_backup.h:285
struct _tocEntry * toc
ArchiveEntryPtrType ArchiveEntryPtr
struct _tocEntry * prev
CatalogId catalogId
struct _tocEntry * next

References _archiveHandle::ArchiveEntryPtr, _tocEntry::catalogId, fb(), _archiveHandle::maxDumpId, _tocEntry::next, opts, pg_malloc0_object, pg_malloc_array, pg_strdup(), _tocEntry::prev, _archiveHandle::toc, _archiveHandle::tocCount, and true.

Referenced by dropDBs(), dropRoles(), dropTablespaces(), dumpAccessMethod(), dumpACL(), dumpAgg(), dumpAttrDef(), dumpBaseType(), dumpCast(), dumpCollation(), dumpCommentExtended(), dumpCompositeType(), dumpCompositeTypeColComments(), dumpConstraint(), dumpConversion(), dumpDatabase(), dumpDefaultACL(), dumpDomain(), dumpDumpableObject(), dumpEncoding(), dumpEnumType(), dumpEventTrigger(), dumpExtension(), dumpForeignDataWrapper(), dumpForeignServer(), dumpFunc(), dumpIndex(), dumpIndexAttach(), dumpLO(), dumpNamespace(), dumpOpclass(), dumpOpfamily(), dumpOpr(), dumpPolicy(), dumpProcLang(), dumpPublication(), dumpPublicationNamespace(), dumpPublicationTable(), dumpRangeType(), dumpRelationStats(), dumpRoleGUCPrivs(), dumpRoleMembership(), dumpRoles(), dumpRule(), dumpSearchPath(), dumpSecLabel(), dumpSequence(), dumpSequenceData(), dumpShellType(), dumpStatisticsExt(), dumpStatisticsExtStats(), dumpStdStrings(), dumpSubscription(), dumpSubscriptionTable(), dumpTableAttach(), dumpTableComment(), dumpTableData(), dumpTableSchema(), dumpTableSecLabel(), dumpTablespaces(), dumpTransform(), dumpTrigger(), dumpTSConfig(), dumpTSDictionary(), dumpTSParser(), dumpTSTemplate(), dumpUndefinedType(), dumpUserConfig(), dumpUserMappings(), main(), and refreshMatViewData().

◆ checkSeek()

bool checkSeek ( FILE fp)
extern

Definition at line 4327 of file pg_backup_archiver.c.

4328{
4329 pgoff_t tpos;
4330
4331 /* Check that ftello works on this file */
4332 tpos = ftello(fp);
4333 if (tpos < 0)
4334 return false;
4335
4336 /*
4337 * Check that fseeko(SEEK_SET) works, too. NB: we used to try to test
4338 * this with fseeko(fp, 0, SEEK_CUR). But some platforms treat that as a
4339 * successful no-op even on files that are otherwise unseekable.
4340 */
4341 if (fseeko(fp, tpos, SEEK_SET) != 0)
4342 return false;
4343
4344 return true;
4345}
off_t pgoff_t
Definition port.h:421
#define ftello(stream)
Definition win32_port.h:209
#define fseeko(stream, offset, origin)
Definition win32_port.h:206

References fb(), fseeko, and ftello.

Referenced by InitArchiveFmt_Custom(), and InitArchiveFmt_Tar().

◆ CloneArchive()

ArchiveHandle * CloneArchive ( ArchiveHandle AH)
extern

Definition at line 5194 of file pg_backup_archiver.c.

5195{
5197
5198 /* Make a "flat" copy */
5200 memcpy(clone, AH, sizeof(ArchiveHandle));
5201
5202 /* Likewise flat-copy the RestoreOptions, so we can alter them locally */
5203 clone->public.ropt = pg_malloc_object(RestoreOptions);
5204 memcpy(clone->public.ropt, AH->public.ropt, sizeof(RestoreOptions));
5205
5206 /* Handle format-independent fields */
5207 memset(&(clone->sqlparse), 0, sizeof(clone->sqlparse));
5208
5209 /* The clone will have its own connection, so disregard connection state */
5210 clone->connection = NULL;
5211 clone->connCancel = NULL;
5212 clone->currUser = NULL;
5213 clone->currSchema = NULL;
5214 clone->currTableAm = NULL;
5215 clone->currTablespace = NULL;
5216
5217 /* savedPassword must be local in case we change it while connecting */
5218 if (clone->savedPassword)
5219 clone->savedPassword = pg_strdup(clone->savedPassword);
5220
5221 /* clone has its own error count, too */
5222 clone->public.n_errors = 0;
5223
5224 /* clones should not share lo_buf */
5225 clone->lo_buf = NULL;
5226
5227 /*
5228 * Clone connections disregard --transaction-size; they must commit after
5229 * each command so that the results are immediately visible to other
5230 * workers.
5231 */
5232 clone->public.ropt->txn_size = 0;
5233
5234 /*
5235 * Connect our new clone object to the database, using the same connection
5236 * parameters used for the original connection.
5237 */
5238 ConnectDatabaseAhx((Archive *) clone, &clone->public.ropt->cparams, true);
5239
5240 /* re-establish fixed state */
5241 if (AH->mode == archModeRead)
5243 /* in write case, setupDumpWorker will fix up connection state */
5244
5245 /* Let the format-specific code have a chance too */
5246 clone->ClonePtr(clone);
5247
5248 Assert(clone->connection != NULL);
5249 return clone;
5250}
#define Assert(condition)
Definition c.h:885
#define pg_malloc_object(type)
Definition fe_memutils.h:50
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
@ archModeRead
Definition pg_backup.h:52
static void _doSetFixedOutputState(ArchiveHandle *AH)
RestoreOptions * ropt
Definition pg_backup.h:230

References _doSetFixedOutputState(), archModeRead, Assert, ConnectDatabaseAhx(), fb(), _archiveHandle::mode, pg_malloc_object, pg_strdup(), _archiveHandle::public, and Archive::ropt.

Referenced by RunWorker().

◆ DeCloneArchive()

void DeCloneArchive ( ArchiveHandle AH)
extern

Definition at line 5258 of file pg_backup_archiver.c.

5259{
5260 /* Should not have an open database connection */
5261 Assert(AH->connection == NULL);
5262
5263 /* Clear format-specific state */
5264 AH->DeClonePtr(AH);
5265
5266 /* Clear state allocated by CloneArchive */
5267 if (AH->sqlparse.curCmd)
5269
5270 /* Clear any connection-local state */
5271 free(AH->currUser);
5272 free(AH->currSchema);
5273 free(AH->currTablespace);
5274 free(AH->currTableAm);
5275 free(AH->savedPassword);
5276
5277 free(AH);
5278}
void destroyPQExpBuffer(PQExpBuffer str)
#define free(a)
DeClonePtrType DeClonePtr
sqlparseInfo sqlparse

References Assert, _archiveHandle::connection, sqlparseInfo::curCmd, _archiveHandle::currSchema, _archiveHandle::currTableAm, _archiveHandle::currTablespace, _archiveHandle::currUser, _archiveHandle::DeClonePtr, destroyPQExpBuffer(), fb(), free, _archiveHandle::savedPassword, and _archiveHandle::sqlparse.

Referenced by RunWorker().

◆ DropLOIfExists()

void DropLOIfExists ( ArchiveHandle AH,
Oid  oid 
)
extern

Definition at line 612 of file pg_backup_db.c.

613{
614 ahprintf(AH,
615 "SELECT pg_catalog.lo_unlink(oid) "
616 "FROM pg_catalog.pg_largeobject_metadata "
617 "WHERE oid = '%u';\n",
618 oid);
619}
int ahprintf(ArchiveHandle *AH, const char *fmt,...)

References ahprintf().

Referenced by _StartLO(), RestoreArchive(), and StartRestoreLO().

◆ EndRestoreLO()

void EndRestoreLO ( ArchiveHandle AH,
Oid  oid 
)
extern

Definition at line 1562 of file pg_backup_archiver.c.

1563{
1564 if (AH->lo_buf_used > 0)
1565 {
1566 /* Write remaining bytes from the LO buffer */
1567 dump_lo_buf(AH);
1568 }
1569
1570 AH->writingLO = false;
1571
1572 if (AH->connection)
1573 {
1574 lo_close(AH->connection, AH->loFd);
1575 AH->loFd = -1;
1576 }
1577 else
1578 {
1579 ahprintf(AH, "SELECT pg_catalog.lo_close(0);\n\n");
1580 }
1581}
int lo_close(PGconn *conn, int fd)
Definition fe-lobj.c:96

References ahprintf(), _archiveHandle::connection, dump_lo_buf(), _archiveHandle::lo_buf_used, lo_close(), _archiveHandle::loFd, and _archiveHandle::writingLO.

Referenced by _LoadLOs(), _LoadLOs(), and _LoadLOs().

◆ EndRestoreLOs()

void EndRestoreLOs ( ArchiveHandle AH)
extern

Definition at line 1489 of file pg_backup_archiver.c.

1490{
1491 RestoreOptions *ropt = AH->public.ropt;
1492
1493 if (!(ropt->single_txn || ropt->txn_size > 0))
1494 {
1495 if (AH->connection)
1497 else
1498 ahprintf(AH, "COMMIT;\n\n");
1499 }
1500
1501 pg_log_info(ngettext("restored %d large object",
1502 "restored %d large objects",
1503 AH->loCount),
1504 AH->loCount);
1505}
#define ngettext(s, p, n)
Definition c.h:1198
#define pg_log_info(...)
Definition logging.h:124
static void CommitTransaction(void)
Definition xact.c:2241

References ahprintf(), CommitTransaction(), _archiveHandle::connection, _archiveHandle::loCount, ngettext, pg_log_info, _archiveHandle::public, Archive::ropt, _restoreOptions::single_txn, and _restoreOptions::txn_size.

Referenced by _LoadLOs(), _LoadLOs(), and _LoadLOs().

◆ getTocEntryByDumpId()

TocEntry * getTocEntryByDumpId ( ArchiveHandle AH,
DumpId  id 
)

Definition at line 2051 of file pg_backup_archiver.c.

2052{
2053 /* build index arrays if we didn't already */
2054 if (AH->tocsByDumpId == NULL)
2056
2057 if (id > 0 && id <= AH->maxDumpId)
2058 return AH->tocsByDumpId[id];
2059
2060 return NULL;
2061}
static void buildTocEntryArrays(ArchiveHandle *AH)
struct _tocEntry ** tocsByDumpId

References buildTocEntryArrays(), fb(), and _archiveHandle::tocsByDumpId.

Referenced by _PrintTocData(), _tocEntryRequired(), IssueACLPerBlob(), parseWorkerCommand(), SortTocFromFile(), and TocIDRequired().

◆ InitArchiveFmt_Custom()

void InitArchiveFmt_Custom ( ArchiveHandle AH)
extern

Definition at line 105 of file pg_backup_custom.c.

106{
107 lclContext *ctx;
108
109 /* Assuming static functions, this can be copied for each format. */
113 AH->EndDataPtr = _EndData;
117 AH->ReadBufPtr = _ReadBuf;
124
126 AH->StartLOPtr = _StartLO;
127 AH->EndLOPtr = _EndLO;
128 AH->EndLOsPtr = _EndLOs;
129
131 AH->ClonePtr = _Clone;
132 AH->DeClonePtr = _DeClone;
133
134 /* no parallel dump in the custom archive, only parallel restore */
137
138 /* Set up a private area. */
140 AH->formatData = ctx;
141
142 /*
143 * Now open the file
144 */
145 if (AH->mode == archModeWrite)
146 {
147 if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
148 {
149 AH->FH = fopen(AH->fSpec, PG_BINARY_W);
150 if (!AH->FH)
151 pg_fatal("could not open output file \"%s\": %m", AH->fSpec);
152 }
153 else
154 {
155 AH->FH = stdout;
156 if (!AH->FH)
157 pg_fatal("could not open output file: %m");
158 }
159
160 ctx->hasSeek = checkSeek(AH->FH);
161 }
162 else
163 {
164 if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
165 {
166 AH->FH = fopen(AH->fSpec, PG_BINARY_R);
167 if (!AH->FH)
168 pg_fatal("could not open input file \"%s\": %m", AH->fSpec);
169 }
170 else
171 {
172 AH->FH = stdin;
173 if (!AH->FH)
174 pg_fatal("could not open input file: %m");
175 }
176
177 ctx->hasSeek = checkSeek(AH->FH);
178
179 ReadHead(AH);
180 ReadToc(AH);
181
182 /*
183 * Remember location of first data block (i.e., the point after TOC)
184 * in case we have to search for desired data blocks.
185 */
186 ctx->lastFilePos = _getFilePos(AH, ctx);
187 }
188}
#define PG_BINARY_R
Definition c.h:1311
#define PG_BINARY_W
Definition c.h:1312
@ archModeWrite
Definition pg_backup.h:51
bool checkSeek(FILE *fp)
void ReadHead(ArchiveHandle *AH)
void ReadToc(ArchiveHandle *AH)
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static pgoff_t _getFilePos(ArchiveHandle *AH, lclContext *ctx)
static void _DeClone(ArchiveHandle *AH)
static void _ReopenArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static int _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
static void _Clone(ArchiveHandle *AH)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
#define pg_fatal(...)
EndLOsPtrType EndLOsPtr
ReadExtraTocPtrType ReadExtraTocPtr
WorkerJobDumpPtrType WorkerJobDumpPtr
StartLOsPtrType StartLOsPtr
WriteDataPtrType WriteDataPtr
StartLOPtrType StartLOPtr
ClonePtrType ClonePtr
WriteBufPtrType WriteBufPtr
PrepParallelRestorePtrType PrepParallelRestorePtr
EndLOPtrType EndLOPtr
WriteExtraTocPtrType WriteExtraTocPtr
ReadBytePtrType ReadBytePtr
WorkerJobRestorePtrType WorkerJobRestorePtr
PrintTocDataPtrType PrintTocDataPtr
WriteBytePtrType WriteBytePtr
ReadBufPtrType ReadBufPtr
PrintExtraTocPtrType PrintExtraTocPtr
StartDataPtrType StartDataPtr
ReopenPtrType ReopenPtr
EndDataPtrType EndDataPtr
ClosePtrType ClosePtr
pgoff_t lastFilePos

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndData(), _EndLO(), _EndLOs(), _getFilePos(), _PrepParallelRestore(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartData(), _StartLO(), _StartLOs(), _WorkerJobRestoreCustom(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), _archiveHandle::ArchiveEntryPtr, archModeWrite, checkSeek(), _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, fb(), _archiveHandle::FH, _archiveHandle::formatData, _archiveHandle::fSpec, lclContext::hasSeek, lclContext::lastFilePos, _archiveHandle::mode, PG_BINARY_R, PG_BINARY_W, pg_fatal, pg_malloc0_object, _archiveHandle::PrepParallelRestorePtr, _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, _archiveHandle::StartDataPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

◆ InitArchiveFmt_Directory()

void InitArchiveFmt_Directory ( ArchiveHandle AH)
extern

Definition at line 110 of file pg_backup_directory.c.

111{
112 lclContext *ctx;
113
114 /* Assuming static functions, this can be copied for each format. */
118 AH->EndDataPtr = _EndData;
122 AH->ReadBufPtr = _ReadBuf;
129
131 AH->StartLOPtr = _StartLO;
132 AH->EndLOPtr = _EndLO;
133 AH->EndLOsPtr = _EndLOs;
134
136 AH->ClonePtr = _Clone;
137 AH->DeClonePtr = _DeClone;
138
141
142 /* Set up our private context */
144 AH->formatData = ctx;
145
146 ctx->dataFH = NULL;
147 ctx->LOsTocFH = NULL;
148
149 /*
150 * Now open the TOC file
151 */
152
153 if (!AH->fSpec || strcmp(AH->fSpec, "") == 0)
154 pg_fatal("no output directory specified");
155
156 ctx->directory = AH->fSpec;
157
158 if (AH->mode == archModeWrite)
159 {
160 /* we accept an empty existing directory */
162 }
163 else
164 { /* Read Mode */
165 char fname[MAXPGPATH];
167
168 setFilePath(AH, fname, "toc.dat");
169
171 if (tocFH == NULL)
172 pg_fatal("could not open input file \"%s\": %m", fname);
173
174 ctx->dataFH = tocFH;
175
176 /*
177 * The TOC of a directory format dump shares the format code of the
178 * tar format.
179 */
180 AH->format = archTar;
181 ReadHead(AH);
182 AH->format = archDirectory;
183 ReadToc(AH);
184
185 /* Nothing else in the file, so close it again... */
187 pg_fatal("could not close TOC file: %m");
188 ctx->dataFH = NULL;
189 }
190}
bool EndCompressFileHandle(CompressFileHandle *CFH)
CompressFileHandle * InitDiscoverCompressFileHandle(const char *path, const char *mode)
void create_or_open_dir(const char *dirname)
Definition dumputils.c:940
@ archTar
Definition pg_backup.h:43
@ archDirectory
Definition pg_backup.h:45
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static void _DeClone(ArchiveHandle *AH)
static void _ReopenArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _PrepParallelRestore(ArchiveHandle *AH)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _Clone(ArchiveHandle *AH)
static int _WorkerJobRestoreDirectory(ArchiveHandle *AH, TocEntry *te)
static void setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename)
static int _WorkerJobDumpDirectory(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
#define MAXPGPATH
ArchiveFormat format
CompressFileHandle * LOsTocFH
CompressFileHandle * dataFH

References _ArchiveEntry(), _Clone(), _CloseArchive(), _DeClone(), _EndData(), _EndLO(), _EndLOs(), _PrepParallelRestore(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _ReopenArchive(), _StartData(), _StartLO(), _StartLOs(), _WorkerJobDumpDirectory(), _WorkerJobRestoreDirectory(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archDirectory, _archiveHandle::ArchiveEntryPtr, archModeWrite, archTar, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, create_or_open_dir(), lclContext::dataFH, _archiveHandle::DeClonePtr, lclContext::directory, EndCompressFileHandle(), _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, fb(), _archiveHandle::format, _archiveHandle::formatData, _archiveHandle::fSpec, InitDiscoverCompressFileHandle(), lclContext::LOsTocFH, MAXPGPATH, _archiveHandle::mode, PG_BINARY_R, pg_fatal, pg_malloc0_object, _archiveHandle::PrepParallelRestorePtr, _archiveHandle::PrintExtraTocPtr, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::ReadExtraTocPtr, ReadHead(), ReadToc(), _archiveHandle::ReopenPtr, setFilePath(), _archiveHandle::StartDataPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WorkerJobDumpPtr, _archiveHandle::WorkerJobRestorePtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, _archiveHandle::WriteDataPtr, and _archiveHandle::WriteExtraTocPtr.

Referenced by _allocAH().

◆ InitArchiveFmt_Null()

void InitArchiveFmt_Null ( ArchiveHandle AH)
extern

Definition at line 48 of file pg_backup_null.c.

49{
50 /* Assuming static functions, this can be copied for each format. */
52 AH->EndDataPtr = _EndData;
56 AH->ReopenPtr = NULL;
58
60 AH->StartLOPtr = _StartLO;
61 AH->EndLOPtr = _EndLO;
62 AH->EndLOsPtr = _EndLOs;
63 AH->ClonePtr = NULL;
64 AH->DeClonePtr = NULL;
65
66 /*
67 * Now prevent reading...
68 */
69 if (AH->mode == archModeRead)
70 pg_fatal("this format cannot be read");
71}
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _CloseArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)

References _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _PrintTocData(), _StartLO(), _StartLOs(), _WriteBuf(), _WriteByte(), _WriteData(), archModeRead, _archiveHandle::ClonePtr, _archiveHandle::ClosePtr, _archiveHandle::DeClonePtr, _archiveHandle::EndDataPtr, _archiveHandle::EndLOPtr, _archiveHandle::EndLOsPtr, fb(), _archiveHandle::mode, pg_fatal, _archiveHandle::PrintTocDataPtr, _archiveHandle::ReopenPtr, _archiveHandle::StartLOPtr, _archiveHandle::StartLOsPtr, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, and _archiveHandle::WriteDataPtr.

Referenced by _allocAH().

◆ InitArchiveFmt_Tar()

void InitArchiveFmt_Tar ( ArchiveHandle AH)
extern

Definition at line 121 of file pg_backup_tar.c.

122{
123 lclContext *ctx;
124
125 /* Assuming static functions, this can be copied for each format. */
129 AH->EndDataPtr = _EndData;
133 AH->ReadBufPtr = _ReadBuf;
135 AH->ReopenPtr = NULL;
140
142 AH->StartLOPtr = _StartLO;
143 AH->EndLOPtr = _EndLO;
144 AH->EndLOsPtr = _EndLOs;
145 AH->ClonePtr = NULL;
146 AH->DeClonePtr = NULL;
147
150
151 /*
152 * Set up some special context used in compressing data.
153 */
155 AH->formatData = ctx;
156 ctx->filePos = 0;
157 ctx->isSpecialScript = 0;
158
159 /*
160 * Now open the tar file, and load the TOC if we're in read mode.
161 */
162 if (AH->mode == archModeWrite)
163 {
164 if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
165 {
166 ctx->tarFH = fopen(AH->fSpec, PG_BINARY_W);
167 if (ctx->tarFH == NULL)
168 pg_fatal("could not open TOC file \"%s\" for output: %m",
169 AH->fSpec);
170 }
171 else
172 {
173 ctx->tarFH = stdout;
174 if (ctx->tarFH == NULL)
175 pg_fatal("could not open TOC file for output: %m");
176 }
177
178 ctx->tarFHpos = 0;
179
180 /*
181 * Make unbuffered since we will dup() it, and the buffers screw each
182 * other
183 */
184 /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
185
186 ctx->hasSeek = checkSeek(ctx->tarFH);
187
188 /*
189 * We don't support compression because reading the files back is not
190 * possible since gzdopen uses buffered IO which totally screws file
191 * positioning.
192 */
194 pg_fatal("compression is not supported by tar archive format");
195 }
196 else
197 { /* Read Mode */
198 if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
199 {
200 ctx->tarFH = fopen(AH->fSpec, PG_BINARY_R);
201 if (ctx->tarFH == NULL)
202 pg_fatal("could not open TOC file \"%s\" for input: %m",
203 AH->fSpec);
204 }
205 else
206 {
207 ctx->tarFH = stdin;
208 if (ctx->tarFH == NULL)
209 pg_fatal("could not open TOC file for input: %m");
210 }
211
212 /*
213 * Make unbuffered since we will dup() it, and the buffers screw each
214 * other
215 */
216 /* setvbuf(ctx->tarFH, NULL, _IONBF, 0); */
217
218 ctx->tarFHpos = 0;
219
220 ctx->hasSeek = checkSeek(ctx->tarFH);
221
222 ctx->FH = tarOpen(AH, "toc.dat", 'r');
223 ReadHead(AH);
224 ReadToc(AH);
225 tarClose(AH, ctx->FH); /* Nothing else in the file... */
226 }
227}
@ PG_COMPRESSION_NONE
Definition compression.h:23
static void _PrintTocData(ArchiveHandle *AH, TocEntry *te)
static void _StartData(ArchiveHandle *AH, TocEntry *te)
static void _PrintExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
static void _CloseArchive(ArchiveHandle *AH)
static void _StartLOs(ArchiveHandle *AH, TocEntry *te)
static void _WriteExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _EndLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static void _EndLOs(ArchiveHandle *AH, TocEntry *te)
static int _WriteByte(ArchiveHandle *AH, const int i)
static void _StartLO(ArchiveHandle *AH, TocEntry *te, Oid oid)
static int _ReadByte(ArchiveHandle *AH)
static void _ReadExtraToc(ArchiveHandle *AH, TocEntry *te)
static void _ReadBuf(ArchiveHandle *AH, void *buf, size_t len)
static TAR_MEMBER * tarOpen(ArchiveHandle *AH, const char *filename, char mode)
static void _EndData(ArchiveHandle *AH, TocEntry *te)
static void _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
static void tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
pg_compress_specification compression_spec
pgoff_t filePos
pgoff_t tarFHpos
TAR_MEMBER * FH
int isSpecialScript
pg_compress_algorithm algorithm
Definition compression.h:34

References _ArchiveEntry(), _CloseArchive(), _EndData(), _EndLO(), _EndLOs(), _PrintExtraToc(), _PrintTocData(), _ReadBuf(), _ReadByte(), _ReadExtraToc(), _StartData(), _StartLO(), _StartLOs(), _WriteBuf(), _WriteByte(), _WriteData(), _WriteExtraToc(), archModeWrite, checkSeek(), fb(), lclContext::FH, lclContext::filePos, lclContext::hasSeek, lclContext::isSpecialScript, PG_BINARY_R, PG_BINARY_W, PG_COMPRESSION_NONE, pg_fatal, pg_malloc0_object, ReadHead(), ReadToc(), tarClose(), lclContext::tarFH, lclContext::tarFHpos, and tarOpen().

Referenced by _allocAH().

◆ IssueACLPerBlob()

void IssueACLPerBlob ( ArchiveHandle AH,
TocEntry te 
)
extern

Definition at line 538 of file pg_backup_db.c.

539{
541 char *buf;
542 char *st;
543 char *st2;
544 char *en;
545 bool inquotes;
546
547 if (!blobte)
548 pg_fatal("could not find entry for ID %d", te->dependencies[0]);
549 Assert(strcmp(blobte->desc, "BLOB METADATA") == 0);
550
551 /* Make a writable copy of the ACL commands string */
552 buf = pg_strdup(te->defn);
553
554 /*
555 * We have to parse out the commands sufficiently to locate the blob OIDs
556 * and find the command-ending semicolons. The commands should not
557 * contain anything hard to parse except for double-quoted role names,
558 * which are easy to ignore. Once we've split apart the first and second
559 * halves of a command, apply IssueCommandPerBlob. (This means the
560 * updates on the blobs are interleaved if there's multiple commands, but
561 * that should cause no trouble.)
562 */
563 inquotes = false;
564 st = en = buf;
565 st2 = NULL;
566 while (*en)
567 {
568 /* Ignore double-quoted material */
569 if (*en == '"')
571 if (inquotes)
572 {
573 en++;
574 continue;
575 }
576 /* If we found "LARGE OBJECT", that's the end of the first half */
577 if (strncmp(en, "LARGE OBJECT ", 13) == 0)
578 {
579 /* Terminate the first-half string */
580 en += 13;
581 Assert(isdigit((unsigned char) *en));
582 *en++ = '\0';
583 /* Skip the rest of the blob OID */
584 while (isdigit((unsigned char) *en))
585 en++;
586 /* Second half starts here */
587 Assert(st2 == NULL);
588 st2 = en;
589 }
590 /* If we found semicolon, that's the end of the second half */
591 else if (*en == ';')
592 {
593 /* Terminate the second-half string */
594 *en++ = '\0';
595 Assert(st2 != NULL);
596 /* Issue this command for each blob */
598 /* For neatness, skip whitespace before the next command */
599 while (isspace((unsigned char) *en))
600 en++;
601 /* Reset for new command */
602 st = en;
603 st2 = NULL;
604 }
605 else
606 en++;
607 }
608 pg_free(buf);
609}
void pg_free(void *ptr)
TocEntry * getTocEntryByDumpId(ArchiveHandle *AH, DumpId id)
void IssueCommandPerBlob(ArchiveHandle *AH, TocEntry *te, const char *cmdBegin, const char *cmdEnd)
static char buf[DEFAULT_XLOG_SEG_SIZE]
DumpId * dependencies

References Assert, buf, _tocEntry::defn, _tocEntry::dependencies, fb(), getTocEntryByDumpId(), IssueCommandPerBlob(), pg_fatal, pg_free(), and pg_strdup().

Referenced by _printTocEntry().

◆ IssueCommandPerBlob()

void IssueCommandPerBlob ( ArchiveHandle AH,
TocEntry te,
const char cmdBegin,
const char cmdEnd 
)
extern

Definition at line 491 of file pg_backup_db.c.

493{
494 /* Make a writable copy of the command string */
495 char *buf = pg_strdup(te->defn);
496 RestoreOptions *ropt = AH->public.ropt;
497 char *st;
498 char *en;
499
500 st = buf;
501 while ((en = strchr(st, '\n')) != NULL)
502 {
503 *en++ = '\0';
504 ahprintf(AH, "%s%s%s;\n", cmdBegin, st, cmdEnd);
505
506 /* In --transaction-size mode, count each command as an action */
507 if (ropt && ropt->txn_size > 0)
508 {
509 if (++AH->txnCount >= ropt->txn_size)
510 {
511 if (AH->connection)
512 {
515 }
516 else
517 ahprintf(AH, "COMMIT;\nBEGIN;\n\n");
518 AH->txnCount = 0;
519 }
520 }
521
522 st = en;
523 }
524 ahprintf(AH, "\n");
525 pg_free(buf);
526}
static void StartTransaction(void)
Definition xact.c:2077

References ahprintf(), buf, CommitTransaction(), _archiveHandle::connection, _tocEntry::defn, fb(), pg_free(), pg_strdup(), _archiveHandle::public, Archive::ropt, StartTransaction(), _restoreOptions::txn_size, and _archiveHandle::txnCount.

Referenced by _printTocEntry(), IssueACLPerBlob(), and RestoreArchive().

◆ isValidTarHeader()

bool isValidTarHeader ( char header)
extern

Definition at line 988 of file pg_backup_tar.c.

989{
990 int sum;
991 int chk = tarChecksum(header);
992
993 sum = read_tar_number(&header[TAR_OFFSET_CHECKSUM], 8);
994
995 if (sum != chk)
996 return false;
997
998 /* POSIX tar format */
999 if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar\0", 6) == 0 &&
1000 memcmp(&header[TAR_OFFSET_VERSION], "00", 2) == 0)
1001 return true;
1002 /* GNU tar format */
1003 if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar \0", 8) == 0)
1004 return true;
1005 /* not-quite-POSIX format written by pre-9.3 pg_dump */
1006 if (memcmp(&header[TAR_OFFSET_MAGIC], "ustar00\0", 8) == 0)
1007 return true;
1008
1009 return false;
1010}
uint64 read_tar_number(const char *s, int len)
Definition tar.c:58
int tarChecksum(char *header)
Definition tar.c:90
@ TAR_OFFSET_VERSION
Definition pgtar.h:49
@ TAR_OFFSET_CHECKSUM
Definition pgtar.h:45
@ TAR_OFFSET_MAGIC
Definition pgtar.h:48

References fb(), read_tar_number(), TAR_OFFSET_CHECKSUM, TAR_OFFSET_MAGIC, TAR_OFFSET_VERSION, and tarChecksum().

Referenced by _discoverArchiveFormat().

◆ on_exit_close_archive()

void on_exit_close_archive ( Archive AHX)
extern

Definition at line 330 of file parallel.c.

331{
332 shutdown_info.AHX = AHX;
334}
static void archive_close_connection(int code, void *arg)
Definition parallel.c:355
static ShutdownInformation shutdown_info
Definition parallel.c:154
void on_exit_nicely(on_exit_nicely_callback function, void *arg)

References ShutdownInformation::AHX, archive_close_connection(), on_exit_nicely(), and shutdown_info.

Referenced by main(), main(), restore_global_objects(), and restore_one_database().

◆ parallel_restore()

int parallel_restore ( ArchiveHandle AH,
TocEntry te 
)
extern

Definition at line 4827 of file pg_backup_archiver.c.

4828{
4829 int status;
4830
4831 Assert(AH->connection != NULL);
4832
4833 /* Count only errors associated with this TOC entry */
4834 AH->public.n_errors = 0;
4835
4836 /* Restore the TOC item */
4837 status = restore_toc_entry(AH, te, true);
4838
4839 return status;
4840}
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, bool is_parallel)
int n_errors
Definition pg_backup.h:253

References Assert, _archiveHandle::connection, fb(), Archive::n_errors, _archiveHandle::public, and restore_toc_entry().

Referenced by _WorkerJobRestoreCustom(), and _WorkerJobRestoreDirectory().

◆ ReadHead()

void ReadHead ( ArchiveHandle AH)
extern

Definition at line 4194 of file pg_backup_archiver.c.

4195{
4196 char *errmsg;
4197 char vmaj,
4198 vmin,
4199 vrev;
4200 int fmt;
4201
4202 /*
4203 * If we haven't already read the header, do so.
4204 *
4205 * NB: this code must agree with _discoverArchiveFormat(). Maybe find a
4206 * way to unify the cases?
4207 */
4208 if (!AH->readHeader)
4209 {
4210 char tmpMag[7];
4211
4212 AH->ReadBufPtr(AH, tmpMag, 5);
4213
4214 if (strncmp(tmpMag, "PGDMP", 5) != 0)
4215 pg_fatal("did not find magic string in file header");
4216 }
4217
4218 vmaj = AH->ReadBytePtr(AH);
4219 vmin = AH->ReadBytePtr(AH);
4220
4221 if (vmaj > 1 || (vmaj == 1 && vmin > 0)) /* Version > 1.0 */
4222 vrev = AH->ReadBytePtr(AH);
4223 else
4224 vrev = 0;
4225
4227
4228 if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
4229 pg_fatal("unsupported version (%d.%d) in file header",
4230 vmaj, vmin);
4231
4232 AH->intSize = AH->ReadBytePtr(AH);
4233 if (AH->intSize > 32)
4234 pg_fatal("sanity check on integer size (%zu) failed", AH->intSize);
4235
4236 if (AH->intSize > sizeof(int))
4237 pg_log_warning("archive was made on a machine with larger integers, some operations might fail");
4238
4239 if (AH->version >= K_VERS_1_7)
4240 AH->offSize = AH->ReadBytePtr(AH);
4241 else
4242 AH->offSize = AH->intSize;
4243
4244 fmt = AH->ReadBytePtr(AH);
4245
4246 if (AH->format != fmt)
4247 pg_fatal("expected format (%d) differs from format found in file (%d)",
4248 AH->format, fmt);
4249
4250 if (AH->version >= K_VERS_1_15)
4252 else if (AH->version >= K_VERS_1_2)
4253 {
4254 /* Guess the compression method based on the level */
4255 if (AH->version < K_VERS_1_4)
4256 AH->compression_spec.level = AH->ReadBytePtr(AH);
4257 else
4258 AH->compression_spec.level = ReadInt(AH);
4259
4260 if (AH->compression_spec.level != 0)
4262 }
4263 else
4265
4267 if (errmsg)
4268 {
4269 pg_log_warning("archive is compressed, but this installation does not support compression (%s) -- no data will be available",
4270 errmsg);
4271 pg_free(errmsg);
4272 }
4273
4274 if (AH->version >= K_VERS_1_4)
4275 {
4276 struct tm crtm;
4277
4278 crtm.tm_sec = ReadInt(AH);
4279 crtm.tm_min = ReadInt(AH);
4280 crtm.tm_hour = ReadInt(AH);
4281 crtm.tm_mday = ReadInt(AH);
4282 crtm.tm_mon = ReadInt(AH);
4283 crtm.tm_year = ReadInt(AH);
4284 crtm.tm_isdst = ReadInt(AH);
4285
4286 /*
4287 * Newer versions of glibc have mktime() report failure if tm_isdst is
4288 * inconsistent with the prevailing timezone, e.g. tm_isdst = 1 when
4289 * TZ=UTC. This is problematic when restoring an archive under a
4290 * different timezone setting. If we get a failure, try again with
4291 * tm_isdst set to -1 ("don't know").
4292 *
4293 * XXX with or without this hack, we reconstruct createDate
4294 * incorrectly when the prevailing timezone is different from
4295 * pg_dump's. Next time we bump the archive version, we should flush
4296 * this representation and store a plain seconds-since-the-Epoch
4297 * timestamp instead.
4298 */
4299 AH->createDate = mktime(&crtm);
4300 if (AH->createDate == (time_t) -1)
4301 {
4302 crtm.tm_isdst = -1;
4303 AH->createDate = mktime(&crtm);
4304 if (AH->createDate == (time_t) -1)
4305 pg_log_warning("invalid creation date in header");
4306 }
4307 }
4308
4309 if (AH->version >= K_VERS_1_4)
4310 {
4311 AH->archdbname = ReadStr(AH);
4312 }
4313
4314 if (AH->version >= K_VERS_1_10)
4315 {
4316 AH->archiveRemoteVersion = ReadStr(AH);
4317 AH->archiveDumpVersion = ReadStr(AH);
4318 }
4319}
char * supports_compression(const pg_compress_specification compression_spec)
Definition compress_io.c:87
@ PG_COMPRESSION_GZIP
Definition compression.h:24
int errmsg(const char *fmt,...)
Definition elog.c:1093
static struct pg_tm tm
Definition localtime.c:104
char * ReadStr(ArchiveHandle *AH)
int ReadInt(ArchiveHandle *AH)
#define K_VERS_1_15
#define K_VERS_1_10
#define K_VERS_1_2
#define K_VERS_1_4
#define K_VERS_1_0
#define K_VERS_MAX
#define K_VERS_1_7
#define pg_log_warning(...)
Definition pgfnames.c:24
int tm_sec
Definition pgtime.h:36

References pg_compress_specification::algorithm, _archiveHandle::archdbname, _archiveHandle::archiveDumpVersion, _archiveHandle::archiveRemoteVersion, _archiveHandle::compression_spec, _archiveHandle::createDate, errmsg(), fb(), _archiveHandle::format, _archiveHandle::intSize, K_VERS_1_0, K_VERS_1_10, K_VERS_1_15, K_VERS_1_2, K_VERS_1_4, K_VERS_1_7, K_VERS_MAX, pg_compress_specification::level, MAKE_ARCHIVE_VERSION, _archiveHandle::offSize, PG_COMPRESSION_GZIP, pg_fatal, pg_free(), pg_log_warning, _archiveHandle::ReadBufPtr, _archiveHandle::ReadBytePtr, _archiveHandle::readHeader, ReadInt(), ReadStr(), supports_compression(), tm, pg_tm::tm_sec, and _archiveHandle::version.

Referenced by InitArchiveFmt_Custom(), InitArchiveFmt_Directory(), and InitArchiveFmt_Tar().

◆ ReadInt()

int ReadInt ( ArchiveHandle AH)
extern

Definition at line 2187 of file pg_backup_archiver.c.

2188{
2189 int res = 0;
2190 int bv,
2191 b;
2192 int sign = 0; /* Default positive */
2193 int bitShift = 0;
2194
2195 if (AH->version > K_VERS_1_0)
2196 /* Read a sign byte */
2197 sign = AH->ReadBytePtr(AH);
2198
2199 for (b = 0; b < AH->intSize; b++)
2200 {
2201 bv = AH->ReadBytePtr(AH) & 0xFF;
2202 if (bv != 0)
2203 res = res + (bv << bitShift);
2204 bitShift += 8;
2205 }
2206
2207 if (sign)
2208 res = -res;
2209
2210 return res;
2211}
char sign
Definition informix.c:693
int b
Definition isn.c:74

References b, fb(), _archiveHandle::intSize, K_VERS_1_0, _archiveHandle::ReadBytePtr, sign, and _archiveHandle::version.

Referenced by _CustomReadFunc(), _LoadLOs(), _readBlockHeader(), _ReadExtraToc(), _skipData(), _skipLOs(), ReadHead(), ReadOffset(), ReadStr(), and ReadToc().

◆ ReadOffset()

int ReadOffset ( ArchiveHandle AH,
pgoff_t o 
)

Definition at line 2092 of file pg_backup_archiver.c.

2093{
2094 int i;
2095 int off;
2096 int offsetFlg;
2097
2098 /* Initialize to zero */
2099 *o = 0;
2100
2101 /* Check for old version */
2102 if (AH->version < K_VERS_1_7)
2103 {
2104 /* Prior versions wrote offsets using WriteInt */
2105 i = ReadInt(AH);
2106 /* -1 means not set */
2107 if (i < 0)
2108 return K_OFFSET_POS_NOT_SET;
2109 else if (i == 0)
2110 return K_OFFSET_NO_DATA;
2111
2112 /* Cast to pgoff_t because it was written as an int. */
2113 *o = (pgoff_t) i;
2114 return K_OFFSET_POS_SET;
2115 }
2116
2117 /*
2118 * Read the flag indicating the state of the data pointer. Check if valid
2119 * and die if not.
2120 *
2121 * This used to be handled by a negative or zero pointer, now we use an
2122 * extra byte specifically for the state.
2123 */
2124 offsetFlg = AH->ReadBytePtr(AH) & 0xFF;
2125
2126 switch (offsetFlg)
2127 {
2129 case K_OFFSET_NO_DATA:
2130 case K_OFFSET_POS_SET:
2131
2132 break;
2133
2134 default:
2135 pg_fatal("unexpected data offset flag %d", offsetFlg);
2136 }
2137
2138 /*
2139 * Read the bytes
2140 */
2141 for (off = 0; off < AH->offSize; off++)
2142 {
2143 if (off < sizeof(pgoff_t))
2144 *o |= ((pgoff_t) (AH->ReadBytePtr(AH))) << (off * 8);
2145 else
2146 {
2147 if (AH->ReadBytePtr(AH) != 0)
2148 pg_fatal("file offset in dump file is too large");
2149 }
2150 }
2151
2152 return offsetFlg;
2153}
int i
Definition isn.c:77
#define K_OFFSET_NO_DATA
#define K_OFFSET_POS_NOT_SET
#define K_OFFSET_POS_SET

References fb(), i, K_OFFSET_NO_DATA, K_OFFSET_POS_NOT_SET, K_OFFSET_POS_SET, K_VERS_1_7, _archiveHandle::offSize, pg_fatal, _archiveHandle::ReadBytePtr, ReadInt(), and _archiveHandle::version.

Referenced by _ReadExtraToc().

◆ ReadStr()

char * ReadStr ( ArchiveHandle AH)
extern

Definition at line 2233 of file pg_backup_archiver.c.

2234{
2235 char *buf;
2236 int l;
2237
2238 l = ReadInt(AH);
2239 if (l < 0)
2240 buf = NULL;
2241 else
2242 {
2243 buf = (char *) pg_malloc(l + 1);
2244 AH->ReadBufPtr(AH, buf, l);
2245
2246 buf[l] = '\0';
2247 }
2248
2249 return buf;
2250}
void * pg_malloc(size_t size)
Definition fe_memutils.c:47

References buf, fb(), pg_malloc(), _archiveHandle::ReadBufPtr, and ReadInt().

Referenced by _ReadExtraToc(), _ReadExtraToc(), ReadHead(), and ReadToc().

◆ ReadToc()

void ReadToc ( ArchiveHandle AH)
extern

Definition at line 2730 of file pg_backup_archiver.c.

2731{
2732 int i;
2733 char *tmp;
2734 DumpId *deps;
2735 int depIdx;
2736 int depSize;
2737 TocEntry *te;
2738 bool is_supported;
2739
2740 AH->tocCount = ReadInt(AH);
2741 AH->maxDumpId = 0;
2742
2743 for (i = 0; i < AH->tocCount; i++)
2744 {
2746 te->dumpId = ReadInt(AH);
2747
2748 if (te->dumpId > AH->maxDumpId)
2749 AH->maxDumpId = te->dumpId;
2750
2751 /* Sanity check */
2752 if (te->dumpId <= 0)
2753 pg_fatal("entry ID %d out of range -- perhaps a corrupt TOC",
2754 te->dumpId);
2755
2756 te->hadDumper = ReadInt(AH);
2757
2758 if (AH->version >= K_VERS_1_8)
2759 {
2760 tmp = ReadStr(AH);
2761 sscanf(tmp, "%u", &te->catalogId.tableoid);
2762 free(tmp);
2763 }
2764 else
2766 tmp = ReadStr(AH);
2767 sscanf(tmp, "%u", &te->catalogId.oid);
2768 free(tmp);
2769
2770 te->tag = ReadStr(AH);
2771 te->desc = ReadStr(AH);
2772
2773 if (AH->version >= K_VERS_1_11)
2774 {
2775 te->section = ReadInt(AH);
2776 }
2777 else
2778 {
2779 /*
2780 * Rules for pre-8.4 archives wherein pg_dump hasn't classified
2781 * the entries into sections. This list need not cover entry
2782 * types added later than 8.4.
2783 */
2784 if (strcmp(te->desc, "COMMENT") == 0 ||
2785 strcmp(te->desc, "ACL") == 0 ||
2786 strcmp(te->desc, "ACL LANGUAGE") == 0)
2787 te->section = SECTION_NONE;
2788 else if (strcmp(te->desc, "TABLE DATA") == 0 ||
2789 strcmp(te->desc, "BLOBS") == 0 ||
2790 strcmp(te->desc, "BLOB COMMENTS") == 0)
2791 te->section = SECTION_DATA;
2792 else if (strcmp(te->desc, "CONSTRAINT") == 0 ||
2793 strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
2794 strcmp(te->desc, "FK CONSTRAINT") == 0 ||
2795 strcmp(te->desc, "INDEX") == 0 ||
2796 strcmp(te->desc, "RULE") == 0 ||
2797 strcmp(te->desc, "TRIGGER") == 0)
2799 else
2801 }
2802
2803 te->defn = ReadStr(AH);
2804 te->dropStmt = ReadStr(AH);
2805
2806 if (AH->version >= K_VERS_1_3)
2807 te->copyStmt = ReadStr(AH);
2808
2809 if (AH->version >= K_VERS_1_6)
2810 te->namespace = ReadStr(AH);
2811
2812 if (AH->version >= K_VERS_1_10)
2813 te->tablespace = ReadStr(AH);
2814
2815 if (AH->version >= K_VERS_1_14)
2816 te->tableam = ReadStr(AH);
2817
2818 if (AH->version >= K_VERS_1_16)
2819 te->relkind = ReadInt(AH);
2820
2821 te->owner = ReadStr(AH);
2822 is_supported = true;
2823 if (AH->version < K_VERS_1_9)
2824 is_supported = false;
2825 else
2826 {
2827 tmp = ReadStr(AH);
2828
2829 if (strcmp(tmp, "true") == 0)
2830 is_supported = false;
2831
2832 free(tmp);
2833 }
2834
2835 if (!is_supported)
2836 pg_log_warning("restoring tables WITH OIDS is not supported anymore");
2837
2838 /* Read TOC entry dependencies */
2839 if (AH->version >= K_VERS_1_5)
2840 {
2841 depSize = 100;
2843 depIdx = 0;
2844 for (;;)
2845 {
2846 tmp = ReadStr(AH);
2847 if (!tmp)
2848 break; /* end of list */
2849 if (depIdx >= depSize)
2850 {
2851 depSize *= 2;
2852 deps = pg_realloc_array(deps, DumpId, depSize);
2853 }
2854 sscanf(tmp, "%d", &deps[depIdx]);
2855 free(tmp);
2856 depIdx++;
2857 }
2858
2859 if (depIdx > 0) /* We have a non-null entry */
2860 {
2861 deps = pg_realloc_array(deps, DumpId, depIdx);
2862 te->dependencies = deps;
2863 te->nDeps = depIdx;
2864 }
2865 else
2866 {
2867 free(deps);
2868 te->dependencies = NULL;
2869 te->nDeps = 0;
2870 }
2871 }
2872 else
2873 {
2874 te->dependencies = NULL;
2875 te->nDeps = 0;
2876 }
2877 te->dataLength = 0;
2878
2879 if (AH->ReadExtraTocPtr)
2880 AH->ReadExtraTocPtr(AH, te);
2881
2882 pg_log_debug("read TOC entry %d (ID %d) for %s %s",
2883 i, te->dumpId, te->desc, te->tag);
2884
2885 /* link completed entry into TOC circular list */
2886 te->prev = AH->toc->prev;
2887 AH->toc->prev->next = te;
2888 AH->toc->prev = te;
2889 te->next = AH->toc;
2890
2891 /* special processing immediately upon read for some items */
2892 if (strcmp(te->desc, "ENCODING") == 0)
2893 processEncodingEntry(AH, te);
2894 else if (strcmp(te->desc, "STDSTRINGS") == 0)
2895 processStdStringsEntry(AH, te);
2896 else if (strcmp(te->desc, "SEARCHPATH") == 0)
2897 processSearchPathEntry(AH, te);
2898 }
2899}
#define pg_realloc_array(pointer, type, count)
Definition fe_memutils.h:63
#define pg_log_debug(...)
Definition logging.h:133
@ SECTION_NONE
Definition pg_backup.h:57
@ SECTION_POST_DATA
Definition pg_backup.h:60
@ SECTION_PRE_DATA
Definition pg_backup.h:58
@ SECTION_DATA
Definition pg_backup.h:59
static void processEncodingEntry(ArchiveHandle *AH, TocEntry *te)
static void processSearchPathEntry(ArchiveHandle *AH, TocEntry *te)
static void processStdStringsEntry(ArchiveHandle *AH, TocEntry *te)
#define K_VERS_1_14
#define K_VERS_1_5
#define K_VERS_1_6
#define K_VERS_1_8
#define K_VERS_1_11
#define K_VERS_1_9
#define K_VERS_1_16
#define K_VERS_1_3
#define InvalidOid
Oid tableoid
Definition pg_backup.h:281
teSection section

References _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::dataLength, _tocEntry::defn, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, fb(), free, _tocEntry::hadDumper, i, InvalidOid, K_VERS_1_10, K_VERS_1_11, K_VERS_1_14, K_VERS_1_16, K_VERS_1_3, K_VERS_1_5, K_VERS_1_6, K_VERS_1_8, K_VERS_1_9, _archiveHandle::maxDumpId, _tocEntry::nDeps, _tocEntry::next, CatalogId::oid, _tocEntry::owner, pg_fatal, pg_log_debug, pg_log_warning, pg_malloc0_object, pg_malloc_array, pg_realloc_array, _tocEntry::prev, processEncodingEntry(), processSearchPathEntry(), processStdStringsEntry(), _archiveHandle::ReadExtraTocPtr, ReadInt(), ReadStr(), _tocEntry::relkind, _tocEntry::section, SECTION_DATA, SECTION_NONE, SECTION_POST_DATA, SECTION_PRE_DATA, _tocEntry::tableam, CatalogId::tableoid, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::tocCount, and _archiveHandle::version.

Referenced by InitArchiveFmt_Custom(), InitArchiveFmt_Directory(), and InitArchiveFmt_Tar().

◆ ReconnectToServer()

void ReconnectToServer ( ArchiveHandle AH,
const char dbname 
)
extern

Definition at line 73 of file pg_backup_db.c.

74{
76 RestoreOptions *ropt = AH->public.ropt;
77
78 /*
79 * Save the dbname, if given, in override_dbname so that it will also
80 * affect any later reconnection attempt.
81 */
82 if (dbname)
84
85 /*
86 * Note: we want to establish the new connection, and in particular update
87 * ArchiveHandle's connCancel, before closing old connection. Otherwise
88 * an ill-timed SIGINT could try to access a dead connection.
89 */
90 AH->connection = NULL; /* dodge error check in ConnectDatabaseAhx */
91
92 ConnectDatabaseAhx((Archive *) AH, &ropt->cparams, true);
93
95}
void PQfinish(PGconn *conn)
void ConnectDatabaseAhx(Archive *AHX, const ConnParams *cparams, bool isReconnect)
char * dbname
Definition streamutil.c:49
char * override_dbname
Definition pg_backup.h:94
ConnParams cparams
Definition pg_backup.h:146

References ConnectDatabaseAhx(), _archiveHandle::connection, _restoreOptions::cparams, dbname, fb(), _connParams::override_dbname, pg_strdup(), PQfinish(), _archiveHandle::public, and Archive::ropt.

Referenced by _reconnectToDB().

◆ replace_on_exit_close_archive()

void replace_on_exit_close_archive ( Archive AHX)
extern

Definition at line 345 of file parallel.c.

346{
347 shutdown_info.AHX = AHX;
348}

References ShutdownInformation::AHX, and shutdown_info.

Referenced by restore_one_database().

◆ StartRestoreLO()

void StartRestoreLO ( ArchiveHandle AH,
Oid  oid,
bool  drop 
)
extern

Definition at line 1512 of file pg_backup_archiver.c.

1513{
1514 bool old_lo_style = (AH->version < K_VERS_1_12);
1515 Oid loOid;
1516
1517 AH->loCount++;
1518
1519 /* Initialize the LO Buffer */
1520 if (AH->lo_buf == NULL)
1521 {
1522 /* First time through (in this process) so allocate the buffer */
1523 AH->lo_buf_size = LOBBUFSIZE;
1525 }
1526 AH->lo_buf_used = 0;
1527
1528 pg_log_info("restoring large object with OID %u", oid);
1529
1530 /* With an old archive we must do drop and create logic here */
1531 if (old_lo_style && drop)
1532 DropLOIfExists(AH, oid);
1533
1534 if (AH->connection)
1535 {
1536 if (old_lo_style)
1537 {
1538 loOid = lo_create(AH->connection, oid);
1539 if (loOid == 0 || loOid != oid)
1540 pg_fatal("could not create large object %u: %s",
1541 oid, PQerrorMessage(AH->connection));
1542 }
1543 AH->loFd = lo_open(AH->connection, oid, INV_WRITE);
1544 if (AH->loFd == -1)
1545 pg_fatal("could not open large object %u: %s",
1546 oid, PQerrorMessage(AH->connection));
1547 }
1548 else
1549 {
1550 if (old_lo_style)
1551 ahprintf(AH, "SELECT pg_catalog.lo_open(pg_catalog.lo_create('%u'), %d);\n",
1552 oid, INV_WRITE);
1553 else
1554 ahprintf(AH, "SELECT pg_catalog.lo_open('%u', %d);\n",
1555 oid, INV_WRITE);
1556 }
1557
1558 AH->writingLO = true;
1559}
char * PQerrorMessage(const PGconn *conn)
int lo_open(PGconn *conn, Oid lobjId, int mode)
Definition fe-lobj.c:57
Oid lo_create(PGconn *conn, Oid lobjId)
Definition fe-lobj.c:474
#define INV_WRITE
Definition libpq-fs.h:21
#define LOBBUFSIZE
void DropLOIfExists(ArchiveHandle *AH, Oid oid)
#define K_VERS_1_12
unsigned int Oid

References ahprintf(), _archiveHandle::connection, DropLOIfExists(), fb(), INV_WRITE, K_VERS_1_12, _archiveHandle::lo_buf, _archiveHandle::lo_buf_size, _archiveHandle::lo_buf_used, lo_create(), lo_open(), LOBBUFSIZE, _archiveHandle::loCount, _archiveHandle::loFd, pg_fatal, pg_log_info, pg_malloc(), PQerrorMessage(), _archiveHandle::version, and _archiveHandle::writingLO.

Referenced by _LoadLOs(), _LoadLOs(), and _LoadLOs().

◆ StartRestoreLOs()

void StartRestoreLOs ( ArchiveHandle AH)
extern

Definition at line 1465 of file pg_backup_archiver.c.

1466{
1467 RestoreOptions *ropt = AH->public.ropt;
1468
1469 /*
1470 * LOs must be restored within a transaction block, since we need the LO
1471 * handle to stay open while we write it. Establish a transaction unless
1472 * there's one being used globally.
1473 */
1474 if (!(ropt->single_txn || ropt->txn_size > 0))
1475 {
1476 if (AH->connection)
1478 else
1479 ahprintf(AH, "BEGIN;\n\n");
1480 }
1481
1482 AH->loCount = 0;
1483}

References ahprintf(), _archiveHandle::connection, _archiveHandle::loCount, _archiveHandle::public, Archive::ropt, _restoreOptions::single_txn, StartTransaction(), and _restoreOptions::txn_size.

Referenced by _LoadLOs(), _LoadLOs(), and _LoadLOs().

◆ TocIDRequired()

int TocIDRequired ( ArchiveHandle AH,
DumpId  id 
)
extern

Definition at line 2064 of file pg_backup_archiver.c.

2065{
2066 TocEntry *te = getTocEntryByDumpId(AH, id);
2067
2068 if (!te)
2069 return 0;
2070
2071 return te->reqs;
2072}

References getTocEntryByDumpId(), and _tocEntry::reqs.

Referenced by _tarPositionTo(), and findDumpableDependencies().

◆ warn_or_exit_horribly()

void warn_or_exit_horribly ( ArchiveHandle AH,
const char fmt,
  ... 
)
extern

◆ WriteDataChunks()

void WriteDataChunks ( ArchiveHandle AH,
struct ParallelState pstate 
)
extern

Definition at line 2518 of file pg_backup_archiver.c.

2519{
2520 TocEntry *te;
2521
2522 if (pstate && pstate->numWorkers > 1)
2523 {
2524 /*
2525 * In parallel mode, this code runs in the leader process. We
2526 * construct an array of candidate TEs, then sort it into decreasing
2527 * size order, then dispatch each TE to a data-transfer worker. By
2528 * dumping larger tables first, we avoid getting into a situation
2529 * where we're down to one job and it's big, losing parallelism.
2530 */
2531 TocEntry **tes;
2532 int ntes;
2533
2535 ntes = 0;
2536 for (te = AH->toc->next; te != AH->toc; te = te->next)
2537 {
2538 /* Consider only TEs with dataDumper functions ... */
2539 if (!te->dataDumper)
2540 continue;
2541 /* ... and ignore ones not enabled for dump */
2542 if ((te->reqs & REQ_DATA) == 0)
2543 continue;
2544
2545 tes[ntes++] = te;
2546 }
2547
2548 if (ntes > 1)
2550
2551 for (int i = 0; i < ntes; i++)
2552 DispatchJobForTocEntry(AH, pstate, tes[i], ACT_DUMP,
2554
2555 pg_free(tes);
2556
2557 /* Now wait for workers to finish. */
2558 WaitForWorkers(AH, pstate, WFW_ALL_IDLE);
2559 }
2560 else
2561 {
2562 /* Non-parallel mode: just dump all candidate TEs sequentially. */
2563 for (te = AH->toc->next; te != AH->toc; te = te->next)
2564 {
2565 /* Must have same filter conditions as above */
2566 if (!te->dataDumper)
2567 continue;
2568 if ((te->reqs & REQ_DATA) == 0)
2569 continue;
2570
2572 }
2573 }
2574}
void WaitForWorkers(ArchiveHandle *AH, ParallelState *pstate, WFW_WaitOption mode)
Definition parallel.c:1467
void DispatchJobForTocEntry(ArchiveHandle *AH, ParallelState *pstate, TocEntry *te, T_Action act, ParallelCompletionPtr callback, void *callback_data)
Definition parallel.c:1221
@ WFW_ALL_IDLE
Definition parallel.h:35
void WriteDataChunksForTocEntry(ArchiveHandle *AH, TocEntry *te)
static int TocEntrySizeCompareQsort(const void *p1, const void *p2)
static void mark_dump_job_done(ArchiveHandle *AH, TocEntry *te, int status, void *callback_data)
#define REQ_DATA
#define qsort(a, b, c, d)
Definition port.h:495
DataDumperPtr dataDumper

References ACT_DUMP, _tocEntry::dataDumper, DispatchJobForTocEntry(), fb(), i, mark_dump_job_done(), _tocEntry::next, ParallelState::numWorkers, pg_free(), pg_malloc_array, qsort, REQ_DATA, _tocEntry::reqs, _archiveHandle::toc, _archiveHandle::tocCount, TocEntrySizeCompareQsort(), WaitForWorkers(), WFW_ALL_IDLE, and WriteDataChunksForTocEntry().

Referenced by _CloseArchive(), _CloseArchive(), and _CloseArchive().

◆ WriteDataChunksForTocEntry()

void WriteDataChunksForTocEntry ( ArchiveHandle AH,
TocEntry te 
)
extern

Definition at line 2599 of file pg_backup_archiver.c.

2600{
2603
2604 AH->currToc = te;
2605
2606 if (strcmp(te->desc, "BLOBS") == 0)
2607 {
2608 startPtr = AH->StartLOsPtr;
2609 endPtr = AH->EndLOsPtr;
2610 }
2611 else
2612 {
2613 startPtr = AH->StartDataPtr;
2614 endPtr = AH->EndDataPtr;
2615 }
2616
2617 if (startPtr != NULL)
2618 (*startPtr) (AH, te);
2619
2620 /*
2621 * The user-provided DataDumper routine needs to call AH->WriteData
2622 */
2623 te->dataDumper((Archive *) AH, te->dataDumperArg);
2624
2625 if (endPtr != NULL)
2626 (*endPtr) (AH, te);
2627
2628 AH->currToc = NULL;
2629}
void(* EndDataPtrType)(ArchiveHandle *AH, TocEntry *te)
void(* StartDataPtrType)(ArchiveHandle *AH, TocEntry *te)
struct _tocEntry * currToc
const void * dataDumperArg

References _archiveHandle::currToc, _tocEntry::dataDumper, _tocEntry::dataDumperArg, _tocEntry::desc, _archiveHandle::EndDataPtr, _archiveHandle::EndLOsPtr, fb(), _archiveHandle::StartDataPtr, and _archiveHandle::StartLOsPtr.

Referenced by _WorkerJobDumpDirectory(), and WriteDataChunks().

◆ WriteHead()

void WriteHead ( ArchiveHandle AH)
extern

Definition at line 4168 of file pg_backup_archiver.c.

4169{
4170 struct tm crtm;
4171
4172 AH->WriteBufPtr(AH, "PGDMP", 5); /* Magic code */
4173 AH->WriteBytePtr(AH, ARCHIVE_MAJOR(AH->version));
4174 AH->WriteBytePtr(AH, ARCHIVE_MINOR(AH->version));
4175 AH->WriteBytePtr(AH, ARCHIVE_REV(AH->version));
4176 AH->WriteBytePtr(AH, AH->intSize);
4177 AH->WriteBytePtr(AH, AH->offSize);
4178 AH->WriteBytePtr(AH, AH->format);
4180 crtm = *localtime(&AH->createDate);
4181 WriteInt(AH, crtm.tm_sec);
4182 WriteInt(AH, crtm.tm_min);
4183 WriteInt(AH, crtm.tm_hour);
4184 WriteInt(AH, crtm.tm_mday);
4185 WriteInt(AH, crtm.tm_mon);
4186 WriteInt(AH, crtm.tm_year);
4187 WriteInt(AH, crtm.tm_isdst);
4188 WriteStr(AH, PQdb(AH->connection));
4190 WriteStr(AH, PG_VERSION);
4191}
char * PQdb(const PGconn *conn)
size_t WriteInt(ArchiveHandle *AH, int i)
size_t WriteStr(ArchiveHandle *AH, const char *c)
#define ARCHIVE_MAJOR(version)
#define ARCHIVE_MINOR(version)
#define ARCHIVE_REV(version)
char * remoteVersionStr
Definition pg_backup.h:233

References pg_compress_specification::algorithm, ARCHIVE_MAJOR, ARCHIVE_MINOR, ARCHIVE_REV, _archiveHandle::compression_spec, _archiveHandle::connection, _archiveHandle::createDate, fb(), _archiveHandle::format, _archiveHandle::intSize, _archiveHandle::offSize, PQdb(), _archiveHandle::public, Archive::remoteVersionStr, tm, _archiveHandle::version, _archiveHandle::WriteBufPtr, _archiveHandle::WriteBytePtr, WriteInt(), and WriteStr().

Referenced by _CloseArchive(), _CloseArchive(), and _CloseArchive().

◆ WriteInt()

size_t WriteInt ( ArchiveHandle AH,
int  i 
)
extern

Definition at line 2156 of file pg_backup_archiver.c.

2157{
2158 int b;
2159
2160 /*
2161 * This is a bit yucky, but I don't want to make the binary format very
2162 * dependent on representation, and not knowing much about it, I write out
2163 * a sign byte. If you change this, don't forget to change the file
2164 * version #, and modify ReadInt to read the new format AS WELL AS the old
2165 * formats.
2166 */
2167
2168 /* SIGN byte */
2169 if (i < 0)
2170 {
2171 AH->WriteBytePtr(AH, 1);
2172 i = -i;
2173 }
2174 else
2175 AH->WriteBytePtr(AH, 0);
2176
2177 for (b = 0; b < AH->intSize; b++)
2178 {
2179 AH->WriteBytePtr(AH, i & 0xFF);
2180 i >>= 8;
2181 }
2182
2183 return AH->intSize + 1;
2184}

References b, i, _archiveHandle::intSize, and _archiveHandle::WriteBytePtr.

Referenced by _CustomWriteFunc(), _EndData(), _EndLO(), _EndLOs(), _StartData(), _StartLO(), _StartLOs(), WriteHead(), WriteStr(), and WriteToc().

◆ WriteOffset()

size_t WriteOffset ( ArchiveHandle AH,
pgoff_t  o,
int  wasSet 
)

Definition at line 2075 of file pg_backup_archiver.c.

2076{
2077 int off;
2078
2079 /* Save the flag */
2080 AH->WriteBytePtr(AH, wasSet);
2081
2082 /* Write out pgoff_t smallest byte first, prevents endian mismatch */
2083 for (off = 0; off < sizeof(pgoff_t); off++)
2084 {
2085 AH->WriteBytePtr(AH, o & 0xFF);
2086 o >>= 8;
2087 }
2088 return sizeof(pgoff_t) + 1;
2089}

References fb(), and _archiveHandle::WriteBytePtr.

Referenced by _WriteExtraToc().

◆ WriteStr()

size_t WriteStr ( ArchiveHandle AH,
const char c 
)
extern

Definition at line 2214 of file pg_backup_archiver.c.

2215{
2216 size_t res;
2217
2218 if (c)
2219 {
2220 int len = strlen(c);
2221
2222 res = WriteInt(AH, len);
2223 AH->WriteBufPtr(AH, c, len);
2224 res += len;
2225 }
2226 else
2227 res = WriteInt(AH, -1);
2228
2229 return res;
2230}
const void size_t len
char * c

References fb(), len, _archiveHandle::WriteBufPtr, and WriteInt().

Referenced by _WriteExtraToc(), _WriteExtraToc(), WriteHead(), and WriteToc().

◆ WriteToc()

void WriteToc ( ArchiveHandle AH)
extern

Definition at line 2632 of file pg_backup_archiver.c.

2633{
2634 TocEntry *te;
2635 char workbuf[32];
2636 int tocCount;
2637 int i;
2638
2639 /* count entries that will actually be dumped */
2640 tocCount = 0;
2641 for (te = AH->toc->next; te != AH->toc; te = te->next)
2642 {
2643 if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS | REQ_SPECIAL)) != 0)
2644 tocCount++;
2645 }
2646
2647 /* printf("%d TOC Entries to save\n", tocCount); */
2648
2649 WriteInt(AH, tocCount);
2650
2651 for (te = AH->toc->next; te != AH->toc; te = te->next)
2652 {
2653 if ((te->reqs & (REQ_SCHEMA | REQ_DATA | REQ_STATS | REQ_SPECIAL)) == 0)
2654 continue;
2655
2656 WriteInt(AH, te->dumpId);
2657 WriteInt(AH, te->dataDumper ? 1 : 0);
2658
2659 /* OID is recorded as a string for historical reasons */
2660 sprintf(workbuf, "%u", te->catalogId.tableoid);
2661 WriteStr(AH, workbuf);
2662 sprintf(workbuf, "%u", te->catalogId.oid);
2663 WriteStr(AH, workbuf);
2664
2665 WriteStr(AH, te->tag);
2666 WriteStr(AH, te->desc);
2667 WriteInt(AH, te->section);
2668
2669 if (te->defnLen)
2670 {
2671 /*
2672 * defnLen should only be set for custom format's second call to
2673 * WriteToc(), which rewrites the TOC in place to update data
2674 * offsets. Instead of calling the defnDumper a second time
2675 * (which could involve re-executing queries), just skip writing
2676 * the entry. While regenerating the definition should
2677 * theoretically produce the same result as before, it's expensive
2678 * and feels risky.
2679 *
2680 * The custom format only calls WriteToc() a second time if
2681 * fseeko() is usable (see _CloseArchive() in pg_backup_custom.c),
2682 * so we can safely use it without checking. For other formats,
2683 * we fail because one of our assumptions must no longer hold
2684 * true.
2685 *
2686 * XXX This is a layering violation, but the alternative is an
2687 * awkward and complicated callback infrastructure for this
2688 * special case. This might be worth revisiting in the future.
2689 */
2690 if (AH->format != archCustom)
2691 pg_fatal("unexpected TOC entry in WriteToc(): %d %s %s",
2692 te->dumpId, te->desc, te->tag);
2693
2694 if (fseeko(AH->FH, te->defnLen, SEEK_CUR) != 0)
2695 pg_fatal("error during file seek: %m");
2696 }
2697 else if (te->defnDumper)
2698 {
2699 char *defn = te->defnDumper((Archive *) AH, te->defnDumperArg, te);
2700
2701 te->defnLen = WriteStr(AH, defn);
2702 pg_free(defn);
2703 }
2704 else
2705 WriteStr(AH, te->defn);
2706
2707 WriteStr(AH, te->dropStmt);
2708 WriteStr(AH, te->copyStmt);
2709 WriteStr(AH, te->namespace);
2710 WriteStr(AH, te->tablespace);
2711 WriteStr(AH, te->tableam);
2712 WriteInt(AH, te->relkind);
2713 WriteStr(AH, te->owner);
2714 WriteStr(AH, "false");
2715
2716 /* Dump list of dependencies */
2717 for (i = 0; i < te->nDeps; i++)
2718 {
2719 sprintf(workbuf, "%d", te->dependencies[i]);
2720 WriteStr(AH, workbuf);
2721 }
2722 WriteStr(AH, NULL); /* Terminate List */
2723
2724 if (AH->WriteExtraTocPtr)
2725 AH->WriteExtraTocPtr(AH, te);
2726 }
2727}
@ archCustom
Definition pg_backup.h:42
#define REQ_SCHEMA
#define REQ_STATS
#define REQ_SPECIAL
#define sprintf
Definition port.h:262
DefnDumperPtr defnDumper
const void * defnDumperArg

References archCustom, _tocEntry::catalogId, _tocEntry::copyStmt, _tocEntry::dataDumper, _tocEntry::defn, _tocEntry::defnDumper, _tocEntry::defnDumperArg, _tocEntry::defnLen, _tocEntry::dependencies, _tocEntry::desc, _tocEntry::dropStmt, _tocEntry::dumpId, fb(), _archiveHandle::FH, _archiveHandle::format, fseeko, i, _tocEntry::nDeps, _tocEntry::next, CatalogId::oid, _tocEntry::owner, pg_fatal, pg_free(), _tocEntry::relkind, REQ_DATA, REQ_SCHEMA, REQ_SPECIAL, REQ_STATS, _tocEntry::reqs, _tocEntry::section, sprintf, _tocEntry::tableam, CatalogId::tableoid, _tocEntry::tablespace, _tocEntry::tag, _archiveHandle::toc, _archiveHandle::WriteExtraTocPtr, WriteInt(), and WriteStr().

Referenced by _CloseArchive(), _CloseArchive(), and _CloseArchive().