1/*-------------------------------------------------------------------------
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * src/bin/pg_basebackup/walmethods.h
9 *-------------------------------------------------------------------------
24 * MORE DATA FOLLOWS AT END OF STRUCT
26 * Each WalWriteMethod is expected to embed this as the first member of a
27 * larger struct with method-specific fields following.
39 * Table of callbacks for a WalWriteMethod.
44 * Open a target file. Returns Walfile, or NULL if open failed. If a temp
45 * suffix is specified, a file with that name will be opened, and then
46 * automatically renamed in close(). If pad_to_size is specified, the file
47 * will be padded with NUL up to that size, if supported by the Walmethod.
49 Walfile *(*open_for_write) (
WalWriteMethod *wwmethod,
const char *pathname,
const char *temp_suffix,
size_t pad_to_size);
52 * Close an open Walfile, using one or more methods for handling automatic
53 * unlinking etc. Returns 0 on success, other values for error.
57 /* Check if a file exist */
60 /* Return the size of a file, or -1 on failure. */
64 * Return the name of the current file to work on in pg_malloc()'d string,
65 * without the base directory. This is useful for logging.
67 char *(*get_file_name) (
WalWriteMethod *wwmethod,
const char *pathname,
const char *temp_suffix);
70 * Write count number of bytes to the file, and return the number of bytes
71 * actually written or -1 for error.
76 * fsync the contents of the specified file. Returns 0 on success.
81 * Clean up the Walmethod, closing any shared resources. For methods like
82 * tar, this includes writing updated headers. Returns true if the
83 * close/write/sync of shared resources succeeded, otherwise returns false
84 * (but the resources are still closed).
89 * Free subsidiary data associated with the WalWriteMethod, and the
90 * WalWriteMethod itself.
96 * A WalWriteMethod structure represents a way of writing streaming WAL as
99 * All methods that have a failure return indicator will set lasterrstring
100 * or lasterrno (the former takes precedence) so that the caller can signal
113 * MORE DATA FOLLOWS AT END OF STRUCT
115 * Each WalWriteMethod is expected to embed this as the first member of a
116 * larger struct with method-specific fields following.
121 * Available WAL methods:
122 * - WalDirectoryMethod - write WAL to regular files in a standard pg_wal
123 * - WalTarMethod - write WAL to a tarfile corresponding to pg_wal
124 * (only implements the methods required for pg_basebackup,
125 * not all those required for pg_receivewal)
129 int compression_level,
bool sync);
132 int compression_level,
bool sync);
static pg_compress_algorithm compression_algorithm
void(* free)(WalWriteMethod *wwmethod)
bool(* existsfile)(WalWriteMethod *wwmethod, const char *pathname)
ssize_t(* write)(Walfile *f, const void *buf, size_t count)
ssize_t(* get_file_size)(WalWriteMethod *wwmethod, const char *pathname)
int(* close)(Walfile *f, WalCloseMethod method)
bool(* finish)(WalWriteMethod *wwmethod)
const char * lasterrstring
const WalWriteMethodOps * ops
pg_compress_algorithm compression_algorithm
WalWriteMethod * wwmethod
WalWriteMethod * CreateWalTarMethod(const char *tarbase, pg_compress_algorithm compression_algorithm, int compression_level, bool sync)
struct WalWriteMethodOps WalWriteMethodOps
WalWriteMethod * CreateWalDirectoryMethod(const char *basedir, pg_compress_algorithm compression_algorithm, int compression_level, bool sync)
const char * GetLastWalMethodError(WalWriteMethod *wwmethod)