PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include "access/timeline.h"
#include "access/xlog_internal.h"
#include "catalog/catversion.h"
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "common/file_perm.h"
#include "common/restricted_token.h"
#include "common/string.h"
#include "fe_utils/option_utils.h"
#include "fe_utils/recovery_gen.h"
#include "fe_utils/string_utils.h"
#include "file_ops.h"
#include "filemap.h"
#include "getopt_long.h"
#include "pg_rewind.h"
#include "rewind_source.h"
#include "storage/bufpage.h"
Go to the source code of this file.
Functions | |
static void | usage (const char *progname) |
static void | perform_rewind (filemap_t *filemap, rewind_source *source, XLogRecPtr chkptrec, TimeLineID chkpttli, XLogRecPtr chkptredo) |
static void | createBackupLabel (XLogRecPtr startpoint, TimeLineID starttli, XLogRecPtr checkpointloc) |
static void | digestControlFile (ControlFileData *ControlFile, const char *content, size_t size) |
static void | getRestoreCommand (const char *argv0) |
static void | sanityChecks (void) |
static TimeLineHistoryEntry * | getTimelineHistory (TimeLineID tli, bool is_source, int *nentries) |
static void | findCommonAncestorTimeline (TimeLineHistoryEntry *a_history, int a_nentries, TimeLineHistoryEntry *b_history, int b_nentries, XLogRecPtr *recptr, int *tliIndex) |
static void | ensureCleanShutdown (const char *argv0) |
static void | disconnect_atexit (void) |
int | main (int argc, char **argv) |
void | progress_report (bool finished) |
static XLogRecPtr | MinXLogRecPtr (XLogRecPtr a, XLogRecPtr b) |
static void | checkControlFile (ControlFileData *ControlFile) |
Variables | |
static ControlFileData | ControlFile_target |
static ControlFileData | ControlFile_source |
static ControlFileData | ControlFile_source_after |
static const char * | progname |
int | WalSegSz |
char * | datadir_target = NULL |
static char * | datadir_source = NULL |
static char * | connstr_source = NULL |
static char * | restore_command = NULL |
static char * | config_file = NULL |
static bool | debug = false |
bool | showprogress = false |
bool | dry_run = false |
bool | do_sync = true |
static bool | restore_wal = false |
DataDirSyncMethod | sync_method = DATA_DIR_SYNC_METHOD_FSYNC |
TimeLineHistoryEntry * | targetHistory |
int | targetNentries |
uint64 | fetch_size |
uint64 | fetch_done |
static PGconn * | conn |
static rewind_source * | source |
|
static |
Definition at line 1004 of file pg_rewind.c.
References COMP_CRC32C, ControlFile, ControlFileData::crc, crc, EQ_CRC32C, FIN_CRC32C, INIT_CRC32C, and pg_fatal.
Referenced by digestControlFile().
|
static |
Definition at line 961 of file pg_rewind.c.
References buf, close_target_file(), len, LSN_FORMAT_ARGS, MAXFNAMELEN, open_target_file(), pg_fatal, snprintf, tm, WalSegSz, write_target_range(), XLByteToSeg, and XLogFileName().
Referenced by perform_rewind().
|
static |
Definition at line 1023 of file pg_rewind.c.
References checkControlFile(), ControlFile, exit(), IsValidWalSegSize, ngettext, PG_CONTROL_FILE_SIZE, pg_fatal, pg_log_error, pg_log_error_detail, size, WalSegSz, and ControlFileData::xlog_seg_size.
Referenced by main(), and perform_rewind().
|
static |
|
static |
Definition at line 1129 of file pg_rewind.c.
References appendPQExpBufferStr(), appendShellString(), argv0, config_file, createPQExpBuffer(), PQExpBufferData::data, datadir_target, destroyPQExpBuffer(), DEVNULL, dry_run, exec_path, exit(), fflush(), find_my_exec(), find_other_exec(), MAXPGPATH, PG_BACKEND_VERSIONSTR, pg_fatal, pg_log_error, pg_log_error_detail, pg_log_info, progname, and strlcpy().
Referenced by main().
|
static |
Definition at line 919 of file pg_rewind.c.
References i, Min, MinXLogRecPtr(), and pg_fatal.
Referenced by main().
|
static |
Definition at line 1056 of file pg_rewind.c.
References appendPQExpBufferStr(), appendShellString(), argv0, config_file, createPQExpBuffer(), PQExpBufferData::data, datadir_target, destroyPQExpBuffer(), find_my_exec(), find_other_exec(), MAXPGPATH, PG_BACKEND_VERSIONSTR, pg_fatal, pg_log_debug, pg_strip_crlf(), pipe_read_line(), progname, restore_command, restore_wal, and strlcpy().
Referenced by main().
|
static |
Definition at line 856 of file pg_rewind.c.
References TimeLineHistoryEntry::begin, datadir_target, debug, TimeLineHistoryEntry::end, rewind_source::fetch_file, i, InvalidXLogRecPtr, LSN_FORMAT_ARGS, MAXPGPATH, pg_free(), pg_log_debug, pg_malloc(), rewind_parseTimeLineHistory(), slurpFile(), source, TLHistoryFilePath(), and TimeLineHistoryEntry::tli.
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 121 of file pg_rewind.c.
References Assert, calculate_totals(), ControlFileData::checkPoint, ControlFileData::checkPointCopy, config_file, conn, CONNECTION_BAD, connstr_source, ControlFile_source, ControlFile_target, datadir_source, datadir_target, DB_SHUTDOWNED, DB_SHUTDOWNED_IN_RECOVERY, debug, decide_file_actions(), rewind_source::destroy, digestControlFile(), disconnect_atexit(), do_sync, dry_run, ensureCleanShutdown(), exit(), extractPageMap(), fetch_done, rewind_source::fetch_file, filemap_t::fetch_size, fetch_size, filehash_init(), findCommonAncestorTimeline(), findLastCheckpoint(), GenerateRecoveryConfig(), get_progname(), get_restricted_token(), GetDataDirectoryCreatePerm(), getopt_long(), getRestoreCommand(), getTimelineHistory(), init_libpq_source(), init_local_source(), keepwal_init(), LSN_FORMAT_ARGS, Max, ControlFileData::minRecoveryPoint, ControlFileData::minRecoveryPointTLI, no_argument, optarg, optind, parse_sync_method(), perform_rewind(), pfree(), pg_fatal, pg_free(), pg_log_error, pg_log_error_hint, pg_log_info, pg_logging_increase_verbosity(), pg_logging_init(), pg_mode_mask, pg_strdup(), PG_TEXTDOMAIN, PQconnectdb(), PQerrorMessage(), PQfinish(), PQstatus(), print_filemap(), process_source_file(), process_target_file(), progname, readOneRecord(), required_argument, restore_command, restore_wal, sanityChecks(), set_pglocale_pgservice(), showprogress, size, slurpFile(), source, ControlFileData::state, sync_method, sync_target_dir(), targetHistory, targetNentries, CheckPoint::ThisTimeLineID, filemap_t::total_size, traverse_datadir(), rewind_source::traverse_files, usage(), writerecoveryconf, and WriteRecoveryConfig().
|
static |
Definition at line 842 of file pg_rewind.c.
References a, b, Min, and XLogRecPtrIsInvalid.
Referenced by findCommonAncestorTimeline().
|
static |
Definition at line 553 of file pg_rewind.c.
References file_entry_t::action, datapagemap::bitmapsize, ControlFileData::checkPoint, ControlFileData::checkPointCopy, close_target_file(), connstr_source, ControlFile_source, ControlFile_source_after, create_target(), createBackupLabel(), datadir_source, datadir_target, datapagemap_iterate(), datapagemap_next(), DB_IN_ARCHIVE_RECOVERY, DB_IN_PRODUCTION, digestControlFile(), do_sync, dry_run, filemap_t::entries, rewind_source::fetch_file, FILE_ACTION_COPY, FILE_ACTION_COPY_TAIL, FILE_ACTION_CREATE, FILE_ACTION_NONE, FILE_ACTION_REMOVE, FILE_ACTION_TRUNCATE, FILE_ACTION_UNDECIDED, rewind_source::finish_fetch, rewind_source::get_current_wal_insert_lsn, i, Max, ControlFileData::minRecoveryPoint, ControlFileData::minRecoveryPointTLI, filemap_t::nentries, file_entry_t::path, pg_fatal, pg_free(), pg_log_info, progress_report(), rewind_source::queue_fetch_file, rewind_source::queue_fetch_range, CheckPoint::redo, remove_target(), showprogress, size, source, file_entry_t::source_size, ControlFileData::state, file_entry_t::target_pages_to_overwrite, file_entry_t::target_size, CheckPoint::ThisTimeLineID, truncate_target_file(), and update_controlfile().
Referenced by main().
static void progress_report | ( | bool | finished | ) |
Definition at line 791 of file pg_rewind.c.
References _, fetch_done, fetch_size, fprintf, last_progress_report, now(), showprogress, snprintf, and UINT64_FORMAT.
Referenced by perform_rewind().
|
static |
Definition at line 733 of file pg_rewind.c.
References CATALOG_VERSION_NO, ControlFileData::catalog_version_no, ControlFile_source, ControlFile_target, ControlFileData::data_checksum_version, datadir_source, DB_SHUTDOWNED, DB_SHUTDOWNED_IN_RECOVERY, PG_CONTROL_VERSION, ControlFileData::pg_control_version, PG_DATA_CHECKSUM_VERSION, pg_fatal, ControlFileData::state, ControlFileData::system_identifier, and ControlFileData::wal_log_hints.
Referenced by main().
|
static |
|
static |
Definition at line 71 of file pg_rewind.c.
Referenced by ensureCleanShutdown(), getRestoreCommand(), and main().
|
static |
Definition at line 88 of file pg_rewind.c.
Referenced by disconnect_atexit(), and main().
|
static |
Definition at line 69 of file pg_rewind.c.
Referenced by main(), and perform_rewind().
|
static |
Definition at line 60 of file pg_rewind.c.
Referenced by main(), perform_rewind(), and sanityChecks().
|
static |
Definition at line 61 of file pg_rewind.c.
Referenced by perform_rewind().
|
static |
Definition at line 59 of file pg_rewind.c.
Referenced by main(), and sanityChecks().
|
static |
Definition at line 68 of file pg_rewind.c.
Referenced by main(), perform_rewind(), and sanityChecks().
char* datadir_target = NULL |
Definition at line 67 of file pg_rewind.c.
Referenced by create_target_dir(), create_target_symlink(), ensureCleanShutdown(), getRestoreCommand(), getTimelineHistory(), main(), open_target_file(), perform_rewind(), remove_target_dir(), remove_target_file(), remove_target_symlink(), sync_target_dir(), and truncate_target_file().
Definition at line 73 of file pg_rewind.c.
Referenced by getTimelineHistory(), and main().
Definition at line 76 of file pg_rewind.c.
Referenced by main(), and perform_rewind().
Definition at line 75 of file pg_rewind.c.
Referenced by ensureCleanShutdown(), main(), and perform_rewind().
uint64 fetch_done |
Definition at line 86 of file pg_rewind.c.
Referenced by main(), progress_report(), and write_target_range().
uint64 fetch_size |
Definition at line 85 of file pg_rewind.c.
Referenced by main(), postgresAcquireSampleRowsFunc(), and progress_report().
|
static |
Definition at line 63 of file pg_rewind.c.
Referenced by ensureCleanShutdown(), getRestoreCommand(), main(), and usage().
|
static |
Definition at line 70 of file pg_rewind.c.
Referenced by getRestoreCommand(), and main().
Definition at line 77 of file pg_rewind.c.
Referenced by getRestoreCommand(), and main().
Definition at line 74 of file pg_rewind.c.
Referenced by main(), perform_rewind(), and progress_report().
|
static |
Definition at line 89 of file pg_rewind.c.
Referenced by append_pathkeys(), appendByteaLiteral(), appendStringLiteral(), ApplySetting(), bpchar(), BufFileAppend(), call_bool_check_hook(), call_enum_check_hook(), call_int_check_hook(), call_real_check_hook(), call_string_check_hook(), check_datestyle(), check_default_table_access_method(), check_default_tablespace(), check_default_text_search_config(), check_locale_messages(), check_random_seed(), check_role(), check_session_authorization(), check_temp_buffers(), check_temp_tablespaces(), check_timezone_abbreviations(), compute_remaining_iovec(), CopyIndexTuple(), exprLocation(), fmgr_security_definer(), gets_fromFile(), getTimelineHistory(), index_truncate_tuple(), initClosestMatch(), InitializeGUCOptionsFromEnvironment(), interval_support(), libpq_destroy(), libpq_fetch_file(), libpq_finish_fetch(), libpq_get_current_wal_insert_lsn(), libpq_queue_fetch_file(), libpq_queue_fetch_range(), libpq_traverse_files(), local_destroy(), local_fetch_file(), local_queue_fetch_file(), local_queue_fetch_range(), local_traverse_files(), main(), MainLoop(), numeric_support(), packGraph(), parse_and_validate_value(), perform_rewind(), pg_utf8_islegal(), pg_utf8_string_len(), pglz_compress(), pglz_decompress(), plsample_func_handler(), plsample_trigger_handler(), PQescapeStringInternal(), process_backslash_command(), ProcessGUCArray(), quote_if_needed(), raw_expression_tree_walker_impl(), reconstruct_from_incremental_file(), selectColorTrigrams(), set_config_option(), set_config_option_ext(), set_config_with_handle(), set_debug_options(), set_plan_disabling_options(), SetConfigOption(), string_to_uuid(), strip_quotes(), syntax_error(), TemporalSimplify(), transform_MERGE_to_join(), translate(), varbit_support(), varchar(), varchar_support(), varstr_levenshtein(), XLogCompressBackupBlock(), XLogFileRead(), and XLogFileReadAnyTLI().
DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC |
Definition at line 78 of file pg_rewind.c.
Referenced by main().
TimeLineHistoryEntry* targetHistory |
Definition at line 81 of file pg_rewind.c.
Referenced by main(), and SimpleXLogPageRead().
int targetNentries |
Definition at line 82 of file pg_rewind.c.
Referenced by main(), and SimpleXLogPageRead().
int WalSegSz |
Definition at line 64 of file pg_rewind.c.
Referenced by createBackupLabel(), and digestControlFile().