brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pg_isready checks whether a PostgreSQL database accepts connections, using an exit code

Database
~/tips/tip-database-pg-isready-exit-code

pg_isready -h 127.0.0.1 -p 5432

Tests PostgreSQL availability without credentials and returns a script-friendly exit code.

For a healthcheck or a startup script I only need a yes or no, with no login. PostgreSQL ships a tool for that.

pg_isready -h 127.0.0.1 -p 5432
echo $?

pg_isready connects, does not log in, and reports through its exit code: 0 means the server accepts connections, 1 means it is up but rejecting them (for example while starting), 2 means no response and 3 means the check could not be attempted.

That makes it handy in a Docker healthcheck or a loop that waits before an app starts. It tells you the server is reachable, not that your user, password or database name are correct.

Further reading: PostgreSQL documentation: pg_isready

More Database tips mariadb -e 'CREATE DATABASE IF NOT EXISTS blog' mariadb-dump --no-create-info --insert-ignore shop orders > orders-rows.sql SELECT table_schema, table_name, CHECKSUM TABLE shop.orders; services: All Database tips (53) All topics

Link