PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <unistd.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <time.h>
#include "access/xlog_internal.h"
#include "common/file_perm.h"
#include "common/file_utils.h"
#include "common/logging.h"
#include "common/string.h"
#include "fe_utils/recovery_gen.h"
#include "fe_utils/string_utils.h"
#include "getopt_long.h"
#include "libpq-fe.h"
#include "pgtar.h"
#include "pgtime.h"
#include "pqexpbuffer.h"
#include "receivelog.h"
#include "replication/basebackup.h"
#include "streamutil.h"
Go to the source code of this file.
Data Structures | |
struct | TablespaceListCell |
struct | TablespaceList |
struct | WriteTarState |
struct | UnpackTarState |
struct | WriteManifestState |
struct | logstreamer_param |
Macros | |
#define | ERRCODE_DATA_CORRUPTED "XX001" |
#define | MINIMUM_VERSION_FOR_PG_WAL 100000 |
#define | MINIMUM_VERSION_FOR_TEMP_SLOTS 100000 |
#define | MINIMUM_VERSION_FOR_MANIFESTS 130000 |
#define | VERBOSE_FILENAME_LENGTH 35 |
Typedefs | |
typedef struct TablespaceListCell | TablespaceListCell |
typedef struct TablespaceList | TablespaceList |
typedef struct WriteTarState | WriteTarState |
typedef struct UnpackTarState | UnpackTarState |
typedef struct WriteManifestState | WriteManifestState |
typedef void(* | WriteDataCallback) (size_t nbytes, char *buf, void *callback_data) |
Enumerations | |
enum | IncludeWal { NO_WAL, FETCH_WAL, STREAM_WAL } |
Functions | |
static void | usage (void) |
static void | verify_dir_is_empty_or_create (char *dirname, bool *created, bool *found) |
static void | progress_report (int tablespacenum, const char *filename, bool force, bool finished) |
static void | ReceiveTarFile (PGconn *conn, PGresult *res, int rownum) |
static void | ReceiveTarCopyChunk (size_t r, char *copybuf, void *callback_data) |
static void | ReceiveAndUnpackTarFile (PGconn *conn, PGresult *res, int rownum) |
static void | ReceiveTarAndUnpackCopyChunk (size_t r, char *copybuf, void *callback_data) |
static void | ReceiveBackupManifest (PGconn *conn) |
static void | ReceiveBackupManifestChunk (size_t r, char *copybuf, void *callback_data) |
static void | ReceiveBackupManifestInMemory (PGconn *conn, PQExpBuffer buf) |
static void | ReceiveBackupManifestInMemoryChunk (size_t r, char *copybuf, void *callback_data) |
static void | BaseBackup (void) |
static bool | reached_end_position (XLogRecPtr segendpos, uint32 timeline, bool segment_finished) |
static const char * | get_tablespace_mapping (const char *dir) |
static void | tablespace_list_append (const char *arg) |
static void | cleanup_directories_atexit (void) |
static void | disconnect_atexit (void) |
static void | kill_bgchild_atexit (void) |
static int | LogStreamerMain (logstreamer_param *param) |
static void | StartLogStreamer (char *startpos, uint32 timeline, char *sysidentifier) |
static int32 | parse_max_rate (char *src) |
static void | ReceiveCopyData (PGconn *conn, WriteDataCallback callback, void *callback_data) |
static void | writeTarData (WriteTarState *state, char *buf, int r) |
int | main (int argc, char **argv) |
#define ERRCODE_DATA_CORRUPTED "XX001" |
Definition at line 45 of file pg_basebackup.c.
Referenced by BaseBackup(), bt_tuple_present_callback(), FreezeMultiXactId(), get_controlfile(), getdatafield(), heap_fetch_toast_slice(), heap_prepare_freeze_tuple(), heapam_index_build_range_scan(), heapam_index_validate_scan(), heapam_tuple_lock(), load_relmap_file(), mdread(), PageAddItemExtended(), PageIndexMultiDelete(), PageIndexTupleDelete(), PageIndexTupleDeleteNoCompact(), PageIndexTupleOverwrite(), PageIsVerifiedExtended(), PageRepairFragmentation(), perform_base_backup(), ProcessTwoPhaseBuffer(), ReadBuffer_common(), ReadControlFile(), ReadTwoPhaseFile(), RelationCopyStorage(), RestoreSlotFromDisk(), SendTimeLineHistory(), SnapBuildRestore(), StartupReplicationOrigin(), text_to_bits(), tuple_data_split(), tuple_data_split_internal(), WALReadRaiseError(), XLogFileCopy(), and XLogPageRead().
#define MINIMUM_VERSION_FOR_MANIFESTS 130000 |
Definition at line 114 of file pg_basebackup.c.
Referenced by main().
#define MINIMUM_VERSION_FOR_PG_WAL 100000 |
Definition at line 104 of file pg_basebackup.c.
Referenced by main(), and StartLogStreamer().
#define MINIMUM_VERSION_FOR_TEMP_SLOTS 100000 |
Definition at line 109 of file pg_basebackup.c.
Referenced by StartLogStreamer().
#define VERBOSE_FILENAME_LENGTH 35 |
Referenced by progress_report().
typedef struct TablespaceList TablespaceList |
typedef struct TablespaceListCell TablespaceListCell |
typedef struct UnpackTarState UnpackTarState |
typedef void(* WriteDataCallback) (size_t nbytes, char *buf, void *callback_data) |
Definition at line 97 of file pg_basebackup.c.
typedef struct WriteManifestState WriteManifestState |
typedef struct WriteTarState WriteTarState |
enum IncludeWal |
Enumerator | |
---|---|
NO_WAL | |
FETCH_WAL | |
STREAM_WAL |
Definition at line 119 of file pg_basebackup.c.
|
static |
Definition at line 1797 of file pg_basebackup.c.
References _dosmaperr(), Assert, basedir, bgchild, bgpipe, CheckServerVersionForStreaming(), checksum_failure, conn, destroyPQExpBuffer(), do_sync, durable_rename(), ERRCODE_DATA_CORRUPTED, estimatesize, fastcheckpoint, FETCH_WAL, filename, format, found_tablespace_dirs, fprintf, GenerateRecoveryConfig(), get_tablespace_mapping(), has_xlogendptr, i, includewal, label, made_tablespace_dirs, manifest, manifest_checksums, manifest_force_encode, MAXPGPATH, maxrate, MemSet, NO_WAL, PG_DIAG_SQLSTATE, pg_log_error, pg_log_info, PGRES_COMMAND_OK, PGRES_TUPLES_OK, PQclear(), PQerrorMessage(), PQescapeStringConn(), PQfinish(), PQgetisnull(), PQgetResult(), PQgetvalue(), PQnfields(), PQntuples(), PQparameterStatus(), PQresultErrorField(), PQresultStatus(), PQsendQuery(), PQserverVersion(), progress_report(), psprintf(), ReceiveAndUnpackTarFile(), ReceiveBackupManifest(), ReceiveTarFile(), replication_slot, RunIdentifySystem(), showprogress, snprintf, StartLogStreamer(), status(), STREAM_WAL, strlcpy(), tablespacecount, totaldone, totalsize_kb, unconstify, verbose, verify_checksums, verify_dir_is_empty_or_create(), wait_result_to_str(), write, writerecoveryconf, and xlogendptr.
Referenced by main().
|
static |
Definition at line 215 of file pg_basebackup.c.
References basedir, checksum_failure, found_existing_pgdata, found_existing_xlogdir, found_tablespace_dirs, in_log_streamer, made_new_pgdata, made_new_xlogdir, made_tablespace_dirs, noclean, pg_log_error, pg_log_info, rmtree(), success, and xlog_dir.
Referenced by main().
|
static |
Definition at line 262 of file pg_basebackup.c.
References conn, and PQfinish().
Referenced by main().
|
static |
Definition at line 1488 of file pg_basebackup.c.
References canonicalize_path(), TablespaceList::head, MAXPGPATH, TablespaceListCell::new_dir, TablespaceListCell::next, TablespaceListCell::old_dir, and strlcpy().
Referenced by BaseBackup(), ReceiveAndUnpackTarFile(), and ReceiveTarAndUnpackCopyChunk().
|
static |
|
static |
Definition at line 531 of file pg_basebackup.c.
References logstreamer_param::bgconn, bgpipe, compresslevel, CreateWalDirectoryMethod(), CreateWalTarMethod(), StreamCtl::do_sync, WalWriteMethod::finish, format, FreeWalDirectoryMethod(), FreeWalTarMethod(), in_log_streamer, StreamCtl::mark_done, MemSet, StreamCtl::partial_suffix, pg_free(), pg_log_error, PGINVALID_SOCKET, PQfinish(), reached_end_position(), ReceiveXlogStream(), StreamCtl::replication_slot, replication_slot, StreamCtl::standby_message_timeout, standby_message_timeout, StreamCtl::startpos, logstreamer_param::startptr, StreamCtl::stop_socket, StreamCtl::stream_stop, StreamCtl::synchronous, StreamCtl::sysidentifier, logstreamer_param::sysidentifier, StreamCtl::timeline, logstreamer_param::timeline, StreamCtl::walmethod, and logstreamer_param::xlog.
Referenced by StartLogStreamer().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 2225 of file pg_basebackup.c.
References _, BaseBackup(), basedir, canonicalize_path(), cleanup_directories_atexit(), compresslevel, conn, connection_string, create_slot, dbgetpassword, dbhost, dbport, dbuser, disconnect_atexit(), do_sync, estimatesize, fastcheckpoint, FETCH_WAL, format, found_existing_pgdata, found_existing_xlogdir, fprintf, free, get_progname(), GetConnection(), getopt_long(), includewal, is_absolute_path, label, made_new_pgdata, made_new_xlogdir, manifest, manifest_checksums, manifest_force_encode, maxrate, MINIMUM_VERSION_FOR_MANIFESTS, MINIMUM_VERSION_FOR_PG_WAL, no_argument, no_slot, NO_WAL, noclean, optarg, optind, parse_max_rate(), pg_log_error, pg_logging_init(), pg_mode_mask, pg_strcasecmp(), pg_strdup(), PG_TEXTDOMAIN, PQserverVersion(), progname, psprintf(), replication_slot, required_argument, RetrieveWalSegSize(), set_pglocale_pgservice(), showprogress, standby_message_timeout, STREAM_WAL, success, symlink, tablespace_list_append(), temp_replication_slot, usage(), verbose, verify_checksums, verify_dir_is_empty_or_create(), writerecoveryconf, xlog_dir, and Z_DEFAULT_COMPRESSION.
|
static |
Definition at line 867 of file pg_basebackup.c.
References MAX_RATE_UPPER, and pg_log_error.
Referenced by main().
|
static |
Definition at line 776 of file pg_basebackup.c.
References fprintf, INT64_FORMAT, last_progress_report, ngettext, now(), showprogress, snprintf, tablespacecount, totaldone, totalsize_kb, verbose, and VERBOSE_FILENAME_LENGTH.
Referenced by BaseBackup(), ReceiveAndUnpackTarFile(), ReceiveTarAndUnpackCopyChunk(), ReceiveTarCopyChunk(), ReceiveTarFile(), and write_target_range().
|
static |
Definition at line 441 of file pg_basebackup.c.
References bgpipe, has_xlogendptr, MemSet, pg_log_error, read, select, and xlogendptr.
Referenced by LogStreamerMain().
Definition at line 1515 of file pg_basebackup.c.
References basedir, UnpackTarState::current_path, UnpackTarState::file, UnpackTarState::filename, get_tablespace_mapping(), pg_log_error, PQgetisnull(), PQgetvalue(), progress_report(), ReceiveCopyData(), ReceiveTarAndUnpackCopyChunk(), strlcpy(), UnpackTarState::tablespacenum, writerecoveryconf, and WriteRecoveryConfig().
Referenced by BaseBackup().
|
static |
Definition at line 1738 of file pg_basebackup.c.
References basedir, WriteManifestState::file, WriteManifestState::filename, pg_log_error, ReceiveBackupManifestChunk(), ReceiveCopyData(), and snprintf.
Referenced by BaseBackup().
|
static |
Definition at line 1760 of file pg_basebackup.c.
References WriteManifestState::file, WriteManifestState::filename, and pg_log_error.
Referenced by ReceiveBackupManifest().
|
static |
Definition at line 1779 of file pg_basebackup.c.
References ReceiveBackupManifestInMemoryChunk(), and ReceiveCopyData().
Referenced by ReceiveTarFile().
|
static |
Definition at line 1788 of file pg_basebackup.c.
References appendPQExpBuffer(), and buf.
Referenced by ReceiveBackupManifestInMemory().
|
static |
Definition at line 952 of file pg_basebackup.c.
References copybuf, pg_log_error, PGRES_COPY_OUT, PQclear(), PQerrorMessage(), PQfreemem(), PQgetCopyData(), PQgetResult(), and PQresultStatus().
Referenced by ReceiveAndUnpackTarFile(), ReceiveBackupManifest(), ReceiveBackupManifestInMemory(), and ReceiveTarFile().
|
static |
Definition at line 1555 of file pg_basebackup.c.
References UnpackTarState::current_len_left, UnpackTarState::current_padding, UnpackTarState::current_path, UnpackTarState::file, UnpackTarState::filename, get_tablespace_mapping(), UnpackTarState::mapped_tblspc_path, mkdir, pg_dir_create_mode, pg_log_error, pg_str_endswith(), progress_report(), read_tar_number(), snprintf, symlink, UnpackTarState::tablespacenum, TAR_BLOCK_SIZE, tarPaddingBytesRequired(), and totaldone.
Referenced by ReceiveAndUnpackTarFile().
|
static |
Definition at line 1298 of file pg_basebackup.c.
References WriteTarState::basetablespace, PQExpBufferData::data, WriteTarState::file_padding_len, WriteTarState::filename, WriteTarState::filesz, WriteTarState::found_postgresql_auto_conf, header(), WriteTarState::in_tarhdr, WriteTarState::is_postgresql_auto_conf, WriteTarState::is_recovery_guc_supported, PQExpBufferData::len, MemSet, pg_file_create_mode, progress_report(), read_tar_number(), WriteTarState::skip_file, WriteTarState::tablespacenum, TAR_BLOCK_SIZE, tarCreateHeader(), WriteTarState::tarhdr, WriteTarState::tarhdrsz, tarPaddingBytesRequired(), totaldone, writerecoveryconf, and writeTarData().
Referenced by ReceiveTarFile().
Definition at line 1039 of file pg_basebackup.c.
References basedir, WriteTarState::basetablespace, buf, compresslevel, PQExpBufferData::data, fd(), WriteTarState::filename, WriteTarState::found_postgresql_auto_conf, header(), WriteTarState::in_tarhdr, initPQExpBuffer(), WriteTarState::is_recovery_guc_supported, PQExpBufferData::len, manifest, MemSet, MINIMUM_VERSION_FOR_RECOVERY_GUC, pg_file_create_mode, pg_log_error, PQExpBufferDataBroken, PQgetisnull(), PQgetvalue(), PQserverVersion(), progress_report(), ReceiveBackupManifestInMemory(), ReceiveCopyData(), ReceiveTarCopyChunk(), snprintf, generate_unaccent_rules::stdout, WriteTarState::tablespacenum, TAR_BLOCK_SIZE, tarCreateHeader(), WriteTarState::tarfile, tarPaddingBytesRequired(), termPQExpBuffer(), writerecoveryconf, and writeTarData().
Referenced by BaseBackup().
|
static |
Definition at line 594 of file pg_basebackup.c.
References basedir, bgchild, logstreamer_param::bgconn, bgpipe, conn, create_slot, CreateReplicationSlot(), format, GetConnection(), kill_bgchild_atexit(), LogStreamerMain(), MAXPGPATH, MINIMUM_VERSION_FOR_PG_WAL, MINIMUM_VERSION_FOR_TEMP_SLOTS, pg_dir_create_mode, pg_log_error, pg_log_info, pg_malloc0(), pg_mkdir_p(), PQbackendPID(), PQserverVersion(), psprintf(), replication_slot, snprintf, logstreamer_param::startptr, logstreamer_param::sysidentifier, temp_replication_slot, logstreamer_param::timeline, verbose, WalSegSz, logstreamer_param::xlog, and XLogSegmentOffset.
Referenced by BaseBackup().
|
static |
Definition at line 287 of file pg_basebackup.c.
References canonicalize_path(), errmsg(), TablespaceList::head, is_absolute_path, MAXPGPATH, TablespaceListCell::new_dir, TablespaceListCell::next, TablespaceListCell::old_dir, pg_log_error, pg_malloc0(), strerror, and TablespaceList::tail.
Referenced by main().
|
static |
Definition at line 720 of file pg_basebackup.c.
References pg_check_dir(), pg_dir_create_mode, pg_log_error, and pg_mkdir_p().
Referenced by BaseBackup(), and main().
|
static |
Definition at line 996 of file pg_basebackup.c.
References WriteTarState::filename, pg_log_error, and WriteTarState::tarfile.
Referenced by ReceiveTarCopyChunk(), and ReceiveTarFile().
|
static |
Definition at line 127 of file pg_basebackup.c.
Referenced by BaseBackup(), cleanup_directories_atexit(), main(), ReceiveAndUnpackTarFile(), ReceiveBackupManifest(), ReceiveTarFile(), and StartLogStreamer().
|
static |
Definition at line 173 of file pg_basebackup.c.
Referenced by BaseBackup(), kill_bgchild_atexit(), and StartLogStreamer().
|
static |
Definition at line 169 of file pg_basebackup.c.
Referenced by BaseBackup(), LogStreamerMain(), reached_end_position(), and StartLogStreamer().
Definition at line 133 of file pg_basebackup.c.
Referenced by BaseBackup(), cleanup_directories_atexit(), and PageIsVerifiedExtended().
|
static |
Definition at line 137 of file pg_basebackup.c.
Referenced by LogStreamerMain(), main(), and ReceiveTarFile().
Definition at line 147 of file pg_basebackup.c.
Referenced by CreateSubscription(), main(), and StartLogStreamer().
Definition at line 141 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
Definition at line 135 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
Definition at line 139 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
|
static |
Definition at line 130 of file pg_basebackup.c.
Referenced by _fmt(), BaseBackup(), check_selective_binary_conversion(), datetime_to_char_body(), do_to_timestamp(), doabbr(), dopr(), exec_simple_query(), ExplainMissingMembers(), float4_to_char(), float8_to_char(), flushbuffer(), getCopyStart(), getRowDescriptions(), int4_to_char(), int8_to_char(), LogStreamerMain(), main(), NUM_cache(), numeric_to_char(), numeric_to_number(), PGLC_localeconv(), PGTYPESdate_fmt_asc(), print_aligned_text(), print_aligned_vertical(), printtup_prepare_info(), ReceiveCopyBegin(), SendCopyBegin(), SendRowDescriptionCols_3(), and StartLogStreamer().
Definition at line 156 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
Definition at line 158 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
Definition at line 160 of file pg_basebackup.c.
Referenced by BaseBackup(), and cleanup_directories_atexit().
|
static |
Definition at line 180 of file pg_basebackup.c.
Referenced by BaseBackup(), and reached_end_position().
Definition at line 174 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and LogStreamerMain().
|
static |
Definition at line 138 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
|
static |
Definition at line 131 of file pg_basebackup.c.
Referenced by _copySecLabelStmt(), _equalSecLabelStmt(), _fmt(), BaseBackup(), CATALOG(), doPickSplit(), dumpEnumType(), dumpSecLabel(), dumpTableSecLabel(), emitShSecLabels(), expandNSItemAttrs(), expandRecordVariable(), expandRTE(), expandTupleDesc(), ExplainCustomChildren(), main(), plpgsql_parse_err_condition(), plpgsql_recognize_err_condition(), sepgsql_get_label(), sepgsql_mcstrans_in(), sepgsql_mcstrans_out(), spgSplitNodeAction(), and TypeGetTupleDesc().
|
static |
Definition at line 143 of file pg_basebackup.c.
Referenced by progress_report().
Definition at line 155 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
Definition at line 157 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
Definition at line 159 of file pg_basebackup.c.
Referenced by BaseBackup(), and cleanup_directories_atexit().
Definition at line 150 of file pg_basebackup.c.
Referenced by BaseBackup(), main(), perform_base_backup(), and ReceiveTarFile().
|
static |
Definition at line 152 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
Definition at line 151 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
|
static |
Definition at line 144 of file pg_basebackup.c.
Referenced by BaseBackup(), main(), and parse_basebackup_options().
Definition at line 148 of file pg_basebackup.c.
Referenced by main().
Definition at line 132 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
|
static |
Definition at line 186 of file pg_basebackup.c.
|
static |
Definition at line 145 of file pg_basebackup.c.
Referenced by BaseBackup(), LogStreamerMain(), main(), and StartLogStreamer().
Definition at line 134 of file pg_basebackup.c.
Referenced by BaseBackup(), main(), and progress_report().
|
static |
Definition at line 142 of file pg_basebackup.c.
Referenced by LogStreamerMain(), and main().
Definition at line 154 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
|
static |
Definition at line 128 of file pg_basebackup.c.
|
static |
Definition at line 165 of file pg_basebackup.c.
Referenced by BaseBackup(), and progress_report().
Definition at line 146 of file pg_basebackup.c.
Referenced by main(), and StartLogStreamer().
|
static |
Definition at line 164 of file pg_basebackup.c.
Referenced by BaseBackup(), progress_report(), ReceiveTarAndUnpackCopyChunk(), and ReceiveTarCopyChunk().
|
static |
Definition at line 163 of file pg_basebackup.c.
Referenced by BaseBackup(), and progress_report().
|
static |
Definition at line 136 of file pg_basebackup.c.
Referenced by BaseBackup(), cluster(), cluster_rel(), ExecReindex(), ExecVacuum(), main(), optimize(), progress_report(), and StartLogStreamer().
Definition at line 149 of file pg_basebackup.c.
Referenced by BaseBackup(), and main().
Definition at line 140 of file pg_basebackup.c.
Referenced by BaseBackup(), main(), ReceiveAndUnpackTarFile(), ReceiveTarCopyChunk(), and ReceiveTarFile().
|
static |
Definition at line 129 of file pg_basebackup.c.
Referenced by cleanup_directories_atexit(), and main().
|
static |
Definition at line 177 of file pg_basebackup.c.
Referenced by BaseBackup(), and reached_end_position().