Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fbf45e3

Browse files
committed
Merge branch 'PGPROEE9_6_wait_sampling' into PGPROEE9_6
2 parents 2ea80c5 + 2d210bc commit fbf45e3

File tree

14 files changed

+1437
-2
lines changed

14 files changed

+1437
-2
lines changed

contrib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ SUBDIRS = \
4343
pgrowlocks \
4444
pgstattuple \
4545
pg_visibility \
46+
pg_wait_sampling \
4647
postgres_fdw \
4748
rum \
4849
seg \

contrib/pg_wait_sampling/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.deps
2+
*.o
3+
*.so

contrib/pg_wait_sampling/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# contrib/pg_wait_sampling/Makefile
2+
3+
MODULE_big = pg_wait_sampling
4+
OBJS = pg_wait_sampling.o collector.o
5+
6+
EXTENSION = pg_wait_sampling
7+
DATA = pg_wait_sampling--1.0.sql
8+
9+
REGRESS = load
10+
11+
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
12+
13+
ifdef USE_PGXS
14+
PG_CONFIG = pg_config
15+
PGXS := $(shell $(PG_CONFIG) --pgxs)
16+
include $(PGXS)
17+
else
18+
subdir = contrib/pg_wait_sampling
19+
top_builddir = ../..
20+
include $(top_builddir)/src/Makefile.global
21+
include $(top_srcdir)/contrib/contrib-global.mk
22+
endif

contrib/pg_wait_sampling/README.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
pg\_wait\_sampling – sampling based statistics of wait events
2+
=============================================================
3+
4+
Introduction
5+
------------
6+
7+
PostgreSQL 9.6+ provides an information about current wait event of particular
8+
process. However, in order to gather descriptive statistics of server
9+
behavior user have to sample current wait event multiple times.
10+
pg\_wait\_sampling is an extension for collecting sampling statistics of wait
11+
events.
12+
13+
The module must be loaded by adding pg\_wait\_sampling to
14+
shared\_preload\_libraries in postgresql.conf, because it requires additional
15+
shared memory and launches background worker. This means that a server restart
16+
is needed to add or remove the module.
17+
18+
When pg\_wait\_sampling is enabled, it collects two kinds of statistics.
19+
20+
* History of waits events. It's implemented as in-memory ring buffer where
21+
samples of each process wait events are written with given (configurable)
22+
period. Therefore, for each running process user can see some number of
23+
recent samples depending on history size (configurable). Assuming there is
24+
a client who periodically read this history and dump it somewhere, user
25+
can have continuous history.
26+
* Waits profile. It's implemented as in-memory hash table where count
27+
of samples are accumulated per each process and each wait event. This hash
28+
table can be reset by user request. Assuming there is a client who
29+
periodically dumps profile and resets it, user can have statistics of
30+
intensivity of wait events among time.
31+
32+
pg\_wait\_sampling launches special background worker for gathering the
33+
statistics above.
34+
35+
Authors
36+
-------
37+
38+
* Alexander Korotkov <a.korotkov@postgrespro.ru>, Postgres Professional,
39+
Moscow, Russia
40+
41+
Availability
42+
------------
43+
44+
pg\_wait\_sampling is realized as an extension and not available in default
45+
PostgreSQL installation. It is available from
46+
[github](https://github.com/postgrespro/pg_wait_sampling)
47+
under the same license as
48+
[PostgreSQL](http://www.postgresql.org/about/licence/)
49+
and supports PostgreSQL 9.6+.
50+
51+
Installation
52+
------------
53+
54+
pg\_wait\_sampling is PostgreSQL extension which requires PostgreSQL 9.6 or
55+
higher. Before build and install you should ensure following:
56+
57+
* PostgreSQL version is 9.6 or higher.
58+
* You have development package of PostgreSQL installed or you built
59+
PostgreSQL from source.
60+
* Your PATH variable is configured so that pg\_config command available, or
61+
set PG_CONFIG variable.
62+
63+
Typical installation procedure may look like this:
64+
65+
$ git clone https://github.com/postgrespro/pg_wait_sampling.git
66+
$ cd pg_wait_sampling
67+
$ make USE_PGXS=1
68+
$ sudo make USE_PGXS=1 install
69+
$ make USE_PGXS=1 installcheck
70+
$ psql DB -c "CREATE EXTENSION pg_wait_sampling;"
71+
72+
Usage
73+
-----
74+
75+
pg\_wait\_sampling interacts with user by set of views and functions.
76+
77+
pg\_wait\_sampling\_current view – information about current wait events for
78+
all processed including background workers.
79+
80+
| Column name | Column type | Description |
81+
| ----------- | ----------- | ----------------------- |
82+
| pid | int4 | Id of process |
83+
| event_type | text | Name of wait event type |
84+
| event | text | Name of wait event |
85+
86+
pg_wait_sampling_get_current(pid int4) returns the same table for single given
87+
process.
88+
89+
pg\_wait\_sampling\_history view – history of wait events obtained by sampling into
90+
in-memory ring buffer.
91+
92+
| Column name | Column type | Description |
93+
| ----------- | ----------- | ----------------------- |
94+
| pid | int4 | Id of process |
95+
| ts | timestamptz | Sample timestamp |
96+
| event_type | text | Name of wait event type |
97+
| event | text | Name of wait event |
98+
99+
pg\_wait\_sampling\_profile view – profile of wait events obtained by sampling into
100+
in-memory hash table.
101+
102+
| Column name | Column type | Description |
103+
| ----------- | ----------- | ----------------------- |
104+
| pid | int4 | Id of process |
105+
| event_type | text | Name of wait event type |
106+
| event | text | Name of wait event |
107+
| count | text | Count of samples |
108+
109+
pg_wait_sampling_reset_profile() function resets the profile.
110+
111+
The work of wait event statistics collector worker is controlled by following
112+
GUCs.
113+
114+
| Parameter name | Data type | Description | Default value |
115+
| ------------------------------- | --------- | ------------------------------------------- | ------------: |
116+
| pg_wait_sampling.history_size | int4 | Size of history in-memory ring buffer | 5000 |
117+
| pg_wait_sampling.history_period | int4 | Period for history sampling in milliseconds | 10 |
118+
| pg_wait_sampling.profile_period | int4 | Period for profile sampling in milliseconds | 10 |
119+
| pg_wait_sampling.profile_pid | bool | Whether profile should be per pid | true |
120+
121+
If pg\_wait\_sampling.profile\_pid is set to false, sampling profile wouldn't be
122+
collected in per-process manner. In this case the value of pid could would
123+
be always zero and corresponding row contain samples among all the processes.
124+
125+
These GUCs are allowed to be changed by superuser. Also, they are placed into
126+
shared memory. Thus, they could be changed from any backend and affects worker
127+
runtime.
128+
129+
130+
See
131+
[PostgreSQL documentation](http://www.postgresql.org/docs/devel/static/monitoring-stats.html#WAIT-EVENT-TABLE)
132+
for list of possible wait events.
133+
134+
Contribution
135+
------------
136+
137+
Please, notice, that pg\_wait\_sampling is still under development and while
138+
it's stable and tested, it may contains some bugs. Don't hesitate to raise
139+
[issues at github](https://github.com/postgrespro/pg_wait_sampling/issues) with
140+
your bug reports.
141+
142+
If you're lacking of some functionality in pg\_wait\_sampling and feeling power
143+
to implement it then you're welcome to make pull requests.
144+

0 commit comments

Comments
 (0)