GithubHelp home page GithubHelp logo

wolph / pg_query_analyser Goto Github PK

View Code? Open in Web Editor NEW
54.0 6.0 8.0 596 KB

A PostgreSQL query analyzer written in C++. Mimicks the output of PgFouine but _much_ faster.

License: GNU General Public License v3.0

C++ 67.10% Makefile 3.27% QMake 1.79% HTML 22.09% Roff 5.75%

pg_query_analyser's Introduction

pg_query_analyser -- PostgreSQL Slow Query Log parser

Overview

pg_query_analyser is a C++ clone of the PgFouine log analyser.

Processing logs with millions of lines only takes a few minutes with this parser while PgFouine chokes long before that.

Example output

The normal overview:

image

The overview with the examples expanded:

image

Requirements

Ubuntu (tested with 13.10):

apt-get install qt4-dev-tools

Ubuntu (tested with 16.04.2 LTS)

apt-get install qt4-dev-tools qt4-qmake libqt4-dev

Install

qmake
make
make test
sudo make install

Usage

Set Postgres to use this `log_line_prefix`:

log_line_prefix = '%t [%p]: [%l-1] host=%h,user=%u,db=%d,tx=%x,vtx=%v '

After that we can start parsing data.

From stdin:

cat /var/log/postgresql/postgresql.log | head -n 100000 | ./pg_query_analyser -i -

From file:

./pg_query_analyser --input-file=/var/log/postgresql/postgresql.log

For a full build+analyze on Ubuntu:

cd examples
fab -H <remote-ubuntu-postgres-server> build log_and_analyse

Help

# ./pg_query_analyser -h
Usage: ./pg_query_analyser [flags]
Options: 
  -h, --help=[false]
  -u, --users=[]
  -v, --verbose=[false]
  -i, --input-file=[/var/log/postgresql/postgresql-9.1-main.log]
  -d, --databases=[]
  -t, --query-types=[SELECT,UPDATE,INSERT,DELETE]
  -o, --output-file=[report.html]
  --top=[20]

pg_query_analyser's People

Contributors

danbst avatar ekohl avatar jamesmeneghello avatar mark0978 avatar wolph avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pg_query_analyser's Issues

can't compile on ubuntu: QBool: No such file or directory

Hi,
Can you give hint which packages are needed to compile?

make

g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_SQL_LIB -DQT_CORE_LIB -I../../../share/qt5/mkspecs/linux-g++-64 -I. -I../../../include/qt5 -I../../../include/qt5/QtSql -I../../../include/qt5/QtCore -I. -o main.o main.cpp
In file included from args.h:10:0,
from main.h:12,
from main.cpp:1:
arg.h:6:17: fatal error: QBool: No such file or directory
#include
^
compilation terminated.
make: *** [main.o] Error 1

Duration not processed

Hey,
I have strange problem with your tool, everything works fine except zeros in every query "duration time".
Im not sure, problem is in our log format (configured like in documentation) or with something else, but i really need this information. Can you help me with it?
Below one query from log.

P.S. We use patroni over our pg cluster, i hope its not a problem.

BR
Bart

Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: 2017-12-15 06:25:40 UTC [26476]: [4087633-1] host=127.0.0.1,user=postgres,db=postgres,tx=0,vtx=2/2043829 LOG:  statement: SELECT to_char(pg_postmaster_start_time(), 'YYYY-MM-DD HH24:MI:SS.MS TZ'),
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       pg_is_in_recovery(),
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       CASE WHEN pg_is_in_recovery()
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                            THEN 0
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                            ELSE pg_xlog_location_diff(pg_current_xlog_location(), '0/0')::bigint
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       END,
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       pg_xlog_location_diff(pg_last_xlog_receive_location(), '0/0')::bigint,
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       pg_xlog_location_diff(pg_last_xlog_replay_location(), '0/0')::bigint,
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       to_char(pg_last_xact_replay_timestamp(), 'YYYY-MM-DD HH24:MI:SS.MS TZ'),
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: #011                                       pg_is_in_recovery() AND pg_is_xlog_replay_paused()
Dec 15 06:25:40 ip-172-26-100-121 patroni[26448]: 2017-12-15 06:25:40 UTC [26476]: [4087634-1] host=127.0.0.1,user=postgres,db=postgres,tx=0,vtx=2/0 LOG:  duration: 0.251 ms

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.