PG_ISREADY(1)

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

πŸ’– pg_isready(1) β€” your lil vibe check for a Postgres server πŸ’–

okay so bestie, this is the PG_ISREADY(1) page, straight out of the PostgreSQL 16.15 docs, and it's genuinely one of the most useful lil tools in the whole toolbox. let's get into it 🫢


🌸 NAME 🌸

pg_isready β€” check the connection status of a PostgreSQL server

like, is the server up? is it down? is it going through something? pg_isready will tell you. no cap.


✨ SYNOPSIS ✨

pg_isready [connection-option...] [option...]

that's it. that's the whole thing. you throw connection options at it, you throw regular options at it, it goes and checks. iconic behavior honestly πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

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.

and that's the whole personality: it checks, and then it tells you the answer through its exit status. so if you're scripting, you're not parsing text β€” you're reading $? like the main character you are. ⭐

fr fr: the exit status is the answer. the pretty printed message is just a bonus.

πŸ’œ OPTIONS πŸ’œ

  • -d dbname, --dbname=dbname β€” Specifies the name of the database to connect to. plot twist: dbname can be a connection string, and if it is, connection string parameters will override any conflicting command line options. so the connection string wins the argument. periodt. πŸ‘‘
  • -h hostname, --host=hostname β€” Specifies the host name of the machine on which the server is running. and if the value begins with a slash, it's used as the directory for the Unix-domain socket. slash = socket, that's the trick iykyk 🧚
  • -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. lowkey the move when you just want the exit code and none of the chit-chat 🀫
  • -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. three seconds of patience, then it says what it says 😭
  • -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 🌈

get ready bestie, this is the whole point of the tool. pg_isready returns:

  1. 0 to the shell if the server is accepting connections normally β€” slay, we're so back πŸ’–
  2. 1 if the server is rejecting connections (for example during startup) β€” it's waking up, give it a minute
  3. 2 if there was no response to the connection attempt β€” πŸ’€
  4. 3 if no attempt was made (for example due to invalid parameters) β€” that one's on you, not the server πŸ™ˆ

πŸŽ€ ENVIRONMENT πŸŽ€

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

The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never. pretty messages? we love to see it πŸ’…


πŸ‘‘ 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.

so like β€” you can be messy and pass garbage credentials and still get your answer, but the server's log will remember. it always remembers. 😭


πŸ“ 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

see? three examples, three exit codes, all the vibes. πŸ¦‹


and that's the tea, bestie 🫢 this lil page came to you courtesy of PostgreSQL 16.15, dated 2026, under the manual name PG_ISREADY(1) β€” go check on your servers, they miss you βœ¨πŸ’–πŸŽ€

πŸ“¦ where this page comes from