Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.1.2 instead.
Reason given by maintainers: superseded by 0.1.2: query-literal masking could send SQL string values unmasked

dbhealth-agent

Client-side agent for DBHealth — collects PostgreSQL pg_stat_* health metrics, strips query literals, client IPs, application names, and row contents on a best-effort basis, and sends only the sanitized aggregates to the DBHealth API, which turns them into a periodic health report by email (weekly on paid plans, every four weeks on the free plan). Run dbhealth verify --json-output before your first real run to see, field by field, exactly what would leave your server for YOUR data — that JSON audit output, not this paragraph, is the authoritative source for what gets sent. (Plain dbhealth verify, without --json-output, prints a human-readable summary — counts and a truncated first-example query, not the full wire payload — plus an explicit list of the sanitizer's current best-effort masking gaps.)

Literal masking (best-effort — a conservative filter, not a SQL lexer; details on the verify screen): masking is a fail-CLOSED regex filter that errs toward over-masking. It replaces standard, escape (E'...'), and dollar-quoted strings ($$...$$ / $tag$...$tag$) with '?', replaces every numeric form (including 1e10, 1_000, 0xFF, 0b1010, 1.5e-3, .5) with ?, and strips SQL comments (-- ... and /* ... */). When the collector's 400-char transfer cap cuts a literal mid-value and leaves it unclosed, the masker cuts the preview and appends … rather than shipping the tail verbatim; if a literal earlier in the same query was already masked to '?', the cut is rolled back to that '?' so the text in between is dropped too — an unmatched quote means the filter may have mis-read that text, so it is treated as untrusted. The cost is deliberate over-masking of a valid query truncated inside a later literal (col='?'… rather than col='?', other=…). Complete valid queries keep their full masked shape. The masking behaviour proven by the executed test corpus covers valid SQL and the malformed shapes recorded there; it is still a regex filter, not a full PostgreSQL lexer, so it makes no absolute guarantee — run dbhealth verify --json-output on your own query patterns to confirm exactly what leaves your server.

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>.

python -m pip install "dbhealth-agent==0.1.1"

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.1") 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.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbhealth-agent 0.1.1
File Size Uploaded Provenance Actions
dbhealth_agent-0.1.1.tar.gz 52.2 kB With provenance Details for dbhealth_agent-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dbhealth-agent 0.1.1
File Interpreter ABI Platform Actions
dbhealth_agent-0.1.1-py3-none-any.whl Python 3 none any Details for dbhealth_agent-0.1.1-py3-none-any.whl

Total release size: 102.2 kB

Release files / dbhealth_agent-0.1.1.tar.gz

Download URL dbhealth_agent-0.1.1.tar.gz
Size 52.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8642e0c337726c12e1a3552fab704fde0c927af15b7fd12062f118692df76572
BLAKE2b-256 checksum
How to use checksums
70f1feaa990a831ecc6e85f8be62bb79dd194b24a4c561b0759f7fa97fb26b96
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 18, 2026.

Transparency log

Release files / dbhealth_agent-0.1.1-py3-none-any.whl

Download URL dbhealth_agent-0.1.1-py3-none-any.whl
Size 50.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1acfebc3d2d5c21609b83d28f83425d303b85ba35003ca172ab44cd7dec384b
BLAKE2b-256 checksum
How to use checksums
55f40420226caa0883c2c88461acd1d53317eb99b86f131807405b152bacbf04
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 18, 2026.

Transparency log

Security for dbhealth-agent 0.1.1

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.

Select from 2 files

Attestation for dbhealth_agent-0.1.1.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 18, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page