{"id":20245576,"url":"https://github.com/noloader/pg_check_conn","last_synced_at":"2026-06-08T00:31:21.020Z","repository":{"id":58715633,"uuid":"533324399","full_name":"noloader/pg_check_conn","owner":"noloader","description":"A PostgreSQL utility to check a user's access to a database","archived":false,"fork":false,"pushed_at":"2022-09-08T17:16:15.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-03T15:46:56.258Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noloader.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-06T12:56:49.000Z","updated_at":"2022-09-06T14:08:03.000Z","dependencies_parsed_at":"2023-01-18T01:30:42.262Z","dependency_job_id":null,"html_url":"https://github.com/noloader/pg_check_conn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/noloader/pg_check_conn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noloader%2Fpg_check_conn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noloader%2Fpg_check_conn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noloader%2Fpg_check_conn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noloader%2Fpg_check_conn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noloader","download_url":"https://codeload.github.com/noloader/pg_check_conn/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noloader%2Fpg_check_conn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34043822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-07T02:00:07.652Z","response_time":124,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T09:22:12.184Z","updated_at":"2026-06-08T00:31:21.001Z","avatar_url":"https://github.com/noloader.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg_check_conn\n\nA PostgreSQL utility to check a user's access to a database. `pg_check_conn` will use supplied options to connect to a PostgreSQL database and return `0` on success, and `PQstatus` otherwise.\n\n`pg_check_conn` is a direct replacement for `pg_isready`. The new utility accepts the same options as `pg_isready`: database (`-d`), hostname (`-h`), username (`-U`), port (`-p`), and timeout (`-t`). Environmental variables, like `PGPASSWORD`, should work as expected as `pg_check_conn` leaves them in tact for the underlying `libpg` library.\n\nThe reason for the `pg_check_conn` utility is, `pg_isready` does not use options when it tests a connection. If you use a fictitious or incorrect option like `-d foo`, `-U bar` or `PGPASSWORD=baz`, then `pg_isready` will still return success if the PostgreSQL server is running and accepting connections. For the details, see [Determine if a user and database are available](https://www.postgresql.org/message-id/CAH8yC8%3DfbU-DWSNso7qKDSNCj52hTop8ENKxF7_4a%3DhjY-nn6w%40mail.gmail.com) on the pgsql-general mailing list.\n\n## Prerequisites\n\n`pg_check_conn` requires the PostgreSQL development package and a C++ compiler. C++ simplifies the program by handling memory management.\n\nThe PostgreSQL development packages are `libpq-dev` on Debian and derivatives like Ubuntu; and `libpq-devel` on Red Hat derivatives, like CentOS and Fedora.\n\n## Compiling pg_check_conn\n\nYou can compile `pg_check_conn` with the following command:\n\n```bash\ng++ -g -O2 `pkg-config --cflags libpq` pg_check_conn.cpp -o pg_check_conn `pkg-config --libs libpq`\n```\n\n## Running pg_check_conn\n\n`pg_check_conn` is a direct replacement for `pg_isready`. Running `pg_check_conn` with no issues will result in success and a return code of 0. On error, an error string written to standard output as reported by `PQerrorMessage` and the value of `PQstatus` is returned by the program. The examples below show two typical failues.\n\n```bash\n$ PGPASSWORD=${password} pg_check_conn -h \"${hostname}\" -U \"${username}\" -d \"${database}\" -p \"${port}\"\nError: connection to server at \"localhost\" (::1), port 5432 failed: FATAL: Ident authentication failed for user \"postgres\"\n```\n\nand\n\n```bash\n$ PGPASSWORD=${password} pg_check_conn -U \"${username}\" -d \"${database}\" -p \"${port}\"\nError: connection to server on socket \"/var/run/postgresql/.s.PGSQL.5432\" failed: FATAL: Peer authentication failed for user \"postgres\"\n```\n\nThe exit code for `pg_check_conn` is different than `pg_isready` since `pg_isready` returns success for nearly everything, including a missing database, a missing user, bad credentials and an incorrect authentication method. `pg_isready` would have reported success in the examples since the server was running and accepting connections.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoloader%2Fpg_check_conn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoloader%2Fpg_check_conn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoloader%2Fpg_check_conn/lists"}