
Deploy pgwatch
Self-hosted PostgreSQL monitoring with preloaded Grafana dashboards.
grafana
Just deployed
/var/lib/grafana
Just deployed
postgres-metrics
Just deployed
/var/lib/postgresql/data
postgres-config
Just deployed
/var/lib/postgresql/data
Deploy and Host pgwatch on Railway
pgwatch is an open-source PostgreSQL monitoring tool. It polls the statistics collectors of any Postgres instance you point it at, stores the measurements as time series, and visualizes them in Grafana. No agent is installed on the monitored database, only a connection string is needed.
About Hosting pgwatch
This template runs the full pgwatch stack from public Docker images, with no source repository to fork or maintain. Four services deploy together: a config database holding the list of monitored instances, a metrics database holding the gathered time series, the pgwatch gatherer with its web UI, and Grafana. pgwatch creates its own schema in both databases on first connect, so nothing needs bootstrapping. Grafana fetches the 22 official pgwatch dashboards from the pinned upstream release on first boot, caches them on its volume, and provisions both the dashboards and the metrics datasource automatically, so the graphs are populated the moment you add a monitored database.
Common Use Cases
- Finding slow queries and performance bottlenecks across production Postgres instances
- Tracking connection counts, locks, cache hit ratios, and WAL activity over time
- Watching table and index bloat, and reviewing pgwatch's built-in configuration recommendations
Dependencies for pgwatch Hosting
- A PostgreSQL instance to monitor, reachable from Railway, plus a connection string for it. Everything else is provisioned by the template.
- A monitoring role on that instance.
pg_monitormembership (or superuser) gives full coverage; a plain login role still yields the basic metrics. - Optional:
pg_stat_statementson the monitored instance for the query-performance dashboards.
Deployment Dependencies
Implementation Details
Getting started after deploy. Open the pgwatch service's domain and log in with admin and the generated PW_WEBPASSWORD from that service's variables. Add your database under Sources, then open Grafana (its own domain, user admin, generated GF_SECURITY_ADMIN_PASSWORD) and pick a dashboard from the pgwatch folder. The first measurements land within about two minutes, since pgwatch rescans its source list every 120 seconds.
No custom images. Upstream ships the Grafana dashboards as files in the source tree rather than in any image, which normally forces a custom Dockerfile and therefore a repository. Instead, the Grafana service runs the stock grafana/grafana-oss image with a start command that downloads the pinned release tarball, writes the dashboard and datasource provisioning YAML, and then hands off to Grafana's own entrypoint:
curl -fsSL "https://codeload.github.com/cybertec-postgresql/pgwatch/tar.gz/refs/tags/v$PGWATCH_VERSION" \
| tar -xz -C "$DASHDIR" --strip-components=4 "pgwatch-$PGWATCH_VERSION/grafana/postgres/v12"
...
exec /run.sh
The download is cached on the Grafana volume and re-runs only when PGWATCH_VERSION changes, so restarts do not depend on GitHub being reachable. The datasource is provisioned with uid pgwatch-metrics, which is what all 22 dashboards bind to; renaming it silently blanks every panel.
Plugins. The dashboards use one external panel plugin, marcusolsson-treemap-panel, installed via GF_PLUGINS_PREINSTALL. GF_INSTALL_PLUGINS is deprecated in current Grafana and does nothing unless GF_INSTALL_PLUGINS_FORCE=true is also set.
Ports and permissions. Railway probes the healthcheck on PORT, while pgwatch binds PW_WEBADDR; both are pinned to 8080 so the probe and the process agree. Grafana runs with RAILWAY_RUN_UID=0 because Railway mounts volumes root-owned while the image would otherwise run as uid 472.
Credentials. Both admin passwords are generated per deployment rather than shipped as admin/admin. Leaving PW_WEBUSER and PW_WEBPASSWORD both empty disables pgwatch's authentication entirely, so keep them set.
Why Deploy pgwatch on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying pgwatch on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
grafana
grafana/grafana-oss:13.0.2postgres-metrics
ghcr.io/railwayapp-templates/postgres-ssl:18postgres-config
ghcr.io/railwayapp-templates/postgres-ssl:18