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.
It can easily be used in bash. PostgresSQL Docs - pg_isready
Example Usage:
pg_isready -d <db_name> -h <host_name> -p <port_number> -U <db_user>
Exit Status
pg_isready
returns the following to the shell:
0 - 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).
Notice: man pg_isready
states: 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…