Giter Club home page Giter Club logo

pghero_logs's Introduction

PgHero Logs

Slow query log parser for Postgres

Total    Avg  Count  Query
(min)   (ms)
   20   4381    283  SELECT DISTINCT "orders"."id" AS t0_r0, "orders"
    7   3574    120  SELECT "visits".* FROM "visits" WHERE ("visits".
    4  12621     20  SELECT DISTINCT "order_deliveries"."id" AS t0_r0

Install

gem install pghero_logs

It can take 10 minutes or more to compile the query parser ๐Ÿ•‘

Tell Postgres to log slow queries in postgresql.conf

log_min_duration_statement = 20 # ms

Analyze the logs

cat /usr/local/var/postgres/server.log | pghero_logs

Amazon RDS

First, download the logs. Create an IAM user with the policy below

{
  "Statement": [
    {
      "Sid": "Stmt1410669817271",
      "Action": [
        "rds:DescribeDBLogFiles",
        "rds:DownloadDBLogFilePortion"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}

And run

export AWS_ACCESS_KEY_ID=test123
export AWS_SECRET_ACCESS_KEY=secret123
export AWS_DB_INSTANCE_IDENTIFIER=production
pghero_logs download

Once logs are downloaded, run

cat logs/postgresql.log.* | pghero_logs

To analyze with PgBadger, install

brew install pgbadger

And run

pgbadger --prefix "%t:%r:%u@%d:[%p]:" --outfile pgbadger.html logs/* && open pgbadger.html

Thanks to RDS PgBadger for the prefix.

pghero_logs's People

Contributors

hokichaio avatar ankane avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.