PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include "catalog/pg_control.h"
#include "common/controldata_utils.h"
#include "common/file_perm.h"
#include "common/logging.h"
#include "common/string.h"
#include "getopt_long.h"
#include "utils/pidfile.h"
Go to the source code of this file.
Macros | |
#define | DEFAULT_WAIT 60 |
#define | USEC_PER_SEC 1000000 |
#define | WAITS_PER_SEC 10 /* should divide USEC_PER_SEC evenly */ |
Enumerations | |
enum | ShutdownMode { SMART_MODE , FAST_MODE , IMMEDIATE_MODE } |
enum | WaitPMResult { POSTMASTER_READY , POSTMASTER_STILL_STARTING , POSTMASTER_READY , POSTMASTER_STILL_STARTING , POSTMASTER_SHUTDOWN_IN_RECOVERY , POSTMASTER_FAILED } |
enum | CtlCommand { NO_COMMAND = 0 , INIT_COMMAND , START_COMMAND , STOP_COMMAND , RESTART_COMMAND , RELOAD_COMMAND , STATUS_COMMAND , PROMOTE_COMMAND , LOGROTATE_COMMAND , KILL_COMMAND , REGISTER_COMMAND , UNREGISTER_COMMAND , RUN_AS_SERVICE_COMMAND } |
Functions | |
static void | write_stderr (const char *fmt,...) pg_attribute_printf(1 |
static void static void | do_advice (void) |
static void | do_help (void) |
static void | set_mode (char *modeopt) |
static void | set_sig (char *signame) |
static void | do_init (void) |
static void | do_start (void) |
static void | do_stop (void) |
static void | do_restart (void) |
static void | do_reload (void) |
static void | do_status (void) |
static void | do_promote (void) |
static void | do_logrotate (void) |
static void | do_kill (pid_t pid) |
static void | print_msg (const char *msg) |
static void | adjust_data_dir (void) |
static pid_t | get_pgpid (bool is_status_request) |
static char ** | readfile (const char *path, int *numlines) |
static void | free_readfile (char **optlines) |
static pid_t | start_postmaster (void) |
static void | read_post_opts (void) |
static WaitPMResult | wait_for_postmaster_start (pid_t pm_pid, bool do_checkpoint) |
static bool | wait_for_postmaster_stop (void) |
static bool | wait_for_postmaster_promote (void) |
static bool | postmaster_is_alive (pid_t pid) |
static void | unlimit_core_size (void) |
static DBState | get_control_dbstate (void) |
static void | trap_sigint_during_startup (SIGNAL_ARGS) |
static char * | find_other_exec_or_die (const char *argv0, const char *target, const char *versionstr) |
int | main (int argc, char **argv) |
Variables | |
static bool | do_wait = true |
static int | wait_seconds = DEFAULT_WAIT |
static bool | wait_seconds_arg = false |
static bool | silent_mode = false |
static ShutdownMode | shutdown_mode = FAST_MODE |
static int | sig = SIGINT |
static CtlCommand | ctl_command = NO_COMMAND |
static char * | pg_data = NULL |
static char * | pg_config = NULL |
static char * | pgdata_opt = NULL |
static char * | post_opts = NULL |
static const char * | progname |
static char * | log_file = NULL |
static char * | exec_path = NULL |
static char * | event_source = NULL |
static char * | register_servicename = "PostgreSQL" |
static char * | register_username = NULL |
static char * | register_password = NULL |
static char * | argv0 = NULL |
static bool | allow_core_files = false |
static time_t | start_time |
static char | postopts_file [MAXPGPATH] |
static char | version_file [MAXPGPATH] |
static char | pid_file [MAXPGPATH] |
static char | promote_file [MAXPGPATH] |
static char | logrotate_file [MAXPGPATH] |
static volatile pid_t | postmasterPID = -1 |
#define WAITS_PER_SEC 10 /* should divide USEC_PER_SEC evenly */ |
enum CtlCommand |
enum ShutdownMode |
enum WaitPMResult |
|
static |
Definition at line 2125 of file pg_ctl.c.
References _, argv0, canonicalize_path(), exec_path, exit(), fd(), fflush(), filename, find_other_exec_or_die(), free, MAXPGPATH, my_exec_path, PG_BACKEND_VERSIONSTR, pg_config, pg_data, pg_strdup(), pg_strip_crlf(), pgdata_opt, post_opts, progname, psprintf(), snprintf, and write_stderr().
Referenced by main().
|
static |
Definition at line 1965 of file pg_ctl.c.
References _, progname, and write_stderr().
Referenced by main(), set_mode(), and set_sig().
|
static |
|
static |
Definition at line 902 of file pg_ctl.c.
References _, argv0, DEVNULL, exec_path, exit(), fflush(), find_other_exec_or_die(), pgdata_opt, post_opts, progname, psprintf(), silent_mode, and write_stderr().
Referenced by main().
|
static |
|
static |
Definition at line 1267 of file pg_ctl.c.
References _, exit(), get_pgpid(), kill, logrotate_file, MAXPGPATH, pg_data, pid_file, print_msg(), progname, sig, SIGUSR1, snprintf, and write_stderr().
Referenced by main().
|
static |
Definition at line 1186 of file pg_ctl.c.
References _, DB_IN_ARCHIVE_RECOVERY, do_wait, exit(), get_control_dbstate(), get_pgpid(), kill, MAXPGPATH, pg_data, pid_file, print_msg(), progname, promote_file, sig, SIGUSR1, snprintf, wait_for_postmaster_promote(), and write_stderr().
Referenced by main().
|
static |
Definition at line 1149 of file pg_ctl.c.
References _, exit(), get_pgpid(), kill, pid_file, print_msg(), progname, sig, and write_stderr().
Referenced by main().
|
static |
Definition at line 1085 of file pg_ctl.c.
References _, do_start(), exit(), get_pgpid(), kill, pid_file, postmaster_is_alive(), print_msg(), progname, shutdown_mode, sig, SMART_MODE, wait_for_postmaster_stop(), and write_stderr().
Referenced by main().
|
static |
Definition at line 931 of file pg_ctl.c.
References _, allow_core_files, argv0, ctl_command, do_wait, exec_path, exit(), find_other_exec_or_die(), get_pgpid(), PG_BACKEND_VERSIONSTR, pgdata_opt, POSTMASTER_FAILED, POSTMASTER_READY, POSTMASTER_SHUTDOWN_IN_RECOVERY, POSTMASTER_STILL_STARTING, postmasterPID, pqsignal(), print_msg(), progname, read_post_opts(), RESTART_COMMAND, setenv, snprintf, start_postmaster(), trap_sigint_during_startup(), unlimit_core_size(), wait_for_postmaster_start(), and write_stderr().
Referenced by do_restart(), and main().
|
static |
Definition at line 1348 of file pg_ctl.c.
References _, exit(), free_readfile(), get_pgpid(), postmaster_is_alive(), postopts_file, printf, progname, and readfile().
Referenced by main().
|
static |
Definition at line 1027 of file pg_ctl.c.
References _, do_wait, exit(), get_pgpid(), kill, pid_file, print_msg(), progname, shutdown_mode, sig, SMART_MODE, wait_for_postmaster_stop(), and write_stderr().
Referenced by main().
|
static |
Definition at line 875 of file pg_ctl.c.
References _, argv0, exit(), find_my_exec(), find_other_exec(), MAXPGPATH, pg_malloc(), progname, strlcpy(), and write_stderr().
Referenced by adjust_data_dir(), do_init(), and do_start().
|
static |
Definition at line 410 of file pg_ctl.c.
Referenced by do_status(), read_post_opts(), and wait_for_postmaster_start().
|
static |
Definition at line 2183 of file pg_ctl.c.
References _, exit(), get_controlfile(), pfree(), pg_data, progname, ControlFileData::state, and write_stderr().
Referenced by do_promote(), wait_for_postmaster_promote(), and wait_for_postmaster_start().
|
static |
Definition at line 246 of file pg_ctl.c.
References _, exit(), pg_data, pid_file, progname, stat, version_file, and write_stderr().
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_status(), do_stop(), wait_for_postmaster_promote(), and wait_for_postmaster_stop().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 2202 of file pg_ctl.c.
References _, adjust_data_dir(), allow_core_files, argv0, canonicalize_path(), ctl_command, do_advice(), do_help(), do_init(), do_kill(), do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_status(), do_stop(), do_wait, event_source, exec_path, exit(), free, get_progname(), GetDataDirectoryCreatePerm(), getopt_long(), INIT_COMMAND, KILL_COMMAND, log_file, LOGROTATE_COMMAND, MAXPGPATH, no_argument, NO_COMMAND, optarg, optind, pg_config, pg_data, pg_logging_init(), pg_mode_mask, PG_MODE_MASK_OWNER, pg_strdup(), PG_TEXTDOMAIN, pgdata_opt, pid_file, post_opts, postopts_file, progname, PROMOTE_COMMAND, psprintf(), REGISTER_COMMAND, register_password, register_servicename, register_username, RELOAD_COMMAND, required_argument, RESTART_COMMAND, RUN_AS_SERVICE_COMMAND, set_mode(), set_pglocale_pgservice(), set_sig(), setenv, sig, SIGHUP, silent_mode, snprintf, START_COMMAND, start_time, STATUS_COMMAND, STOP_COMMAND, UNREGISTER_COMMAND, version_file, wait_seconds, wait_seconds_arg, and write_stderr().
|
static |
Definition at line 1324 of file pg_ctl.c.
References kill.
Referenced by do_restart(), and do_status().
|
static |
Definition at line 236 of file pg_ctl.c.
References fflush(), silent_mode, and generate_unaccent_rules::stdout.
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_stop(), wait_for_postmaster_promote(), wait_for_postmaster_start(), and wait_for_postmaster_stop().
|
static |
Definition at line 802 of file pg_ctl.c.
References _, ctl_command, exec_path, exit(), free_readfile(), pg_strdup(), post_opts, postopts_file, progname, readfile(), RESTART_COMMAND, and write_stderr().
Referenced by do_start().
|
static |
Definition at line 314 of file pg_ctl.c.
References close, fd(), free, fstat, i, len, PG_BINARY, pg_malloc(), read, and stat::st_size.
Referenced by do_status(), read_post_opts(), and wait_for_postmaster_start().
|
static |
Definition at line 2047 of file pg_ctl.c.
References _, do_advice(), exit(), FAST_MODE, IMMEDIATE_MODE, progname, shutdown_mode, sig, SIGQUIT, SMART_MODE, and write_stderr().
Referenced by main().
|
static |
|
static |
Definition at line 440 of file pg_ctl.c.
References _, close, DEVNULL, exec_path, exit(), fd(), fflush(), log_file, pgdata_opt, post_opts, progname, psprintf(), and write_stderr().
Referenced by check_and_dump_old_cluster(), do_start(), issue_warnings_and_set_wal_level(), main(), and setup().
|
static |
Definition at line 857 of file pg_ctl.c.
References _, kill, postmasterPID, pqsignal(), progname, SIG_DFL, and write_stderr().
Referenced by do_start().
|
static |
Definition at line 782 of file pg_ctl.c.
References _, progname, and write_stderr().
Referenced by do_start().
|
static |
Definition at line 754 of file pg_ctl.c.
References DB_IN_PRODUCTION, get_control_dbstate(), get_pgpid(), kill, pg_usleep(), print_msg(), USEC_PER_SEC, wait_seconds, and WAITS_PER_SEC.
Referenced by do_promote().
|
static |
Definition at line 593 of file pg_ctl.c.
References DB_SHUTDOWNED_IN_RECOVERY, free_readfile(), get_control_dbstate(), i, LOCK_FILE_LINE_PID, LOCK_FILE_LINE_PM_STATUS, LOCK_FILE_LINE_START_TIME, pg_usleep(), pid_file, PM_STATUS_READY, PM_STATUS_STANDBY, POSTMASTER_FAILED, POSTMASTER_READY, POSTMASTER_SHUTDOWN_IN_RECOVERY, POSTMASTER_STILL_STARTING, print_msg(), readfile(), start_time, USEC_PER_SEC, wait_seconds, and WAITS_PER_SEC.
Referenced by do_start().
|
static |
Definition at line 717 of file pg_ctl.c.
References get_pgpid(), kill, pg_usleep(), print_msg(), USEC_PER_SEC, wait_seconds, and WAITS_PER_SEC.
Referenced by do_restart(), and do_stop().
|
static |
Definition at line 202 of file pg_ctl.c.
References fmt, pgwin32_is_service(), va_end(), va_start(), vfprintf(), and vsnprintf.
Referenced by adjust_data_dir(), do_advice(), do_init(), do_kill(), do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_stop(), find_other_exec_or_die(), get_control_dbstate(), get_pgpid(), main(), read_post_opts(), set_mode(), set_sig(), start_postmaster(), trap_sigint_during_startup(), and unlimit_core_size().
Definition at line 94 of file pg_ctl.c.
Referenced by do_start(), and main().
|
static |
Definition at line 93 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_start(), ensureCleanShutdown(), find_my_exec(), find_other_exec(), find_other_exec_or_die(), get_exec_path(), get_progname(), getInstallationPaths(), getRestoreCommand(), InitStandaloneProcess(), main(), pg_logging_init(), process_psqlrc(), set_pglocale_pgservice(), setup(), and setup_bin_paths().
|
static |
Definition at line 81 of file pg_ctl.c.
Referenced by do_start(), main(), and read_post_opts().
Definition at line 75 of file pg_ctl.c.
Referenced by do_promote(), do_start(), do_stop(), getMessageFromWorker(), ListenToWorkers(), main(), and WaitForWorkers().
|
static |
Definition at line 88 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_start(), ensureCleanShutdown(), get_exec_path(), main(), read_post_opts(), setup(), and start_postmaster().
|
static |
Definition at line 87 of file pg_ctl.c.
Referenced by exec_prog(), main(), parallel_exec_prog(), and start_postmaster().
|
static |
Definition at line 101 of file pg_ctl.c.
Referenced by do_logrotate().
|
static |
Definition at line 83 of file pg_ctl.c.
Referenced by adjust_data_dir(), and main().
|
static |
Definition at line 82 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_logrotate(), do_promote(), get_control_dbstate(), get_pgpid(), and main().
|
static |
Definition at line 84 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_start(), main(), and start_postmaster().
|
static |
Definition at line 99 of file pg_ctl.c.
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_stop(), get_pgpid(), main(), and wait_for_postmaster_start().
|
static |
Definition at line 85 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), main(), read_post_opts(), and start_postmaster().
|
static |
Definition at line 103 of file pg_ctl.c.
Referenced by do_start(), and trap_sigint_during_startup().
|
static |
Definition at line 97 of file pg_ctl.c.
Referenced by do_status(), main(), and read_post_opts().
|
static |
Definition at line 86 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_advice(), do_help(), do_init(), do_kill(), do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_status(), do_stop(), find_other_exec_or_die(), get_control_dbstate(), get_pgpid(), main(), read_post_opts(), set_mode(), set_sig(), start_postmaster(), trap_sigint_during_startup(), and unlimit_core_size().
|
static |
Definition at line 100 of file pg_ctl.c.
Referenced by do_promote(), and pg_promote().
|
static |
|
static |
Definition at line 79 of file pg_ctl.c.
Referenced by do_restart(), do_stop(), and set_mode().
|
static |
Definition at line 80 of file pg_ctl.c.
Referenced by _discoverArchiveFormat(), checkcondition_bit(), create_LifetimeEnd(), do_kill(), do_logrotate(), do_promote(), do_reload(), do_restart(), do_stop(), gist_qtxt(), main(), pg_signal_backend(), pgwin32_dispatch_queued_signals(), set_mode(), set_sig(), and StatementTimeoutHandler().
Definition at line 78 of file pg_ctl.c.
Referenced by do_init(), main(), and print_msg().
|
static |
Definition at line 95 of file pg_ctl.c.
Referenced by ApplyLauncherSetWorkerStartTime(), bgworker_should_start_now(), ConditionVariableTimedSleep(), feTimestampDifference(), feTimestampDifferenceExceeds(), log_status_format(), main(), pgstat_count_io_op_time(), run_permutation(), test_timing(), TimestampDifference(), TimestampDifferenceExceeds(), TimestampDifferenceMilliseconds(), try_complete_step(), wait_for_postmaster_start(), WaitEventSetWait(), and write_jsonlog().
|
static |
Definition at line 98 of file pg_ctl.c.
Referenced by get_pgpid(), main(), and write_version_file().
|
static |
Definition at line 76 of file pg_ctl.c.
Referenced by main(), pg_promote(), regression_main(), wait_for_postmaster_promote(), wait_for_postmaster_start(), and wait_for_postmaster_stop().