dbhealth-agent
Client-side agent for DBHealth — collects PostgreSQL
pg_stat_* health metrics, masks the literals in query text, and sends the
result to the DBHealth API, which turns it into a periodic health report by
email (weekly on paid plans, every four weeks on the free plan).
Privacy contract. The payload MAY contain: database, schema, table, index and role names exactly as they appear in your database (object identifiers are sent verbatim, including quoted identifiers and role names in statements such as GRANT, and are not masked); aggregate pg_stat metrics; the server version, collection timestamp and uptime; the backend PIDs of long-running queries; and query shapes with every literal replaced by ?. The payload NEVER contains row data, literal values or bind parameters, credentials or connection strings (DSNs), or the IP addresses, hostnames or application names of connected clients (none of these is sent). Literals are removed by a single-pass lexer that follows PostgreSQL literal syntax and is tested against the PostgreSQL lexer itself; input it cannot read with confidence, such as an unterminated string, is cut off rather than guessed at. This is tested, not proven: run dbhealth verify to see the exact payload.
Run dbhealth verify --json-output before your first real run: that JSON, not
this page, is the authoritative record of what would be sent for YOUR data.
Plain dbhealth verify prints a human-readable summary plus the same contract.
Your database credentials never leave your server: the agent reads directly
from Postgres and only ever ships the sanitized JSON body over an encrypted
connection (HTTPS; http://localhost/127.0.0.1 is permitted only for local
development and never reaches the network).
Install
Requires Python 3.10+ on a machine that can reach your PostgreSQL server, a read-only database user, and a DBHealth API token (shown once when you sign up at dbhealth.io).
The pg_stat_statements extension is optional: without it the slow-query
section of the report is empty and everything else still works. To see query
text from sessions other than its own (in pg_stat_activity and
pg_stat_statements), the read-only user needs the built-in pg_monitor role
(or pg_read_all_stats); without it those queries show as
<insufficient privilege>.
python3 -m venv ~/.dbhealth
. ~/.dbhealth/bin/activate
python -m pip install "dbhealth-agent==0.1.2"
Install into a dedicated virtualenv, not the system Python: current Debian and
Ubuntu (and Homebrew) mark the system Python "externally managed", so a bare
pip install fails there. On Debian/Ubuntu, python3 -m venv needs
sudo apt install python3-venv first.
Pin the exact version: the agent runs unattended against your production
database, so upgrades should be ones you chose. Add the cron extra
("dbhealth-agent[cron]==0.1.2") if you want dbhealth install-cron to print
the next scheduled run; the job itself works without it.
Usage
Set credentials via environment variables, not --token/--dsn flags.
CLI flags are visible to any local user via ps aux and persist forever in
~/.bash_history; the token and DSN password deserve better than that. Every
command below reads DBHEALTH_TOKEN / DBHEALTH_DSN / DBHEALTH_API_URL
from the environment if the corresponding flag is omitted:
export DBHEALTH_DSN="postgresql://readonly_user:password@localhost:5432/yourdb"
export DBHEALTH_TOKEN=dh_xxxx
# Audit exactly what would be sent — nothing is sent
dbhealth verify
# Collect metrics and send them to the API
dbhealth run
# Install a weekly cron job (default: every Monday 08:00, server timezone) --
# writes DBHEALTH_TOKEN/DBHEALTH_DSN as their own crontab environment lines,
# never as part of the executed command, so they never appear in argv either
dbhealth install-cron
Run dbhealth --help for the full command list.
Docker
The agent's container image is a one-shot job, not a daemon: it runs
dbhealth run, sends one report, and exits. docker compose up is not a
scheduler — it starts the container once and leaves it stopped — and a Docker
restart policy is not a timer either: restart: unless-stopped reads the
successful exit as a crash and re-runs the agent immediately, in a hot loop
against your database. The weekly cadence therefore comes from the host's
scheduler, running one container per occurrence:
0 8 * * 1 cd /srv/dbhealth && docker compose run --rm dbhealth-agent >> "$HOME/.local/state/dbhealth/dbhealth.log" 2>&1
Cron times are the host's local timezone, not UTC, unless that crontab sets
TZ/CRON_TZ.
No image is published yet. dbhealth docker-snippet fails closed while
that is true: it exits nonzero and tells you what is missing instead of
printing a compose service that names an image which would 404 on first run.
Until an image exists, use dbhealth install-cron — it schedules the same
weekly run without any container.
If you run your own image of this agent, set DBHEALTH_AGENT_IMAGE to its
full reference — registry host, a namespace you own, and a tag equal to this
agent's version — and dbhealth docker-snippet will print the compose service
for it. Anything mutable is rejected: no
latest, no untagged reference, and no tag belonging to a different agent
version than the one printing the snippet.
Secrets stay out of the image and out of the compose file. The generated
service carries no credential values at all — it references a gitignored
.env file that defines DBHEALTH_TOKEN and DBHEALTH_DSN, so those values
never enter docker-compose.yml (usually committed), the crontab line, or
argv (ps aux is readable by every local user).
License
Apache License 2.0 — see LICENSE. The agent is the part of DBHealth that runs
inside your network, so its source ships in the sdist for your security team to
read; the DBHealth service it reports to is a separate, hosted product.
Metadata
Release files for dbhealth-agent 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dbhealth_agent-0.1.2.tar.gz | 46.9 kB | With provenance | Details for dbhealth_agent-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dbhealth_agent-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for dbhealth_agent-0.1.2-py3-none-any.whl |
Total release size: 92.4 kB
Release files / dbhealth_agent-0.1.2.tar.gz
| Download URL | dbhealth_agent-0.1.2.tar.gz |
|---|---|
| Size | 46.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
82a3154905023e99f1066f1ef0a56da2a5d8436b8818f172ef07ee5c1ec887b5
|
|
BLAKE2b-256 checksum How to use checksums |
cfbb24162c06bcbc035a025d2d21c6278dfcd5f95260b350c2134acd49561088
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / dbhealth_agent-0.1.2-py3-none-any.whl
| Download URL | dbhealth_agent-0.1.2-py3-none-any.whl |
|---|---|
| Size | 45.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01f0cd6bead8b377d8bed5f9f3c11127863c920826b353b49c5d438e53c31100
|
|
BLAKE2b-256 checksum How to use checksums |
559efb634e7e5fbf86dc5dc302fa52bc5b3c4539dd56e1b088172662fafed396
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for dbhealth-agent 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for dbhealth_agent-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.