PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <fcntl.h>
#include <signal.h>
#include <time.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 */ |
Typedefs | |
typedef long | pgpid_t |
Enumerations | |
enum | ShutdownMode { SMART_MODE, FAST_MODE, IMMEDIATE_MODE } |
enum | WaitPMResult { POSTMASTER_READY, POSTMASTER_STILL_STARTING, 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 (pgpid_t pid) |
static void | print_msg (const char *msg) |
static void | adjust_data_dir (void) |
static pgpid_t | get_pgpid (bool is_status_request) |
static char ** | readfile (const char *path, int *numlines) |
static void | free_readfile (char **optlines) |
static pgpid_t | start_postmaster (void) |
static void | read_post_opts (void) |
static WaitPMResult | wait_for_postmaster (pgpid_t pm_pid, bool do_checkpoint) |
static bool | postmaster_is_alive (pid_t pid) |
static DBState | get_control_dbstate (void) |
static void | trap_sigint_during_startup (int sig) |
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 | backup_file [MAXPGPATH] |
static char | promote_file [MAXPGPATH] |
static char | logrotate_file [MAXPGPATH] |
static volatile pgpid_t | postmasterPID = -1 |
#define USEC_PER_SEC 1000000 |
Definition at line 75 of file pg_ctl.c.
Referenced by do_promote(), do_restart(), do_stop(), and wait_for_postmaster().
#define WAITS_PER_SEC 10 /* should divide USEC_PER_SEC evenly */ |
Definition at line 77 of file pg_ctl.c.
Referenced by do_promote(), do_restart(), do_stop(), and wait_for_postmaster().
enum CtlCommand |
Definition at line 56 of file pg_ctl.c.
enum ShutdownMode |
Enumerator | |
---|---|
SMART_MODE | |
FAST_MODE | |
IMMEDIATE_MODE |
enum WaitPMResult |
Enumerator | |
---|---|
POSTMASTER_READY | |
POSTMASTER_STILL_STARTING | |
POSTMASTER_FAILED |
|
static |
Definition at line 2176 of file pg_ctl.c.
References _, argv0, canonicalize_path(), exec_path, fd(), 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, snprintf, and write_stderr().
Referenced by main().
|
static |
Definition at line 2016 of file pg_ctl.c.
References _, progname, and write_stderr().
Referenced by main(), set_mode(), and set_sig().
|
static |
|
static |
Definition at line 829 of file pg_ctl.c.
References _, argv0, DEVNULL, exec_path, find_other_exec_or_die(), MAXPGPATH, pgdata_opt, post_opts, progname, silent_mode, snprintf, and write_stderr().
Referenced by main().
|
static |
Definition at line 1399 of file pg_ctl.c.
References _, AddUserToTokenDacl(), appendPQExpBuffer(), appendPQExpBufferStr(), argv0, createPQExpBuffer(), PQExpBufferData::data, DEFAULT_WAIT, do_wait, event_source, find_my_exec(), find_other_exec(), free, i, kill, make_absolute_path(), make_native_path(), MAXPGPATH, MCXT_ALLOC_NO_OOM, PG_BACKEND_VERSIONSTR, pg_config, pg_malloc_extended(), pg_strcasecmp(), post_opts, POSTMASTER_READY, postmasterPID, progname, read_post_opts(), register_password, register_servicename, register_username, sig, SIGHUP, silent_mode, snprintf, sprintf, status(), strerror, wait_for_postmaster(), wait_seconds, wait_seconds_arg, and write_stderr().
Referenced by main().
|
static |
Definition at line 1261 of file pg_ctl.c.
References _, get_pgpid(), kill, logrotate_file, MAXPGPATH, pg_data, pid_file, print_msg(), progname, sig, SIGUSR1, snprintf, strerror, and write_stderr().
Referenced by main().
|
static |
Definition at line 1167 of file pg_ctl.c.
References _, DB_IN_ARCHIVE_RECOVERY, DB_IN_PRODUCTION, DB_STARTUP, do_wait, get_control_dbstate(), get_pgpid(), kill, MAXPGPATH, pg_data, pg_usleep(), pid_file, print_msg(), progname, promote_file, sig, SIGUSR1, snprintf, strerror, USEC_PER_SEC, wait_seconds, WAITS_PER_SEC, and write_stderr().
Referenced by main().
|
static |
Definition at line 1130 of file pg_ctl.c.
References _, get_pgpid(), kill, pid_file, print_msg(), progname, sig, strerror, and write_stderr().
Referenced by main().
|
static |
Definition at line 1036 of file pg_ctl.c.
References _, backup_file, DB_IN_ARCHIVE_RECOVERY, do_start(), get_control_dbstate(), get_pgpid(), kill, pg_usleep(), pid_file, postmaster_is_alive(), print_msg(), progname, shutdown_mode, sig, SMART_MODE, stat, strerror, USEC_PER_SEC, wait_seconds, WAITS_PER_SEC, and write_stderr().
Referenced by main().
|
static |
Definition at line 857 of file pg_ctl.c.
References _, allow_core_files, argv0, ctl_command, do_wait, exec_path, find_other_exec_or_die(), get_pgpid(), PG_BACKEND_VERSIONSTR, pgdata_opt, POSTMASTER_FAILED, POSTMASTER_READY, POSTMASTER_STILL_STARTING, postmasterPID, pqsignal(), print_msg(), progname, read_post_opts(), RESTART_COMMAND, setenv, snprintf, start_postmaster(), trap_sigint_during_startup(), wait_for_postmaster(), and write_stderr().
Referenced by do_restart(), and main().
|
static |
Definition at line 1342 of file pg_ctl.c.
References _, free_readfile(), get_pgpid(), postmaster_is_alive(), postopts_file, printf, progname, and readfile().
Referenced by main().
|
static |
Definition at line 949 of file pg_ctl.c.
References _, backup_file, DB_IN_ARCHIVE_RECOVERY, do_wait, get_control_dbstate(), get_pgpid(), kill, pg_usleep(), pid_file, print_msg(), progname, shutdown_mode, sig, SMART_MODE, stat, strerror, USEC_PER_SEC, wait_seconds, WAITS_PER_SEC, and write_stderr().
Referenced by main().
|
static |
Definition at line 798 of file pg_ctl.c.
References _, 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 413 of file pg_ctl.c.
Referenced by do_status(), read_post_opts(), and wait_for_postmaster().
|
static |
Definition at line 2234 of file pg_ctl.c.
References _, get_controlfile(), pfree(), pg_data, progname, ControlFileData::state, and write_stderr().
Referenced by do_promote(), do_restart(), and do_stop().
Definition at line 249 of file pg_ctl.c.
References _, pg_data, pid_file, progname, stat, strerror, version_file, and write_stderr().
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_status(), and do_stop().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 2253 of file pg_ctl.c.
References _, adjust_data_dir(), allow_core_files, argv0, backup_file, 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, 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 1318 of file pg_ctl.c.
References kill.
Referenced by do_restart(), and do_status().
|
static |
Definition at line 239 of file pg_ctl.c.
References silent_mode, and generate_unaccent_rules::stdout.
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_start(), do_stop(), and wait_for_postmaster().
|
static |
Definition at line 725 of file pg_ctl.c.
References _, ctl_command, exec_path, free_readfile(), pg_strdup(), post_opts, postopts_file, progname, readfile(), RESTART_COMMAND, and write_stderr().
Referenced by do_kill(), and do_start().
|
static |
Definition at line 317 of file pg_ctl.c.
References close, fd(), free, fstat, i, PG_BINARY, pg_malloc(), read, and stat::st_size.
Referenced by do_status(), read_post_opts(), and wait_for_postmaster().
|
static |
Definition at line 2098 of file pg_ctl.c.
References _, do_advice(), FAST_MODE, IMMEDIATE_MODE, progname, shutdown_mode, sig, SIGQUIT, SMART_MODE, and write_stderr().
Referenced by main().
|
static |
Definition at line 2126 of file pg_ctl.c.
References _, do_advice(), progname, sig, SIGABRT, SIGHUP, SIGKILL, SIGQUIT, SIGUSR1, SIGUSR2, and write_stderr().
Referenced by main().
|
static |
Definition at line 443 of file pg_ctl.c.
References _, close, DEVNULL, exec_path, fd(), log_file, MAXPGPATH, pgdata_opt, post_opts, progname, snprintf, generate_unaccent_rules::stdout, strerror, 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 780 of file pg_ctl.c.
References _, kill, postmasterPID, pqsignal(), progname, SIG_DFL, strerror, and write_stderr().
Referenced by do_start().
|
static |
Definition at line 593 of file pg_ctl.c.
References _, free_readfile(), 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_STILL_STARTING, print_msg(), progname, readfile(), start_time, status(), USEC_PER_SEC, wait_seconds, WAITS_PER_SEC, and write_stderr().
Referenced by do_kill(), and do_start().
|
static |
Definition at line 205 of file pg_ctl.c.
References pgwin32_is_service(), 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 wait_for_postmaster().
Definition at line 98 of file pg_ctl.c.
Referenced by do_start(), and main().
|
static |
Definition at line 97 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_kill(), do_start(), and main().
|
static |
Definition at line 104 of file pg_ctl.c.
Referenced by do_restart(), do_stop(), and main().
|
static |
Definition at line 85 of file pg_ctl.c.
Referenced by do_start(), main(), and read_post_opts().
Definition at line 79 of file pg_ctl.c.
Referenced by do_kill(), do_promote(), do_start(), do_stop(), main(), and WaitForWorkers().
|
static |
|
static |
Definition at line 92 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_start(), ensureCleanShutdown(), main(), read_post_opts(), setup(), and start_postmaster().
|
static |
Definition at line 91 of file pg_ctl.c.
Referenced by main(), and start_postmaster().
|
static |
Definition at line 106 of file pg_ctl.c.
Referenced by do_logrotate().
|
static |
Definition at line 87 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_kill(), and main().
|
static |
Definition at line 86 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 88 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_start(), main(), and start_postmaster().
|
static |
Definition at line 103 of file pg_ctl.c.
Referenced by do_logrotate(), do_promote(), do_reload(), do_restart(), do_stop(), get_pgpid(), main(), and wait_for_postmaster().
|
static |
Definition at line 89 of file pg_ctl.c.
Referenced by adjust_data_dir(), do_init(), do_kill(), main(), read_post_opts(), and start_postmaster().
|
static |
Definition at line 108 of file pg_ctl.c.
Referenced by do_kill(), do_start(), and trap_sigint_during_startup().
|
static |
Definition at line 101 of file pg_ctl.c.
Referenced by do_status(), main(), and read_post_opts().
|
static |
Definition at line 90 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 wait_for_postmaster().
|
static |
Definition at line 105 of file pg_ctl.c.
Referenced by do_promote(), and pg_promote().
|
static |
|
static |
|
static |
|
static |
Definition at line 83 of file pg_ctl.c.
Referenced by do_restart(), do_stop(), and set_mode().
|
static |
Definition at line 84 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(), pgwin32_dispatch_queued_signals(), set_mode(), set_sig(), and StatementTimeoutHandler().
|
static |
Definition at line 99 of file pg_ctl.c.
Referenced by ConditionVariableTimedSleep(), feTimestampDifference(), feTimestampDifferenceExceeds(), initStats(), main(), test_timing(), TimestampDifference(), TimestampDifferenceExceeds(), TimestampDifferenceMilliseconds(), wait_for_postmaster(), and WaitEventSetWait().
|
static |
Definition at line 102 of file pg_ctl.c.
Referenced by get_pgpid(), main(), and write_version_file().
|
static |
Definition at line 80 of file pg_ctl.c.
Referenced by do_kill(), do_promote(), do_restart(), do_stop(), main(), pg_promote(), regression_main(), and wait_for_postmaster().