Query Performance Monitoring Tool for PostgreSQL
 
 
 
 
 
 
Go to file
Ibrar Ahmed 51744990b7
Update README.md
2020-11-25 04:31:34 +05:00
docs Update USER_GUIDE.md 2020-11-25 04:30:04 +05:00
expected Issue - (#34): PostgreSQL Version 13 support added. 2020-06-23 17:24:21 +00:00
percona-packaging Update packaging license 2020-10-15 16:19:17 +03:00
sql Issue - (#33): Display all the custom configuration parameters used for pg_stat_monitor. 2020-05-25 11:58:22 +00:00
.gitignore Issue - (#1): Initial Commit for PostgreSQL's (pg_stat_statement). 2019-11-19 11:34:34 +00:00
LICENSE Update LICENSE 2020-10-15 18:11:56 +05:00
Makefile Issue(30): Code refactoring. 2020-09-14 22:26:19 +00:00
README.md Update README.md 2020-11-25 04:31:34 +05:00
guc.c Issue - (#21): Show objects(tables) involved in the query. 2020-11-24 20:10:49 +00:00
hash_query.c Issue - (#21): Show objects(tables) involved in the query. 2020-11-24 20:10:49 +00:00
pg_stat_monitor--1.0.sql PG-153: Log application name. 2020-11-24 21:03:32 +00:00
pg_stat_monitor.c PG-153: Log application name. 2020-11-24 21:03:32 +00:00
pg_stat_monitor.conf Issue - (#2): Extended pg_stat_statement to provide new features. 2019-11-20 10:30:57 +00:00
pg_stat_monitor.control Issue - (#2): Extended pg_stat_statement to provide new features. 2019-11-20 10:30:57 +00:00
pg_stat_monitor.h PG-153: Log application name. 2020-11-24 21:03:32 +00:00

README.md

What is pg_stat_monitor?

The pg_stat_monitor is the statistics collection tool based on PostgreSQL's contrib module pg_stat_statements. PostgreSQLs pg_stat_statements provides the basic statistics, which is sometimes not enough. The major shortcoming in pg_stat_statements is that it accumulates all the queries and their statistics and does not provide aggregated statistics nor histogram information. In this case, a user needs to calculate the aggregate which is quite expensive. pg_stat_monitor is developed on the basis of pg_stat_statements as its more advanced replacement. It provides all the features of pg_stat_statements plus its own feature set.

Documentation

  1. Supported PostgreSQL Versions
  2. Installation
  3. Setup
  4. User Guide
  5. Release Notes
  6. License
  7. Copyright Notice

Supported PostgreSQL Versions

The pg_stat_monitor should work on the latest version of PostgreSQL but is only tested with these PostgreSQL versions:

Distribution Version Supported
PostgreSQL Version < 11
PostgreSQL Version 11 ✔️
PostgreSQL Version 12 ✔️
PostgreSQL Version 13 ✔️
Percona Distribution Version < 11
Percona Distribution Version 11 ✔️
Percona Distribution Version 12 ✔️
Percona Distribution Version 13 ✔️

Installation

pg_stat_monitor is supplied as part of Percona Distribution for PostgreSQL. The rpm/deb packages are available from Percona repositories. Refer to Percona Documentation for installation instructions.

The source code of latest release of pg_stat_monitor can be downloaded from this GitHub page or it can be downloaded using the git:

git clone git://github.com/Percona/pg_stat_monitor.git

Compile and Install the extension

cd pg_stat_monitor
make USE_PGXS=1
make USE_PGXS=1 install

Setup

pg_stat_monitor cannot be installed in your running PostgreSQL instance. It should be set in the postgresql.conf file.

# - Shared Library Preloading -

shared_preload_libraries = 'pg_stat_monitor' # (change requires restart)
#local_preload_libraries = ''
#session_preload_libraries = ''

Or you can do from psql terminal using the alter system command.

pg_stat_monitor needs to be loaded at the start time. This requires adding the pg_stat_monitor extension for the shared_preload_libraries parameter and restart the PostgreSQL instance.

postgres=# ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_monitor';
ALTER SYSTEM

sudo systemctl restart postgresql-13

Create the extension using the CREATE EXTENSION command.

CREATE EXTENSION pg_stat_monitor;
CREATE EXTENSION
SELECT application_name, userid::regrole AS user_name, datname AS database_name, substr(query,0, 50) AS query, calls, client_ip 
           FROM pg_stat_monitor, pg_database 
           WHERE dbid = oid;
 
 application_name  | user_name | database_name |                       query                       | calls | client_ip 
-------------------+-----------+---------------+---------------------------------------------------+-------+-----------
 psql              | vagrant   | postgres      | SELECT elevel, sqlcode, message from pg_stat_moni |     1 | 127.0.0.1
 psql              | vagrant   | postgres      | SELECT c.relchecks, c.relkind, c.relhasindex, c.r |     1 | 127.0.0.1
 pg_cron scheduler | vagrant   | postgres      | update cron.job_run_details set status = $1, retu |     1 | 127.0.0.1
 pgbench           | vagrant   | postgres      | vacuum analyze pgbench_accounts                   |     1 | 10.0.2.15
 pgbench           | vagrant   | postgres      | alter table pgbench_branches add primary key (bid |     1 | 10.0.2.15
 psql              | vagrant   | postgres      | SELECT pg_catalog.quote_ident(c.relname) FROM pg_ |     1 | 127.0.0.1
 psql              | vagrant   | postgres      | SELECT decode_error_level(elevel), sqlcode, messa |     2 | 127.0.0.1
(37 rows)
SELECT decode_error_level(elevel) AS elevel, sqlcode, message 
           FROM pg_stat_monitor
           WHERE elevel != 0;
 
 elevel.            | sqlcode |                    message                     
--------------------+---------+------------------------------------------------
 ERROR              |     132 | permission denied for table pgbench_branches
 ERROR              |     130 | division by zero
 ERROR              |     132 | function decode_elevel(integer) does not exist
 ERROR              |     132 | must be owner of table pgbench_accounts
(4 rows)

Copyright (c) 2006 - 2020, Percona LLC.