Update README.md

pull/64/head
Ibrar Ahmed 2020-11-24 23:30:47 +05:00 committed by GitHub
parent 7e570378d1
commit 163e2e5e1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 95 additions and 41 deletions

122
README.md
View File

@ -15,9 +15,8 @@ The pg_stat_monitor is the statistics collection tool based on PostgreSQL's cont
The ``pg_stat_monitor`` should work on the latest version of PostgreSQL but is only tested with these PostgreSQL versions: The ``pg_stat_monitor`` should work on the latest version of PostgreSQL but is only tested with these PostgreSQL versions:
* PostgreSQL Version 11 * PostgreSQL Version 11, 12 and 13
* PostgreSQL Version 12 * Percona Distribution for PostgreSQL 11, 12 and 13
* Percona Distribution for PostgreSQL 11 and 12
# Documentation # Documentation
@ -394,16 +393,61 @@ postgres=# select bucket, bucket_start_time, query from pg_stat_monitor;
**`calls`**: Number of calls of that particular query. **`calls`**: Number of calls of that particular query.
Example 1: Shows the userid, dbid, unique queryid hash, query and total number of calls or that query.
``` ```
postgres=# select userid, dbid, queryid, query, calls from pg_stat_monitor; postgres=# select userid, dbid, queryid, substr(query,0, 50) as query, calls from pg_stat_monitor;
userid | dbid | queryid | query | calls userid | dbid | queryid | query | calls
--------+-------+------------------+--------------------------------------------------------------+------- --------+-------+------------------+---------------------------------------------------+-------
10 | 12696 | 56F12CE7CD01CF2C | select * from pg_stat_monitor_reset() | 1 10 | 12709 | 214646CE6F9B1A85 | BEGIN | 1577
10 | 12696 | 748D9EC1F4CECB36 | select userid, dbid, queryid, query from pg_stat_monitor | 1 10 | 12709 | 8867FEEB8A5388AC | vacuum pgbench_branches | 1
10 | 12696 | 85900141D214EC52 | select bucket, bucket_start_time, query from pg_stat_monitor | 2 10 | 12709 | F47D95C9DF863E43 | UPDATE pgbench_branches SET bbalance = bbalance + | 1577
10 | 12696 | F1AC132034D5B366 | SELECT * FROM foo | 1 10 | 12709 | 2FE0A6ABDC20623 | select substr(query,$1, $2) as query, cmd_type fr | 7
10 | 12709 | A83503D3E1F99139 | select userid, dbid, queryid, substr(query,$1, $ | 1
10 | 12709 | D4B1243AC3268B9B | select count(*) from pgbench_branches | 1
10 | 12709 | 2FE0A6ABDC20623 | select substr(query,$1, $2) as query, cmd_type fr | 1
10 | 12709 | 1D9BDBBCFB89F096 | UPDATE pgbench_accounts SET abalance = abalance + | 1577
10 | 12709 | 15343084284782B | update test SET a = $1 | 2
10 | 12709 | 939C2F56E1F6A174 | END | 1577
1 | 12709 | DAE6D269D27F2EC4 | SELECT FOR UPDATE test SET a = 1; | 1
10 | 12709 | 2B50C2406BFAC907 | INSERT INTO pgbench_history (tid, bid, aid, delta | 1577
10 | 12709 | F6DA9838660825CA | vacuum pgbench_tellers | 1
10 | 12709 | 3AFB8B2452721F9 | SELECT a from test for update | 1
10 | 12709 | A5CD0AF80D28363 | SELECT abalance FROM pgbench_accounts WHERE aid = | 1577
10 | 12709 | E445DD36B9189C53 | UPDATE pgbench_tellers SET tbalance = tbalance + | 1577
10 | 12709 | 4876BBA9A8FCFCF9 | truncate pgbench_history | 1
10 | 12709 | D3C2299FD9E7348C | select userid, dbid, queryid, query, calls from | 1
(18 rows)
``` ```
Example 2: Shows the different username for the queries.
```
postgres=# select userid::regrole, datname, substr(query,0, 50) as query, calls from pg_stat_monitor, pg_database WHERE dbid = oid;
userid | datname | query | calls
----------+----------+---------------------------------------------------+-------
vagrant | postgres | select userid::regrole, datname, substr(query,$1, | 1
vagrant | test_db | insert into bar values($1) | 1
vagrant | postgres | insert into bar values($1) | 1
vagrant | test_db | select * from bar | 1
postgres | postgres | insert into bar values($1) | 1
(5 rows)
```
Example 3: Shows the differen database involved in the queries.
```
postgres=# select userid::regrole, datname, substr(query,0, 50) as query, calls from pg_stat_monitor, pg_database WHERE dbid = oid;
userid | datname | query | calls
---------+----------+---------------------------------------------------+-------
vagrant | postgres | select userid::regrole, datname, substr(query,$1, | 0
vagrant | test_db | insert into bar values($1) | 1
vagrant | test_db | select * from bar | 1
(3 rows)
```
### Error Messages / Error Codes and Error Level ### Error Messages / Error Codes and Error Level
**`elevel`**, **`sqlcode`**,**`message`**,: error level / sql code and log/warning/error message **`elevel`**, **`sqlcode`**,**`message`**,: error level / sql code and log/warning/error message
@ -437,21 +481,27 @@ postgres=# select userid, total_time, min_time, max_time, mean_time, query from
10 | 11277.79 | 11277.79 | 11277.79 | 11277.79 | SELECT * FROM foo 10 | 11277.79 | 11277.79 | 11277.79 | 11277.79 | SELECT * FROM foo
``` ```
### Host / Client IP ### Client IP address
**`client_ip`**: The IP address of the client that originated the query. **`client_ip`**: The IP address of the client that originated the query.
``` ```
postgres=# select client_ip, query from pg_stat_monitor; postgres=# select userid::regrole, datname, substr(query,0, 50) as query, calls,client_ip from pg_stat_monitor, pg_database WHERE dbid = oid;
client_ip | query userid | datname | query | calls | client_ip
-----------+--------------------------------------------------------------------------------------- ---------+----------+---------------------------------------------------+-------+-----------
127.0.0.1 | select * from pg_stat_monitor_reset() vagrant | postgres | UPDATE pgbench_branches SET bbalance = bbalance + | 1599 | 10.0.2.15
127.0.0.1 | select userid, dbid, queryid, query from pg_stat_monitor vagrant | postgres | select userid::regrole, datname, substr(query,$1, | 5 | 10.0.2.15
127.0.0.1 | select bucket, bucket_start_time, query from pg_stat_monitor vagrant | postgres | UPDATE pgbench_accounts SET abalance = abalance + | 1599 | 10.0.2.15
127.0.0.1 | select userid, total_time, min_time, max_time, mean_time, query from pg_stat_monitor vagrant | postgres | select userid::regrole, datname, substr(query,$1, | 1 | 127.0.0.1
127.0.0.1 | select userid, dbid, queryid, query, calls from pg_stat_monitor vagrant | postgres | vacuum pgbench_tellers | 1 | 10.0.2.15
127.0.0.1 | SELECT * FROM foo vagrant | postgres | SELECT abalance FROM pgbench_accounts WHERE aid = | 1599 | 10.0.2.15
(6 rows) vagrant | postgres | END | 1599 | 10.0.2.15
vagrant | postgres | select count(*) from pgbench_branches | 1 | 10.0.2.15
vagrant | postgres | BEGIN | 1599 | 10.0.2.15
vagrant | postgres | INSERT INTO pgbench_history (tid, bid, aid, delta | 1599 | 10.0.2.15
vagrant | postgres | vacuum pgbench_branches | 1 | 10.0.2.15
vagrant | postgres | truncate pgbench_history | 1 | 10.0.2.15
vagrant | postgres | UPDATE pgbench_tellers SET tbalance = tbalance + | 1599 | 10.0.2.15
``` ```
### Call Timings Histogram ### Call Timings Histogram
@ -489,24 +539,28 @@ postgres=# select tables_names, query from pg_stat_monitor;
(8 rows) (8 rows)
``` ```
### Query command Type (SELECT, UPDATE, DELETE, UPDATE, TRUNCATE, NONE) ### Query command Type (SELECT, INSERT, UPDATE OR DELETE)
**`cmd_type`**: List the command type of the query. **`cmd_type`**: List the command type of the query.
``` ```
postgres=# select substr(query,0, 50) as query, cmd_type from pg_stat_monitor where elevel = 0; postgres=# select substr(query,0, 50) as query, cmd_type from pg_stat_monitor where elevel = 0;
query | cmd_type query | cmd_type
---------------------------------------------------+-------------------------------------------------- ---------------------------------------------------+-----------------
select substr(query,$1, $2) as query, cmd_type fr | {0," 0"," 0"," 1"," 0"," 0"," 0"," 0"," 0"," 1"} BEGIN | {INSERT}
vacuum pgbench_branches | {0," 0"," 0"," 1"," 0"," 0"," 0"," 0"," 0"," 0"} vacuum pgbench_branches | {}
vacuum analyze pgbench_branches | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} UPDATE pgbench_branches SET bbalance = bbalance + | {UPDATE,SELECT}
alter table pgbench_branches add primary key (bid | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} select substr(query,$1, $2) as query, cmd_type fr | {SELECT}
alter table pgbench_tellers add primary key (tid) | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} select count(*) from pgbench_branches | {SELECT}
insert into pgbench_tellers(tid,bid,tbalance) val | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} select substr(query,$1, $2) as query, cmd_type fr | {}
UPDATE pgbench_accounts SET abalance = abalance + | {0," 1"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} UPDATE pgbench_accounts SET abalance = abalance + | {UPDATE,SELECT}
insert into pgbench_tellers(tid,bid,tbalance) val | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} update test SET a = $1 | {UPDATE}
insert into pgbench_branches(bid,bbalance) values | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} END | {INSERT}
truncate table pgbench_accounts, pgbench_branches | {0," 0"," 0"," 1"," 0"," 0"," 0"," 0"," 0"," 0"} INSERT INTO pgbench_history (tid, bid, aid, delta | {INSERT}
vacuum analyze pgbench_accounts | {1," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"," 0"} vacuum pgbench_tellers | {}
create table pgbench_history(tid int,bid int,aid | {0," 0"," 0"," 1"," 0"," 0"," 0"," 0"," 0"," 0"} SELECT a from test for update | {UPDATE,SELECT}
SELECT abalance FROM pgbench_accounts WHERE aid = | {SELECT}
UPDATE pgbench_tellers SET tbalance = tbalance + | {UPDATE,SELECT}
truncate pgbench_history | {}
(15 rows)
``` ```