Skip to content
Web UI to view pg_stat_statements
Ruby HTML Dockerfile
Branch: master
Clone or download
Latest commit 6e33018 Oct 14, 2018


Mountable Sinatra app to render pg_stat_statements in user friendly way. Code Climate

Sponsored by Evil Martians


  • Sorting by any column from pg_stat_statements
  • Filtering by database or user
  • Highlighting important queries && hidding not important queries


  1. Prepare your PG setup: enable the pg_stat_statements extension and execute CREATE EXTENSION pg_stat_statements inside the database you want to inspect. Hint: there is an awesome article about pg_stat_statements in russian.
  2. Clone the repo
  3. Fill config.yml.example with your credentians and save it as config.yml
  4. Start the app: rake server (or run rake console to have command line)
  5. ???

Mount inside a rails app

Add this line to your application's Gemfile:

gem 'pg_web_stats', require: 'pg_web_stats_app'

Or if gem is not released yet

gem 'pg_web_stats', git: '', require: 'pg_web_stats_app'

And then execute:

$ bundle

Create file config/initializers/pg_web_stats.rb

# Configure database connection
config_hash = YAML.load_file(Rails.root.join('config', 'database.yml'))[Rails.env]

# Restrict access to pg_web_stats with Basic Authentication
# (or use any other authentication system).
PgWebStatsApp.use(Rack::Auth::Basic) do |user, password|
  password == "secret"

Add to routes.rb

mount PgWebStatsApp, at: '/pg_stats'

Restart rails app and visit http://localhost:3000/pg_stats

Made by [Kir Shatrov](, sponsored by [Evil Martians](

Thanks to Ivan Evtuhovich for advice about making this app.

You can’t perform that action at this time.