Monitoring PostgreSQL with pgwatch

pgwatch is a dedicated PostgreSQL monitoring stack with metric presets, selectable storage and Grafana dashboards. This page explains when it fits better than a general Prometheus setup and what to plan before deploying it.

On this page

Monitoring PostgreSQL with pgwatch: what it covers and when teams choose it

pgwatch is an open-source PostgreSQL monitoring tool that collects database-specific metrics and feeds them to dashboards, so a team running self-hosted PostgreSQL can get useful monitoring without building the collection layer itself. Its core job is to connect to one or more PostgreSQL instances, gather statistics on a schedule, store them in a time-series backend and present them in Grafana. The collection side is driven by metric definitions and presets, which decide which views and counters are sampled and how often. Before you adopt it, confirm the current list of supported presets, storage backends, Grafana dashboard bundles and PostgreSQL versions against the pgwatch project documentation, since these change between releases and this page does not pin a version.

The choice sits within this hub's wider set of options. A general Prometheus setup, usually built with postgres_exporter, gives you a standard scrape model and fits teams that already run Prometheus for everything else. The Zabbix templates suit organizations that centralize infrastructure alerting in Zabbix, and the OpenTelemetry Collector suits teams standardizing telemetry across applications and databases. A dedicated pgwatch stack suits a team that wants PostgreSQL dashboards and metric presets working quickly, is willing to run one extra component just for database observability, and does not want to design its own query set, role grants and dashboard layout. It is a weaker fit if your monitoring standard is already fixed on another backend, because a second metrics store then means a second set of retention, access and upgrade duties to plan for.

How pgwatch collects, stores and displays PostgreSQL metrics

The flow starts at each monitored PostgreSQL instance, where a dedicated monitoring role gives pgwatch read-only access. The pgwatch collector runs the metric presets chosen for each database and writes results to the storage backend you select. Grafana then reads that storage to draw dashboards. Check the trust boundary: the monitoring role should have no write privileges on the databases, and the storage and Grafana sit inside your controlled network, with access limited to the people who need it.

Read-only collection flows through pgwatch into storage and then Grafana.

Storage, deployment and preset options and when each fits

This table compares the storage backends, metric presets and deployment shapes you can choose for a pgwatch stack, and the trade-offs each carries for data volume, retention, load on monitored servers and operator familiarity. Read each row against your fleet size and retention requirement, then confirm the backend and preset names your installed pgwatch version supports before you commit.

OptionWhat it means for pgwatchTrade-offsWhen it fits
Light presetFewer metrics collected at longer intervals, focused on availability, connections, replication and transaction ID ageLowest data volume and query load on monitored servers, but gaps when diagnosing slow queries or lock waitsLarge fleets, first rollout, or teams that only need early warning and capacity trends
Fuller presetAdds per-database, table, index and statement-level metrics, usually at shorter intervalsRicher troubleshooting data, but higher storage growth and more queries run against each monitored serverTeams investigating performance regressions who accept higher storage and collection cost
Custom metric setYou define which metrics and intervals to collect per host or group of hostsMost control over cost and load, but every custom choice needs review and documentation as the fleet changesMixed workloads where production clusters need a narrow set and staging needs more depth
Time-series backend (confirm supported option)Stores metrics in a time-series database suited to dashboards and long retentionEfficient queries over time ranges, but adds a database to back up, size and upgradeLong retention and dashboard-heavy use, where the team already runs that database
PostgreSQL metrics store (confirm supported option)Stores metrics in a PostgreSQL database that the team already operatesFamiliar backup and tooling, but heavy write volume can compete with the workload you are monitoring if it shares a clusterSmaller fleets or teams that want one database technology to operate
Single collector for all targetsOne pgwatch instance polls every monitored serverSimplest to run, but one failure stops collection for the whole fleet and polling load concentrates on one hostSmall fleets in one network zone with a tolerable monitoring gap during restarts
One collector per cluster or zoneSeparate collectors poll the servers in each cluster, network zone or environmentMore instances to deploy, patch and configure, but failures stay contained and network paths stay shortRegulated or segmented networks, and clusters where collection must not cross a trust boundary
Central metrics store with local collectorsCollectors in each zone write to one shared store that Grafana readsCentral dashboards and retention, but the store and the network path between zones become criticalOrganizations with one reporting view across several sites or environments

pgwatch or a general Prometheus setup: choosing the monitoring approach

If your organization already runs Prometheus and Grafana for infrastructure and applications, the main argument is consolidation: one query language, one alerting path, one on-call route and one dashboard access model. A dedicated pgwatch stack adds a second collection pipeline that you must run, patch and secure. It earns its place only when the database team needs presets and dashboards that the shared platform does not give you. Otherwise, extending the existing platform with the build described on the sibling Prometheus page keeps the estate in one system.

  • Consolidation: Database alerts sit beside host and application alerts, so incidents correlate on one timeline.
  • Maintenance: A separate collector means another service to upgrade, its own credentials and its own retention to size.
  • Expertise: Your team already knows PromQL, recording rules and alert routing. Building database dashboards metric by metric takes time, but it stays within skills you have.
  • Grafana access: Grafana's authentication docs list SAML, team sync and SCIM as Enterprise or Cloud features, so confirm which identity features your current edition provides before adding another dashboard source.

Before deciding, check whether your existing exporter already runs under a least-privilege monitoring role and whether the database team will own dashboard changes.

How to set up pgwatch against a PostgreSQL cluster

This sequence takes a PostgreSQL cluster from no monitoring to a dedicated pgwatch stack that collects metrics from every node, feeds Grafana dashboards and routes alerts to the right people. Each step closes with a check so the team knows the layer below works before building on it.

  1. Create a least-privilege monitoring role

    The database administrator creates a dedicated login role on each PostgreSQL server that pgwatch will read from, and grants it only the view and statistics access the chosen metric presets need. Avoid superuser and avoid granting write access to application schemas. Confirm the grants by connecting as the new role and running the queries pgwatch will issue against statistics views, including on standbys if they are monitored. The step is done when the role can read every expected statistics view and is refused on a test write.

  2. Confirm network and TLS access from the collector

    The network or platform engineer opens a path from the pgwatch collector host to each PostgreSQL port, and adds a matching entry in pg_hba.conf that requires TLS and the password method your authentication standard allows. Check that the server accepts TLS connections from the collector address only. The step is done when a connection test from the collector succeeds over TLS for every target, and a connection from an unlisted address is rejected.

  3. Install and configure pgwatch with a preset

    The platform engineer installs pgwatch on the collector host, lists each cluster member as a monitored target and selects the metric preset that matches the goal, such as a lighter set for routine health or a broader set for performance work. Review the collection interval and the storage backend the team chose earlier, and record the configuration in version control. The step is done when the pgwatch process starts without configuration errors and each target appears as active in its status output.

  4. Verify metrics are written to storage

    Before building dashboards, the engineer queries the storage backend directly and confirms that rows or series exist for every target, metric group and host label in the preset. Compare the list against the target inventory so a missing standby or a silent collection error shows up now rather than during an incident. The step is done when each expected target has recent data points for each metric group, and any gap has a logged cause.

  5. Connect Grafana data sources and load dashboards

    The Grafana administrator adds the pgwatch storage backend as a data source and imports the dashboards that match the preset. Where the organization already runs Grafana provisioning, define the data source and dashboard files as YAML or JSON loaded at startup, so the setup can be reviewed and rebuilt from source control. Open each dashboard and check that panels render with the target labels filled in. The step is done when every panel returns data and the provisioned configuration reloads cleanly after a restart.

  6. Test alert rules and notification routing

    The on-call lead defines the alert rules for the metrics that matter to the team, such as target availability and storage growth, and points them at the notification channels used by the operations rota. Trigger a controlled condition on a non-production target, for example by pausing a collector connection for one target, and watch the alert fire and reach the correct recipients. The step is done when the test alert is received by the expected channel and the resolution notice also arrives.

  7. Confirm every target reports expected metrics

    The operations team runs a final check across the full cluster, comparing each primary and standby against the target inventory and the dashboards. Confirm that the monitoring role still has the grants it needs, that the collector restarts without losing targets, and that the retention settings meet the team's needs. Record the results in the runbook with the date and the versions in use. The step is done when every target is shown as reporting, the runbook entry is signed off, and the team has a known baseline to compare against after future changes.

Securing the monitoring stack and its database access

A monitoring stack reads deep into your database and holds information an attacker would value. The controls below cover the database role the collector uses, the transport to PostgreSQL, the Grafana instance that displays the data, and the stored metrics themselves. Each one needs an owner and a check before the stack goes live.

Dedicated monitoring role credentials

Create a separate login role for pgwatch rather than reusing an application or administrator account. Store its password in a secrets manager or a restricted file read only by the collector process, and set a rotation schedule your operators will actually follow. Confirm which authentication method your pg_hba.conf assigns to that role, and prefer SCRAM over MD5, since PostgreSQL 18 deprecated MD5 password authentication.

PostgreSQL auth methods

Least-privilege grants for the collector

The collector should hold only the statistics and catalog read access it needs, with no write access and no superuser rights. Review which databases it connects to and whether it needs access to every schema, because table and column names can reveal business structure. Ask your DBA to confirm the exact grants for your PostgreSQL version and to test the role's reach against a copy of production before go-live.

TLS between collector and database

Require encrypted connections from pgwatch to PostgreSQL, using hostssl entries in pg_hba.conf so that plaintext connections from the collector are refused. Decide whether the collector verifies the server certificate against a trusted CA, since encryption without verification does not stop a man-in-the-middle. Check the certificate expiry date and include renewal in your operations calendar, because an expired certificate usually breaks monitoring first.

Grafana authentication and cookies

Put Grafana behind your central identity provider, using the generic OAuth, LDAP or other methods your edition supports, and disable anonymous access. The Grafana hardening guide recommends secure and SameSite cookies, a Content Security Policy and domain verification against DNS rebinding. Review each setting in grafana.ini after installation, because defaults that suit a laptop trial do not suit a production monitoring console.

Grafana hardening guide

Protecting the metrics endpoint

The Grafana hardening guidance recommends requiring authentication for its metrics endpoint and hiding the version from unauthenticated users. Check that no unauthenticated path can reach internal metrics, and restrict network access to the Grafana port to your load balancer or administrator networks. Do the same review for pgwatch's own web and API surfaces if you expose them, and confirm this with a scan from outside the monitoring network.

Access to stored query text

Some collected statistics can include query text, and that text may contain literal values such as customer identifiers. Decide which metrics and fields your storage retains, restrict who can query the metrics database, and confirm how the chosen storage backend handles query text before it reaches dashboards. Treat the metrics store with the same access controls as the database it observes, and ask your security team to review the retention period.

Patch hygiene for collector and Grafana

Track security releases for pgwatch, Grafana and the PostgreSQL client libraries they use, and assign an owner for applying them. Grafana publishes patch releases at least monthly according to its upgrade guidance, so plan a recurring review rather than an occasional one. Test each upgrade against your dashboards and alert rules, and keep the previous version available for rollback.

Patch release cadence
Monthly
Grafana upgrade guide

Running pgwatch day to day: upgrades, retention and monitoring overhead

Keeping the monitoring stack current is ongoing work, and it starts with the Grafana release cycle. Grafana publishes major releases once a year, usually in April or May, minor releases about every other month and patch releases at least monthly. Each minor release is supported for 9 months, and the last minor release of a major version for 15 months, so a team that upgrades only once a year can end up on an unsupported version. Check the Grafana upgrade guidance each quarter against your installed version, and confirm pgwatch's release notes and its compatibility with your Grafana major version before applying either upgrade. Name one owner for the upgrade calendar, and test each upgrade against a copy of the dashboards before it reaches production.

Retention and overhead are the two load questions a monitoring stack hides until its disk fills or a primary slows down. The metrics store grows with the number of monitored databases, the metrics collected from each and the collection interval, so measure ingestion and disk growth for a representative period on a staging copy, then project the retention you need. Confirm in the pgwatch documentation which presets run by default, how often each one collects and what each query costs on your primary, and enable the broader set only after testing it on a replica or staging server. Record query latency and connection counts on the monitored servers before and after the change. Assign ownership early: a platform team usually runs the stack and its upgrades, while each database owner approves changes to thresholds and panels that affect their on-call rota.

If the Grafana instance itself must survive a server failure, the database becomes the main design decision. Grafana stores its configuration in SQLite by default, and its installation documentation says SQLite does not scale for production, so high availability needs MySQL 8.0 or later or PostgreSQL 12 or later. The Grafana high availability guide describes two or more active-active Grafana servers behind a load balancer sharing that database, with database-backed auth tokens so users can reach any node. Alerting needs additional configuration to avoid duplicate notifications, and Grafana Live has limitations in this mode, so test alert delivery and live panels before relying on them. Keep data sources and dashboards as provisioned files in version control, so a replacement node can be rebuilt from files rather than rebuilt by hand.

Limits to confirm before you commit to pgwatch

pgwatch is only as useful as its fit with your PostgreSQL versions, deployment model, licenses and recovery targets. The cards below list the points to settle with the pgwatch project, your counsel and your own environment before you build on it.

PostgreSQL major version coverage

Confirm which PostgreSQL majors the pgwatch release you plan to run supports, including every version in your fleet. PostgreSQL 14 through 18 are the currently supported majors under the versioning policy, and 14 reaches end of life in November 2026, so a fleet on 14 has a planned upgrade ahead of it. Check whether metric queries and presets were tested against each major you run, not only the newest one, and record the result for the upgrade plan.

Supported majors
14 to 18
Versioning policy

Managed and air-gapped installs

Ask whether the pgwatch release and its Grafana dependency can be installed from an internal mirror with no outbound internet access, and whether the monitored databases can be reached from the monitoring host through your network policy. Managed database services may restrict the monitoring role and the statistics views pgwatch reads, so confirm what the provider exposes before assuming parity with a self-hosted cluster.

License review for pgwatch and Grafana

Have counsel review the license of pgwatch itself and of every Grafana component you deploy. Grafana Labs changed Grafana, Loki and Tempo from Apache License 2.0 to AGPLv3 on April 20, 2021, while plugins and agent software kept other licenses, and Grafana Enterprise is offered as a commercial option. Your obligations depend on whether you modify or distribute the software or offer it to users over a network, so do not assume the choice is settled.

Grafana licensing

Replication and logical slot metrics

Confirm that the chosen preset collects write, flush and replay lag from pg_stat_replication, and that it reports replication slot state, including inactive slots and retained WAL for logical slots. Standbys and slots are where lag and disk growth appear first, so a preset that omits them leaves a gap in your alerting. Test the metric names against a primary with a standby and a logical slot before relying on the dashboards.

Alerting against your RPO targets

Check whether pgwatch alerting can express the thresholds your recovery point objective implies, such as replication lag measured in time or bytes and failed WAL archiving. Metrics that look healthy can still leave a recovery gap, so map each RPO target to a specific metric and alert, and confirm the notification route reaches an on-call owner. pgwatch collects data, but the thresholds and escalation are your decisions.

Grafana configuration database and HA

Grafana stores configuration in SQLite by default, but its installation docs say SQLite does not scale for production, so plan MySQL 8.0 or later or PostgreSQL 12 or later for a production dashboard tier. For high availability, confirm that alerting is configured to avoid duplicate notifications across nodes, since the docs note extra configuration is needed. Decide which Grafana database and node count you will run before you import dashboards.

Grafana HA docs

Questions teams ask before running pgwatch

What drives the cost of a pgwatch rollout?

The main drivers are the number of PostgreSQL clusters and databases in scope, how many monitoring roles must be created and approved, how much storage the metrics need over your retention period, and how much dashboard and alert design you want. Each cluster adds connection setup, access review and collector configuration, so cost grows with the estate rather than with the software, which is open source. Grafana hardening adds work when you require SSO, secure cookies, a Content Security Policy and authenticated metrics endpoints. Ask any quote to itemize these components separately so you can see which are one-time and which recur through maintenance and upgrades.

How long does a pgwatch rollout take?

Duration depends on how many clusters you onboard, how quickly access approvals arrive, and whether the storage and network paths already exist. A single test cluster with an agreed monitoring role and a standard set of dashboards is a much smaller job than a multi-cluster estate with custom alerts and Grafana single sign-on. Approval cycles for database access often take longer than the technical work, so start those early. Ask for a written timeline tied to the agreed scope, with milestones for access, storage sizing, dashboard review and handover.

What must our team provide before a pgwatch rollout starts?

You need to provide the following before work begins:

  • Network paths from the pgwatch host to each PostgreSQL server and to the Grafana users who will view dashboards.
  • Approval for a dedicated monitoring role with the minimum grants the collector needs, plus a named owner who signs off on those grants.
  • Storage for the metrics database, sized against your retention targets, and a backup location for it.
  • A Grafana database backend and identity provider details if you plan to run it for several teams.
  • A list of clusters, environments and owners who will receive alerts.

Confirm each item with your database and security teams early, since a missing approval is the most common blocker.

Can an internal team set up pgwatch without outside help?

Yes, a team with working PostgreSQL administration, Linux and container skills, and some Grafana experience can usually run a single-cluster pilot alone. The harder parts are designing a least-privilege monitoring role, choosing a storage approach that fits your retention needs, hardening Grafana, and keeping dashboards and alerts consistent across clusters. Check whether your team can own these tasks over time, including upgrades. Grafana's own documentation recommends a production database such as MySQL or PostgreSQL for Grafana configuration rather than SQLite, which is a decision worth making deliberately.

What breaks most often in a pgwatch deployment?

The most common failures are overly broad monitoring grants that fail a security review, collectors that lose connectivity after network changes, and storage that fills faster than planned because retention and metric presets were not sized together. Dashboards also drift when clusters are added without updating the configuration. Verify that the monitoring role can read statistics without access to application data, that collection continues after a server restart, and that storage alerts fire before the volume is full. Test these before you rely on the dashboards.

When is a Prometheus-based build a better choice than pgwatch?

A general Prometheus setup suits teams that already run Prometheus and Alertmanager, want PostgreSQL metrics next to application and Kubernetes metrics in one query language, and have engineers who will maintain exporters and rules. Choose pgwatch when you want a dedicated PostgreSQL monitoring stack with its own metric presets and dashboards, and do not want to assemble that from parts. Compare both against the same list of required metrics, the retention you need, the people who will maintain them, and the audit evidence your compliance team expects. For the exporter-based alternative, see the sibling page on monitoring PostgreSQL with Prometheus and Grafana.

Do we need a Grafana license to run pgwatch dashboards?

Grafana is licensed under AGPLv3 for its core software, and Grafana Enterprise is a separate commercial option. Most open-source deployments run the AGPL edition, but SAML, team sync and SCIM provisioning are available only in Grafana Enterprise and Grafana Cloud, according to Grafana's authentication documentation. If your identity requirements include those features, confirm the edition with your legal and security teams before the design is fixed. Check the current terms on Grafana's licensing page.

How DeployOpen scopes and delivers a pgwatch monitoring stack

DeployOpen approaches pgwatch as a dedicated monitoring stack inside your infrastructure, starting with a written scope that names the PostgreSQL clusters, metric presets, storage and dashboards involved. The work is planned, built, tested and documented so your team can run it after handover, with ongoing support available as a retainer.

How we scope

  • We inventory the PostgreSQL instances, versions and hosting models that pgwatch must reach before choosing a deployment layout.
  • We agree which metric presets, alert destinations and Grafana dashboards are in the written scope, and which are excluded.
  • We confirm the monitoring role permissions, network paths and storage backend your security team must approve before work starts.

How we build

  • We deploy pgwatch and its storage backend in your environment, with configuration kept in version-controlled files.
  • We test each monitored target with the dedicated monitoring role to confirm the expected metrics arrive without changing database behavior.
  • We provision Grafana dashboards as code where practical, so dashboard changes are reviewable and repeatable across environments.

How we hand over

  • We deliver runbooks covering setup, adding a new database target, changing a preset and rotating monitoring credentials.
  • We document the monitoring role grants, retention settings and the storage sizing assumptions behind them for your reviewers.
  • We walk your operations team through dashboards and alert routing, and record the open items agreed in the written scope.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades of pgwatch and Grafana, and continuous testing are available as retainers.
  • Confirm with us which pgwatch and Grafana versions and support windows apply at the time you plan the upgrade path.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.