You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-5Lines changed: 16 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# PostreSQL-Monitor
2
2
This is a simple script that aims to be able to diagnose heavy SQL queries and show them in an easy to understand manner
3
3
4
-
##What does it do ?
4
+
# What does it do ?
5
5
This script was designed to be either used as a command line or for a slack / discord bot and can also write to a file<br/>
6
6
The script will display queries that :
7
7
- are the most used
@@ -11,7 +11,7 @@ The script will display queries that :
11
11
- returned the most rows on average
12
12
For each of these criteria, the 10 queries that had the biggest result are displayed
13
13
14
-
##How to use
14
+
# How to use
15
15
First, the database needs to be configured in order to allow the monitoring. This can be done at the following link : <ahref='https://gist.github.com/troyk/4462899'>https://gist.github.com/troyk/4462899</a>
16
16
17
17
Next, the script uses the following library to connect to the database and requires it to work : `psycopg2`
@@ -52,9 +52,20 @@ It will display just the queries for `mostUsed`, `longestTimeOnAverage` and `mos
52
52
53
53
**Note** : the queries that are used by this program are not displayed by default. See the configurations variables to display them
54
54
55
-
##Configuration
55
+
# Configuration
56
56
57
-
## Troubleshooting
57
+
The following class instance variables are used to configure the monitor to your needs :
58
+
`useIgnore` ( boolean ) is used to determine if queries possessing the substrings in the `ignore` variable should be ignored or not<br/>
59
+
`ignore` ( string array ) this array of strings / substrings is used to exclude queries from the displayed query list<br/>
60
+
By default, the following are ignored : "pg_stat_statements", "pg_catalog", "ALTER TABLE", "TRUNCATE TABLE" and "CREATE TABLE"<br/>
61
+
`writeOnConsole` ( boolean ) to allow ( True ) or forbid ( False ) the monitor to output on the console<br/>
62
+
`writeToFile` ( boolean ) to allow ( True ) or forbid ( False ) the monitor to output on a file<br/>
63
+
`filename` ( string ) is the file name that is used by the monitor ( will be overwritten )<br/>
64
+
`truncatedQuerySize` ( integer ) is used to shorted the query lengths. It is mostly used for long queries or small terminals
65
+
`indentBeforeQuery` and `indentBeforeCalls` ( integer ) are used to insert blank spaces and try to get all the data displayed as neatly as possible <br/>
66
+
`displayUsedQueries` ( boolean ) is used to display the queries that the program is using to gather the displayed data
67
+
68
+
# Troubleshooting
58
69
**Important** : the script will only show everything *from the moment the postgresql options are enabled****and****the server restarted*. Anything prior will not be shown as the database was not
59
70
saving the required data
60
71
@@ -66,7 +77,7 @@ Should this script not work, please make sure that :
66
77
Should it still not work, please set the console display ( `writeOnConsole` ) to True in order to see any other possible errors<br/>
67
78
Details on the working of this table here : https://www.postgresql.org/docs/9.6/static/pgstatstatements.html
68
79
69
-
##Example :
80
+
# Example :
70
81
The following output was obtained with the following instruction : `"dbname=test_database user=user password=my-password host=127.0.0.1 port=5432" all 10`<br />
71
82
Note : some queries can be very long, this is why the query id is displayed. This allows the output to not be cluttered with very long queries and allow you to display the important queries using the id directly
0 commit comments