Issue - (#3): README file update.

pull/12/head
jobinau 2019-12-05 14:20:55 +05:30
parent 9f1cf3629d
commit 00b0cb8a7a
1 changed files with 114 additions and 109 deletions

223
README.md
View File

@ -1,10 +1,10 @@
### pg_stat_monitor - Statistics collector for [PostgreSQL][1]. ### pg_stat_monitor - Statistics collector for [PostgreSQL][1].
The pg_stat_monitor is statistics collector tool based on PostgreSQL's pg_stat_statement. PostgreSQLs “pg_stat_statment” provides the basic statistics which is sometimes not enough. The major flaw in this that it accumulates all the queries and its statistics and does not provide aggregate statistics, in that case, the user needs to calculate the aggregate which is quite expensive. The pg_stat_monitor is statistics collector tool based on PostgreSQL's contrib module "pg_stat_statements". PostgreSQLs “pg_stat_statments” provides the basic statistics which is sometimes not enough. The major shortcoming in pg_stat_statment is that it accumulates all the queries and its statistics and does not provide aggregate statistics or histogram information. in that case, the user needs to calculate the aggregate which is quite expensive.
pg_stat_monitor is developed on the basis of pg_stat_statments as more advanced replacement for pg_stat_statment. It provides all the features of pg_stat_statment plus its own feature set.
Pg_stat_monitor is build on top of pg_stat_statment, so it provides all the pg_stat_statment plus its own feature set.
#### Supported PostgreSQL Versions. #### Supported PostgreSQL Versions.
Pg_stat_monitor should work on the latest version of PostgreSQL but only tested with these versions of PostgreSQL. Pg_stat_monitor should work on the latest version of PostgreSQL but only tested with these versions of PostgreSQL.
@ -19,24 +19,29 @@ There are two ways to install pg_stat_monitor. The first is by downloading the p
The latest release of pg_stat_monitor can be downloaded from this GitHub page: The latest release of pg_stat_monitor can be downloaded from this GitHub page:
https://github.com/Percona-Lab/pg_stat_monitor/releases https://github.com/Percona-Lab/pg_stat_monitor/releases
or it can be downloaded using the git: or it can be downloaded using the git:
git clone git://github.com/Percona-Lab/pg_stat_monitor.git git clone git://github.com/Percona-Lab/pg_stat_monitor.git
After downloading the code, set the path for the [PostgreSQL][1] binary: After downloading the code, set the path for the [PostgreSQL][1] binary:
###### Compile ###### Compile and Install extension
cd pg_stat_monitor cd pg_stat_monitor
make USE_PGXS=1 make USE_PGXS=1
make USE_PGXS=1 install make USE_PGXS=1 install
###### Enable Extension ###### Enable and Create Extension
This extension needs to be loaded at the start time. Which requires adding the pg_stat_monitor extension shared_preload_libraries and restart the PostgreSQL Instance.
postgres=# alter system set shared_preload_libraries=pg_stat_monitor; postgres=# alter system set shared_preload_libraries=pg_stat_monitor;
ALTER SYSTEM ALTER SYSTEM
sudo systemctl restart postgresql-11 sudo systemctl restart postgresql-11
Create the extension in the desired database.
postgres=# create extension pg_stat_monitor; postgres=# create extension pg_stat_monitor;
CREATE EXTENSION CREATE EXTENSION
@ -44,53 +49,53 @@ After downloading the code, set the path for the [PostgreSQL][1] binary:
#### Usage #### Usage
There are four views, and complete statistics can be accessed using these views. There are four views, and complete statistics can be accessed using these views.
Pg_stat_monitor * pg_stat_monitor
Pg_stat_agg_database * pg_stat_agg_database
Pg_stat_agg_user * pg_stat_agg_user
pg_stat_agg_hots * pg_stat_agg_host
##### pg_stat_monitor ##### pg_stat_monitor
This is the main view which stores per query-based statistics, similar to pg_stat_statment with some additional columns. This is the main view which stores per query-based statistics, similar to pg_stat_statment with some additional columns.
\d pg_stat_monitor; \d pg_stat_monitor;
View "public.pg_stat_monitor" View "public.pg_stat_monitor"
Column | Type | Collation | Nullable | Default Column | Type | Collation | Nullable | Default
---------------------+------------------+-----------+----------+--------- ---------------------+------------------+-----------+----------+---------
userid | oid | | | userid | oid | | |
dbid | oid | | | dbid | oid | | |
queryid | bigint | | | queryid | bigint | | |
query | text | | | query | text | | |
calls | bigint | | | calls | bigint | | |
total_time | double precision | | | total_time | double precision | | |
min_time | double precision | | | min_time | double precision | | |
max_time | double precision | | | max_time | double precision | | |
mean_time | double precision | | | mean_time | double precision | | |
stddev_time | double precision | | | stddev_time | double precision | | |
rows | bigint | | | rows | bigint | | |
shared_blks_hit | bigint | | | shared_blks_hit | bigint | | |
shared_blks_read | bigint | | | shared_blks_read | bigint | | |
shared_blks_dirtied | bigint | | | shared_blks_dirtied | bigint | | |
shared_blks_written | bigint | | | shared_blks_written | bigint | | |
local_blks_hit | bigint | | | local_blks_hit | bigint | | |
local_blks_read | bigint | | | local_blks_read | bigint | | |
local_blks_dirtied | bigint | | | local_blks_dirtied | bigint | | |
local_blks_written | bigint | | | local_blks_written | bigint | | |
temp_blks_read | bigint | | | temp_blks_read | bigint | | |
temp_blks_written | bigint | | | temp_blks_written | bigint | | |
blk_read_time | double precision | | | blk_read_time | double precision | | |
blk_write_time | double precision | | | blk_write_time | double precision | | |
host | integer | | | host | integer | | |
hist_calls | text | | | hist_calls | text | | |
hist_min_time | text | | | hist_min_time | text | | |
hist_max_time | text | | | hist_max_time | text | | |
hist_mean_time | text | | | hist_mean_time | text | | |
slow_query | text | | | slow_query | text | | |
cpu_user_time | double precision | | | cpu_user_time | double precision | | |
cpu_sys_time | double precision | | | cpu_sys_time | double precision | | |
These are new column added to have more detail about the query. These are new column added to have more detail about the query.
host: Client IP or Hostname host: Client IP or Hostname
hist_calls: Hourly based 24 hours calls of query histogram hist_calls: Hourly based 24 hours calls of query histogram
hist_min_time: Hourly based 24 hours min time of query histogram hist_min_time: Hourly based 24 hours min time of query histogram
@ -101,79 +106,79 @@ These are new column added to have more detail about the query.
cpu_sys_time: CPU System time for that query. cpu_sys_time: CPU System time for that query.
regression=# \d pg_stat_agg_database regression=# \d pg_stat_agg_database
View "public.pg_stat_agg_database" View "public.pg_stat_agg_database"
Column | Type | Collation | Nullable | Default Column | Type | Collation | Nullable | Default
----------------+--------------------------+-----------+----------+--------- ----------------+--------------------------+-----------+----------+---------
queryid | bigint | | | queryid | bigint | | |
dbid | bigint | | | dbid | bigint | | |
userid | oid | | | userid | oid | | |
host | inet | | | host | inet | | |
total_calls | integer | | | total_calls | integer | | |
min_time | double precision | | | min_time | double precision | | |
max_time | double precision | | | max_time | double precision | | |
mean_time | double precision | | | mean_time | double precision | | |
hist_calls | text[] | | | hist_calls | text[] | | |
hist_min_time | text[] | | | hist_min_time | text[] | | |
hist_max_time | text[] | | | hist_max_time | text[] | | |
hist_mean_time | text[] | | | hist_mean_time | text[] | | |
first_log_time | timestamp with time zone | | | first_log_time | timestamp with time zone | | |
last_log_time | timestamp with time zone | | | last_log_time | timestamp with time zone | | |
cpu_user_time | double precision | | | cpu_user_time | double precision | | |
cpu_sys_time | double precision | | | cpu_sys_time | double precision | | |
query | text | | | query | text | | |
slow_query | text | | | slow_query | text | | |
# \d pg_stat_agg_user # \d pg_stat_agg_user
View "public.pg_stat_agg_user" View "public.pg_stat_agg_user"
Column | Type | Collation | Nullable | Default Column | Type | Collation | Nullable | Default
----------------+--------------------------+-----------+----------+--------- ----------------+--------------------------+-----------+----------+---------
queryid | bigint | | | queryid | bigint | | |
dbid | bigint | | | dbid | bigint | | |
userid | oid | | | userid | oid | | |
host | inet | | | host | inet | | |
total_calls | integer | | | total_calls | integer | | |
min_time | double precision | | | min_time | double precision | | |
max_time | double precision | | | max_time | double precision | | |
mean_time | double precision | | | mean_time | double precision | | |
hist_calls | text[] | | | hist_calls | text[] | | |
hist_min_time | text[] | | | hist_min_time | text[] | | |
hist_max_time | text[] | | | hist_max_time | text[] | | |
hist_mean_time | text[] | | | hist_mean_time | text[] | | |
first_log_time | timestamp with time zone | | | first_log_time | timestamp with time zone | | |
last_log_time | timestamp with time zone | | | last_log_time | timestamp with time zone | | |
cpu_user_time | double precision | | | cpu_user_time | double precision | | |
cpu_sys_time | double precision | | | cpu_sys_time | double precision | | |
query | text | | | query | text | | |
slow_query | text | | | slow_query | text | | |
# \d pg_stat_agg_host # \d pg_stat_agg_host
View "public.pg_stat_agg_host" View "public.pg_stat_agg_host"
Column | Type | Collation | Nullable | Default Column | Type | Collation | Nullable | Default
----------------+--------------------------+-----------+----------+--------- ----------------+--------------------------+-----------+----------+---------
queryid | bigint | | | queryid | bigint | | |
dbid | bigint | | | dbid | bigint | | |
userid | oid | | | userid | oid | | |
host | inet | | | host | inet | | |
total_calls | integer | | | total_calls | integer | | |
min_time | double precision | | | min_time | double precision | | |
max_time | double precision | | | max_time | double precision | | |
mean_time | double precision | | | mean_time | double precision | | |
hist_calls | text[] | | | hist_calls | text[] | | |
hist_min_time | text[] | | | hist_min_time | text[] | | |
hist_max_time | text[] | | | hist_max_time | text[] | | |
hist_mean_time | text[] | | | hist_mean_time | text[] | | |
first_log_time | timestamp with time zone | | | first_log_time | timestamp with time zone | | |
last_log_time | timestamp with time zone | | | last_log_time | timestamp with time zone | | |
cpu_user_time | double precision | | | cpu_user_time | double precision | | |
cpu_sys_time | double precision | | | cpu_sys_time | double precision | | |
query | text | | | query | text | | |
slow_query | text | | | slow_query | text | | |
Examples Examples
1 - In this query we are getting the exact value of f1 which is '05:06:07-07' in the case of slow queries. 1 - In this query we are getting the exact value of f1 which is '05:06:07-07' in the case of slow queries.
# select userid, queryid, query, slow_query, max_time, total_calls from pg_stat_agg_user; # select userid, queryid, query, slow_query, max_time, total_calls from pg_stat_agg_user;
-[ RECORD 1 ]---------------------------------------------------------------------------------------- -[ RECORD 1 ]----------------------------------------------------------------------------------------
userid | 10 userid | 10
queryid | -203926152419851453 queryid | -203926152419851453
@ -184,17 +189,17 @@ Examples
2 - Collect all statistics based on the user. 2 - Collect all statistics based on the user.
# select usename, query, max_time, total_calls from pg_stat_agg_user au, pg_user u where au.userid = u.usesysid; # select usename, query, max_time, total_calls from pg_stat_agg_user au, pg_user u where au.userid = u.usesysid;
usename | query | max_time | total_calls usename | query | max_time | total_calls
---------+---------------------------------------------------------+----------+------------- ---------+---------------------------------------------------------+----------+-------------
vagrant | select userid, query, total_calls from pg_stat_agg_user | 0.268842 | 7 vagrant | select userid, query, total_calls from pg_stat_agg_user | 0.268842 | 7
foo | select userid, query, total_calls from pg_stat_agg_user | 0.208551 | 1 foo | select userid, query, total_calls from pg_stat_agg_user | 0.208551 | 1
vagrant | select * from pg_stat_monitor_reset() | 0.0941 | 1 vagrant | select * from pg_stat_monitor_reset() | 0.0941 | 1
(3 rows) (3 rows)
#### Limitation #### Limitation
There are some limitations and Todos. There are some limitations and Todos.
#### Licence #### Licence
Copyright (c) 2006 - 2019, Percona LLC. Copyright (c) 2006 - 2019, Percona LLC.