Skip to content

Commit 8a06c89

Browse files
authored
Merge pull request #50 from nastena1606/DISTPG-166-Doc-add-pgstat-config-steps-13
DISTPG-166 Doc: Added setu steps for using pg_stat_monitor
2 parents 055869f + c5dd817 commit 8a06c89

7 files changed

+291
-37
lines changed

source/.res/important.postgresql.uninstall.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

source/.res/list.supported-platform.deb.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

source/.res/list.supported-platform.rpm.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
.. note::
3+
4+
You need to set up ``pg_stat_monitor`` in order to use it with |pdp|. Refer to :ref:`pg_stat-setup` for configuration guidelines.

source/index.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,19 @@ Installation and Upgrade
4545
major-upgrade
4646
minor-upgrade
4747

48+
Extensions
49+
******************************************
50+
51+
.. toctree::
52+
:maxdepth: 1
53+
54+
pg-stat-monitor
55+
4856
Uninstall |pdp|
4957
******************************************
5058

5159
.. toctree::
5260
:maxdepth: 2
53-
:glob:
5461

5562
uninstalling
5663

source/installing.rst

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,44 @@ Install the |percona-platform-postgresql-13| package using |apt-get-install|.
8383
8484
$ sudo apt-get install percona-postgresql-13
8585
86-
Note that this package will not install the components. To install these
87-
components use the appropriate packages:
86+
Note that this package will not install the components. Use the following commands to install components' packages:
87+
88+
Install ``pg_repack``:
89+
90+
.. code-block:: bash
91+
92+
$ sudo apt-get install percona-postgresql-13-repack
93+
94+
Install ``pgaudit``:
8895

8996
.. code-block:: bash
90-
91-
$ # To install pg_repack
92-
$ sudo apt-get install percona-postgresql-13-repack
93-
$ # To Install pgaudit
97+
9498
$ sudo apt-get install percona-postgresql-13-pgaudit
95-
$ # To install pgBackRest
99+
100+
Install ``pgBackRest``:
101+
102+
.. code-block:: bash
103+
96104
$ sudo apt-get install percona-pgbackrest
97-
$ # To install Patroni
105+
106+
Install ``Patroni``:
107+
108+
.. code-block:: bash
109+
98110
$ sudo apt-get install percona-patroni
99-
$ # To install pg_stat_monitor
111+
112+
Install ``pg_stat_monitor``:
113+
114+
.. code-block:: bash
115+
100116
$ sudo apt-get install percona-pg-stat-monitor13
101-
$ # To install PostgreSQL contrib extensions
117+
118+
.. include:: .res/note-pg_stat_config-required.txt
119+
120+
Install PostgreSQL contrib extensions:
121+
122+
.. code-block:: bash
123+
102124
$ sudo apt-get install percona-postgresql-contrib
103125
104126
.. admonition:: Starting the service
@@ -135,22 +157,44 @@ Install the |percona-platform-postgresql-13| package using |yum-install|.
135157
136158
$ sudo yum install percona-postgresql13-server
137159
138-
Note that this package will not install the components. To install these
139-
components use the appropriate packages:
160+
Note that this package will not install the components. Use the following commands to install components' packages:
161+
162+
Install ``pg_repack``:
140163

141164
.. code-block:: bash
142165
143-
$ # To install pg_repack
144166
$ sudo yum install percona-pg_repack13
145-
$ # To Install pgaudit
167+
168+
Install ``pgaudit``:
169+
170+
.. code-block:: bash
171+
146172
$ sudo yum install percona-pgaudit
147-
$ # To install pgBackRest
173+
174+
Install ``pgBackRest``:
175+
176+
.. code-block:: bash
177+
148178
$ sudo yum install percona-pgbackrest
149-
$ # To install Patroni
179+
180+
Install ``Patroni``:
181+
182+
.. code-block:: bash
183+
150184
$ sudo yum install percona-patroni
151-
$ # To install pg_stat_monitor
152-
$ yum install percona-pg-stat-monitor13
153-
$ # To install PostgreSQL contrib extensions
185+
186+
Install ``pg_stat_monitor``:
187+
188+
.. code-block:: bash
189+
190+
$ sudo yum install percona-pg-stat-monitor13
191+
192+
.. include:: .res/note-pg_stat_config-required.txt
193+
194+
Install PostgreSQL contrib extensions:
195+
196+
.. code-block:: bash
197+
154198
$ sudo yum install percona-postgresql13-contrib
155199
156200
.. admonition:: Starting the service

source/pg-stat-monitor.rst

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
.. _pg_stat-monitor:
2+
3+
pg_stat_monitor
4+
****************************
5+
6+
.. note::
7+
8+
This is a technical preview feature and it is subject to further changes.
9+
10+
Overview
11+
============================
12+
13+
``pg_stat_monitor`` is a |postgres| Query Performance Monitoring
14+
tool. It collects statistics data and writes it in a storage unit called *bucket*. The data is added and stored in a bucket for the defined period – the bucket lifetime.
15+
16+
You can specify the following:
17+
18+
- The number of buckets. Together they form a bucket chain.
19+
- Bucket size. This is the amount of shared memory allocated for buckets. Memory is divided equally among buckets.
20+
- Bucket lifetime.
21+
22+
When a bucket lifetime expires, ``pg_stat_monitor`` resets all statistics and writes the data in the next bucket in the chain. When the last bucket's lifetime expires, ``pg_stat_monitor`` returns to the first bucket.
23+
24+
.. important::
25+
26+
The contents of the bucket will be overwritten. In order not to lose the data, make sure to read the bucket before ``pg_stat_monitor`` starts writing new data to it.
27+
28+
.. _pg_stat-setup:
29+
30+
Setup
31+
===========================
32+
33+
After the :ref:`installation <pdp.installing>`, ``pg_stat_monitor`` requires additional setup in order to use it with |postgres|. The setup steps are the following:
34+
35+
1. Add ``pg_stat_monitor`` in the ``shared_preload_libraries`` configuration parameter.
36+
37+
The recommended way to modify |postgres| configuration file is using the `ALTER SYSTEM <https://www.postgresql.org/docs/13/sql-altersystem.html>`_ command. :ref:`Connect to psql <server-connect>` and use the following command:
38+
39+
.. code-block:: bash
40+
41+
$ ALTER SYSTEM SET shared_preload_libraries = 'pg_stat_monitor';
42+
43+
The parameter value is written to the :file:`postgresql.auto.conf` file which is read in addition with :file:`postgresql.conf` file.
44+
45+
#. Start or restart the PostgreSQL instance to enable ``pg_stat_monitor``. Use the following command for restart:
46+
47+
- On Debian and Ubuntu:
48+
49+
.. code-block:: bash
50+
51+
$ sudo systemctl restart postgresql.service
52+
53+
- On |rhel| and CentOS:
54+
55+
.. code-block:: bash
56+
57+
$ sudo systemctl restart postgresql-13
58+
59+
#. Create the extension. Connect to ``psql`` and use the following command:
60+
61+
.. code-block:: bash
62+
63+
$ CREATE EXTENSION pg_stat_monitor;
64+
65+
Usage
66+
===================
67+
68+
``pg_stat_monitor`` provides two views:
69+
70+
- ``pg_stat_monitor`` is the view where statistics data is presented.
71+
- ``pg_stat_monitor_settings`` shows available configuration options which you can change. To learn more, see :ref:`change-config`.
72+
73+
Use the following query to view what metrics ``pg_stat_monitor`` can collect:
74+
75+
.. code-block:: bash
76+
77+
$ \d pg_stat_monitor;
78+
79+
**Output**
80+
81+
.. code-block:: text
82+
83+
View "public.pg_stat_monitor"
84+
Column | Type | Collation | Nullable | Default
85+
---------------------+--------------------------+-----------+----------+---------
86+
bucket | integer | | |
87+
bucket_start_time | timestamp with time zone | | |
88+
userid | oid | | |
89+
dbid | oid | | |
90+
client_ip | inet | | |
91+
queryid | text | | |
92+
query | text | | |
93+
application_name | text | | |
94+
relations | text[] | | |
95+
cmd_type | text[] | | |
96+
elevel | integer | | |
97+
sqlcode | integer | | |
98+
message | text | | |
99+
plans | bigint | | |
100+
plan_total_time | double precision | | |
101+
plan_min_timei | double precision | | |
102+
plan_max_time | double precision | | |
103+
plan_mean_time | double precision | | |
104+
plan_stddev_time | double precision | | |
105+
calls | bigint | | |
106+
total_time | double precision | | |
107+
min_time | double precision | | |
108+
max_time | double precision | | |
109+
mean_time | double precision | | |
110+
stddev_time | double precision | | |
111+
rows | bigint | | |
112+
shared_blks_hit | bigint | | |
113+
shared_blks_read | bigint | | |
114+
shared_blks_dirtied | bigint | | |
115+
shared_blks_written | bigint | | |
116+
local_blks_hit | bigint | | |
117+
local_blks_read | bigint | | |
118+
local_blks_dirtied | bigint | | |
119+
local_blks_written | bigint | | |
120+
temp_blks_read | bigint | | |
121+
temp_blks_written | bigint | | |
122+
blk_read_time | double precision | | |
123+
blk_write_time | double precision | | |
124+
resp_calls | text[] | | |
125+
cpu_user_time | double precision | | |
126+
cpu_sys_time | double precision | | |
127+
128+
For example, to view the IP address of the client application that made the query, run the following command:
129+
130+
.. code-block:: bash
131+
132+
$ SELECT userid::regrole, datname, substr(query,0, 50) AS query, calls, client_ip
133+
FROM pg_stat_monitor, pg_database
134+
WHERE dbid = oid;
135+
136+
userid | datname | query | calls | client_ip
137+
----------+----------+---------------------------------------------------+-------+-----------
138+
postgres | postgres | select bucket, bucket_start_time, query,calls fro | 1 | 127.0.0.1
139+
postgres | postgres | SELECT c.relchecks, c.relkind, c.relhasindex, c.r | 1 | 127.0.0.1
140+
postgres | postgres | SELECT userid, total_time, min_time, max_time, | 1 | 127.0.0.1
141+
142+
Find more usage examples in `pg_stat_monitor User Guide <https://github.com/percona/pg_stat_monitor/blob/REL0_7_0_STABLE/docs/USER_GUIDE.md>`_.
143+
144+
.. _change-config:
145+
146+
Changing the configuration
147+
==================================
148+
149+
Run the following query to list available configuration parameters.
150+
151+
.. code-block:: sh
152+
153+
$ SELECT name,description FROM pg_stat_monitor_settings;
154+
155+
**Output**
156+
157+
.. code-block:: text
158+
159+
name | description
160+
-----------------------------------------------+-------------------------------------------------------------------
161+
pg_stat_monitor.pgsm_max | Sets the maximum number of statements tracked by pg_stat_monitor.
162+
pg_stat_monitor.pgsm_query_max_len | Sets the maximum length of query.
163+
pg_stat_monitor.pgsm_enable | Enable/Disable statistics collector.
164+
pg_stat_monitor.pgsm_track_utility | Selects whether utility commands are tracked.
165+
pg_stat_monitor.pgsm_normalized_query | Selects whether save query in normalized format.
166+
pg_stat_monitor.pgsm_max_buckets | Sets the maximum number of buckets.
167+
pg_stat_monitor.pgsm_bucket_time | Sets the time in seconds per bucket.
168+
pg_stat_monitor.pgsm_object_cache | Sets the maximum number of object cache
169+
pg_stat_monitor.pgsm_respose_time_lower_bound | Sets the time in millisecond.
170+
pg_stat_monitor.pgsm_respose_time_step | Sets the response time steps in millisecond.
171+
pg_stat_monitor.pgsm_query_shared_buffer | Sets the query shared_buffer size.
172+
173+
You can change a parameter by setting a new value in the configuration file. Some parameters require server restart to apply a new value. For others, configuration reload is enough. Refer to the `configuration section <https://github.com/percona/pg_stat_monitor/blob/REL0_7_0_STABLE/docs/USER_GUIDE.md#configuration>`_ of the ``pg_stat_monitor`` documentation for the parameters’ description, how you can change their values and if the server restart is required to apply them.
174+
175+
As an example, let's set the bucket lifetime from default 60 seconds to 100 seconds. Use the :command:`ALTER SYSTEM` command:
176+
177+
.. code-block:: bash
178+
179+
$ ALTER SYSTEM set pg_stat_monitor.pgsm_bucket_time = 100;
180+
181+
Restart the server to apply the change:
182+
183+
- On Debia and Ubuntu
184+
185+
.. code-block:: bash
186+
187+
$ sudo systemctl restart restart postgresql.service
188+
189+
- On |rhel| and CentOS:
190+
191+
.. code-block:: bash
192+
193+
$ sudo systemctl restart postgresql-13
194+
195+
Verify the updated parameter:
196+
197+
.. code-block:: bash
198+
199+
$ SELECT name, value
200+
FROM pg_stat_monitor_settings
201+
WHERE name = 'pg_stat_monitor.pgsm_bucket_time';
202+
203+
name | value
204+
----------------------------------+-------
205+
pg_stat_monitor.pgsm_bucket_time | 100
206+
207+
.. seealso::
208+
209+
``pg_stat_monitor`` Documentation
210+
https://github.com/percona/pg_stat_monitor/blob/REL0_7_0_STABLE/README.md
211+
212+
Percona Blog: pg_stat_monitor: A New Way Of Looking At PostgreSQL Metrics
213+
https://www.percona.com/blog/2021/01/19/pg_stat_monitor-a-new-way-of-looking-at-postgresql-metrics/
214+
215+
216+
.. include:: .res/replace.txt

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy