PG_ISREADY(1)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸ’– 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 πŸŽ€

  • -d dbname, --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 πŸ‘‘
  • -h hostname, --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 πŸ¦‹
  • -p port, --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 the PGPORT environment variable, or if that's not set, the port specified at compile time β€” usually 5432 πŸ’«
  • -q, --quiet β€” do not display the status message. this is the one for scripting, so your output stays clean and unbothered πŸ’…
  • -t seconds, --timeout=seconds β€” the max number of seconds to wait while attempting connection before it comes back with "the server is not responding". setting it to 0 disables the timeout entirely (bold move 😭). the default is 3 seconds ⏱️
  • -U username, --username=username β€” connect to the database as the user username instead of the default. main character energy, choose your own name πŸ‘‘
  • -V, --version β€” print the pg_isready version and exit. short and sweet πŸ“
  • -?, --help β€” show help about pg_isready command 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 βœ… slay
  • 1 β€” 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