The pg_ctl status
command suggested in other answers checks that the postmaster process exists and if so reports that it's running. That doesn't necessarily mean it is ready to accept connections or execute queries.
It is better to use another method like using psql
to run a simple query and checking the exit code, e.g. psql -c 'SELECT 1'
, or use pg_isready
to check the connection status.