Skip to content

mohllal/postgres-stats-exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Postgres Stats Exporter

A Ruby script to export PostgreSQL table statistics and metrics to a YAML file.

What it does?

  • Connects to PostgreSQL using a connection URI from environment variables (supports .env files)
  • Lists all user tables
  • Exports per-table stats including:
    • Estimated row count
    • Read queries per second (QPS)
    • Write queries per second (QPS)
    • Various table-level counters
  • Outputs results in a YAML file

How to use?

  1. Clone this repository or copy the script files.

  2. Install dependencies:

    bundle install
  3. Create a .env file in the project root with your database connection string:

    DB_URI=postgres://user:password@host:port/dbname
    # Optionally override output file name
    # YAML_FILE=table_stats.yaml
  4. Run the script:

    ruby export_postgres_stats.rb

The output YAML file (default: table_stats.yaml) will contain stats for each table in the following format:

table_name:
  row_count: 1234
  read_qps: 0.0123
  write_qps: 0.0004
  seq_scan: 10
  ...

About

A Ruby script to export PostgreSQL table statistics and metrics to a YAML file.

Topics

Resources

Stars

Watchers

Forks

Languages