PostgreSql pg_ctl command

I. Overview

Tools for controlling PostgreSQL services.

2. Grammar

--初始化数据库实例
pg_ctl init[db] [-D datadir] [-s] [-o initdb-options]

--启动数据库实例
pg_ctl start [-D datadir] [-l filename] [-W] [-t seconds] [-s] [-o options] [-p path] [-c]

--停止数据库实例
pg_ctl stop [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s]

--重启数据库实例
pg_ctl restart [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ] [-W] [-t seconds] [-s] [-o options] [-c]

--重新加载数据库配置文件
pg_ctl reload [-D datadir] [-s]

--查看数据库状态
pg_ctl status [-D datadir]

--备库切换为主库
pg_ctl promote [-D datadir] [-W] [-t seconds] [-s]

--轮换服务器日志文件
pg_ctl logrotate [-D datadir] [-s]

--向一个指定进程发送一个消息
pg_ctl kill signal_name process_id 

--注册服务(Windows)
pg_ctl register [-D datadir] [-N servicename] [-U username] [-P password] [-S a[uto] | d[emand] ] [-e source] [-W] [-t seconds] [-s] [-o options]

--移除服务(Windows)
pg_ctl unregister [-N servicename]

init or initdb: Invokes the initdb command. See initdb for details.

Parameter description :

-c or --core-files : Generate core files for server crashes.
-D datadir or --pgdata=datadir : Specify the database data file location. If this option is omitted, the environment variable PGDATA will be used.
-l filename or --log=filename : Append server log output to filename.
-m mode or --mode=mode : Specifies the shutdown mode. mode can be smart, fast, or immediate, or the first letter of any of these three. If this option is omitted, fast is the default.
-o options or --options=options : Specifies options to be passed directly to the postgres command. -o can be specified multiple times, all given options will be passed. These options should usually be surrounded by single or double quotes to ensure they are passed as a group.
-o initdb-options or --options=initdb-options : Specifies options to pass directly to the initdb command. -o can be specified multiple times, all given options will be passed. These options should usually be surrounded by single or double quotes to ensure they are passed as a group.
-p path : Specifies the location of the postgres executable. By default, the postgres executable is available from the same directory as pg_ctl, or if not found there, in the hard-coded installation directory. Unless you're doing something unusual and get errors saying the postgres executable was not found, this option isn't necessary. In init mode, this option is like specifying the location of the initdb executable.
-s or --silent : only print errors, do not print informational messages.
-t seconds or --timeout=seconds : Specifies the maximum number of seconds to wait for an operation to complete (see option -w). Defaults to the value of the PGCTLTIMEOUT environment variable, or 60 seconds if the environment variable is not set.
-V or --version : print pg_ctl version and exit.
-w or --wait : Wait for the operation to complete. The modes start, stop, restart, promote, and register support this option and are the default for those modes. While waiting, pg_ctl checks the server's PID file over and over, sleeping for a short time between checks. A start operation is considered complete when the PID file indicates that the server is ready to accept connections. A shutdown operation is considered complete when the server removes the PID file. pg_ctl returns an exit code based on the success of the startup or shutdown. If the operation fails to complete within the timeout (see option -t), pg_ctl exits with a nonzero exit status. But be aware that the operation may continue in the background and eventually succeed.
-W or --no-wait : Do not wait for the operation to complete. This is the opposite of option -w. If waiting is disabled, the requested action will be triggered, but there will be no feedback about its success or failure. In this case, it may be necessary to check the progress and success of the operation with server log files or an external monitoring system. In previous versions of PostgreSQL, this was the default option for modes other than stop.

Parameter description (Windows):

-e source : The name of the event source that pg_ctl will use to log in the event log when running as a Windows service. The default is PostgreSQL. Note that this only controls messages sent by pg_ctl itself, once started, the server will use the event source specified in the event_source parameter. If the server fails very early on startup (before this parameter is set), it may also log using the default event source name of PostgreSQL.
-N servicename : The name of the system service to register. This name will be used for the service name and display name. Default PostgreSQL.
-P password : Password for the user running the service.
-S start-type : The start type of the system service to register. The startup type can be auto, demand, or the first letter of either. If this option is omitted, auto is the default.
-U username : The username for the user running the service. For domain users, use the format DOMAIN\username.

3. Example

--启动 
pg_ctl start

--要使用端口 5433 启动,并且运行时不使用fsync: 
pg_ctl -o "-F -p 5433" start
 
--停止
pg_ctl stop
pg_ctl stop -m smart

--重启
pg_ctl restart

--如果指定了-o,则会替换任何之前的选项。要使用端口 5433 重启并在重启时禁用fsync: 
pg_ctl -o "-F -p 5433" restart

--查看状态
pg_ctl status
pg_ctl: server is running (PID: 13718)
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128"
第二行是在重启模式可能被调用的命令行。 

Guess you like

Origin blog.csdn.net/songyundong1993/article/details/132079760