PG_ISREADY(1)
π pg_isready β check the connection status of a PostgreSQL server π
okay bestie, welcome to pg_isready(1) from the PostgreSQL 13.23 docs β¨ this is the little cutie that just pokes your server to see if it's alive β that's it, that's the whole job π«Ά
πΈ SYNOPSIS πΈ
pg_isready [connection-option...] [option...]
β¨ DESCRIPTION β¨
pg_isready is a utility for checking the connection status of a PostgreSQL database server. Literally its whole personality π
it goes and checks, and then it tells you the answer through its exit status β which is the actual result of the connection check. No cap, the exit code is the tea β
π OPTIONS π
-ddbname,--dbname=dbname β tells it which database to connect to. plot twist: dbname can be a connection string, and if it is, the parameters in that connection string will override any conflicting command line options. so the connection string wins the argument, periodt π-hhostname,--host=hostname β the host name of the machine the server's running on. and if the value starts with a slash/, it gets used as the directory for the Unix-domain socket β yes queen, the path is the host, iykyk π¦-pport,--port=port β the TCP port, or the local Unix-domain socket file extension, that the server is listening on for connections. default? it takes the value of thePGPORTenvironment variable, or if that's not set, the port specified at compile time β usually5432π«-q,--quietβ do not display the status message. this is the one for scripting, so your output stays clean and unbothered π-tseconds,--timeout=seconds β the max number of seconds to wait while attempting connection before it comes back with "the server is not responding". setting it to0disables the timeout entirely (bold move π). the default is3seconds β±οΈ-Uusername,--username=username β connect to the database as the user username instead of the default. main character energy, choose your own name π-V,--versionβ print thepg_isreadyversion and exit. short and sweet π-?,--helpβ show help aboutpg_isreadycommand line arguments, and exit. when in doubt, ask for help bestie π
π¦ EXIT STATUS π¦
pg_isready returns these to the shell β memorize them, they're the whole point fr fr:
0β the server is accepting connections normally β slay1β the server is rejecting connections (for example during startup) π§2β there was no response to the connection attempt π3β no attempt was made (for example due to invalid parameters) π
π ENVIRONMENT π
pg_isready, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 33.14).
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never. yes we're doing aesthetic diagnostics now π
π NOTES π
It is not necessary to supply correct user name, password, or database name values to obtain the server status β the check works anyway, iconique. however, if incorrect values are provided, the server will log a failed connection attempt. so likeβ¦ it still works, but there's a receipt in the logs π
π₯ EXAMPLES π₯
Standard Usage:
$ pg_isready
/tmp:5432 - accepting connections
$ echo $?
0
Running with connection parameters to a PostgreSQL cluster in startup:
$ pg_isready -h localhost -p 5433
localhost:5433 - rejecting connections
$ echo $?
1
Running with connection parameters to a non-responsive PostgreSQL cluster:
$ pg_isready -h someremotehost
someremotehost:5432 - no response
$ echo $?
2
okay that's the whole page, go check on your server bestie, it's giving healthy π β¨
mwah π this was PostgreSQL 13.23, dated 2025 β see you in the next manpage, ily π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms