Deploy PgHero

Postgres performance dashboard: slow queries, indexes, space, connections

Deploy PgHero

Deploy and Host PgHero on Railway

PgHero is an open-source performance dashboard for PostgreSQL, built by Andrew Kane and used in production at Instacart. It shows slow and frequent queries, unused and missing indexes, table and index sizes, connections, live queries, vacuum and maintenance stats, and lets you run EXPLAIN on a query, all from a browser.

About Hosting PgHero

This template deploys PgHero 4.1.0 as one stateless service, built from a public GitHub repo that pins the official ankane/pghero image by digest. It doesn't add a database: it reads the Postgres you already run. Deploy it into the project that holds your database and answer the one prompt, DATABASE_URL, with ${{Postgres.DATABASE_URL}}, so PgHero connects over Railway's private network. The dashboard is public behind basic auth with a generated password, and /health serves Railway's health check. Puma runs in single mode, so it needs little memory. Updates arrive as notices when the template repo changes.

Common Use Cases

  • Find slow, frequent or expensive queries in your app's Railway Postgres and check them with EXPLAIN
  • Spot unused, duplicate or missing indexes and see which tables and indexes take up space
  • Watch connections, long-running queries and vacuum health, and cancel a runaway query

Dependencies for PgHero Hosting

  • A PostgreSQL 14 or newer database (Railway Postgres or any other reachable Postgres)
  • The pg_stat_statements extension for the Queries tab (optional; Railway Postgres already preloads it)

Deployment Dependencies

Implementation Details

Point it at your database. Deploy the template into the project that holds your app's Postgres. The deploy page asks for one value, DATABASE_URL: enter ${{Postgres.DATABASE_URL}}, or ${{YOUR-DB-SERVICE.DATABASE_URL}} if your database service has another name. A Postgres outside Railway works too: postgres://USER:PASSWORD@HOST:5432/DBNAME. Use the private DATABASE_URL, not DATABASE_PUBLIC_URL, so traffic stays on the private network and costs no egress. If DATABASE_URL is empty, PgHero stays up and shows a page that says what to set.

Log in. Open the PgHero domain and sign in as admin with the generated PGHERO_PASSWORD from the service's Variables tab.

Query stats. On the Overview page, press "Enable query stats" (or run CREATE EXTENSION pg_stat_statements;). On a Postgres that doesn't preload it, add pg_stat_statements to shared_preload_libraries and restart it first.

Permissions. PgHero can cancel queries and run EXPLAIN with the user in DATABASE_URL. For a tighter setup, create a dedicated monitoring role as PgHero's permissions guide describes, and use its URL instead.

Optional variables: PGHERO_TZ, PGHERO_SLOW_QUERY_MS, PGHERO_LONG_RUNNING_QUERY_SEC, PGHERO_STATS_DATABASE_URL (for historical stats).

Why Deploy PgHero 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 PgHero 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

More templates in this category

View Template
Rootprint
Open-source logs and traces with full-text search on object-storage.

Rootprint
1
View Template
Pyroscope profiling
Protected continuous profiling with durable Pyroscope storage.

Anton Orel
1
View Template
SigOnly
Deploy SigNoz with a working demo app & config in one click

zoeyjones
21