Postgresql 中文操作指南

pg_isready

pg_isready——检查 PostgreSQL 服务器的连接状态

pg_isready — check the connection status of a PostgreSQL server

Synopsis

pg_isready [ connection-option …​] [ option …​]

pg_isready [connection-option…​] [option…​]

Description

pg_isready 是检查 PostgreSQL 数据库服务器的连接状态的实用程序。退出状态指定连接检查的结果。

pg_isready is a utility for checking the connection status of a PostgreSQL database server. The exit status specifies the result of the connection check.

Options

  • -d _dbname—​dbname=_dbname

    • Specifies the name of the database to connect to. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options.

  • -h _hostname—​host=_hostname

    • Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix-domain socket.

  • -p _port—​port=_port

    • Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the PGPORT environment variable or, if not set, to the port specified at compile time, usually 5432.

  • -q_—​quiet_

    • Do not display status message. This is useful when scripting.

  • -t _seconds—​timeout=_seconds

    • The maximum number of seconds to wait when attempting connection before returning that the server is not responding. Setting to 0 disables. The default is 3 seconds.

  • -U _username—​username=_username

    • Connect to the database as the user username instead of the default.

  • -V_—​version_

    • Print the pg_isready version and exit.

  • -?_—​help_

    • Show help about pg_isready command line arguments, and exit.

Exit Status

如果服务器正常接受连接,pg_isready 将返回 0 给 shell,如果服务器拒绝连接(例如在启动期间),返回 1 ,如果连接尝试无响应,返回 2 ,如果未进行尝试(例如由于无效的参数),返回 3

pg_isready returns 0 to the shell if the server is accepting connections normally, 1 if the server is rejecting connections (for example during startup), 2 if there was no response to the connection attempt, and 3 if no attempt was made (for example due to invalid parameters).

Environment

与大多数 PostgreSQL 实用程序一样, pg_isready 也使用 libpq 支持的环境变量(参见 Section 34.15 )。

pg_isready, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 34.15).

环境变量 PG_COLOR 指定是否在诊断消息中使用颜色。可能的值是 alwaysautonever

The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never.

Notes

不需要提供正确用户名、密码或数据库名称值来获取服务器状态;然而,如果提供的数值不正确,服务器将记录失败的连接尝试。

It is not necessary to supply correct user name, password, or database name values to obtain the server status; however, if incorrect values are provided, the server will log a failed connection attempt.

Examples

标准使用方法:

Standard Usage:

$ pg_isready
/tmp:5432 - accepting connections
$ echo $?
0

在启动时运行带有关联参数到 PostgreSQL 集群:

Running with connection parameters to a PostgreSQL cluster in startup:

$ pg_isready -h localhost -p 5433
localhost:5433 - rejecting connections
$ echo $?
1

运行带有关联参数到无响应 PostgreSQL 集群:

Running with connection parameters to a non-responsive PostgreSQL cluster:

$ pg_isready -h someremotehost
someremotehost:5432 - no response
$ echo $?
2