@@ -26,27 +26,40 @@ Add module name to the `shared_preload_libraries` parameter in `postgresql.conf`
2626shared_preload_libraries = 'pg_query_state'
2727```
2828It is essential to restart the PostgreSQL instance. After that, execute the following query in psql:
29- ```
29+ ``` sql
3030CREATE EXTENSION pg_query_state;
3131```
3232Done!
3333
3434##Tests
35- Tests using parallel sessionsusing python 2.7 script:
36- ```
37- python tests/pg_qs_test_runner.py [OPTION]...
38- ```
35+ Test using parallel sessionswith Python 2.7/3+ compatible script:
36+ ``` shell
37+ python tests/pg_qs_test_runner.py [OPTION]...
38+ ```
3939* prerequisite packages* :
4040* ` psycopg2 ` version 2.6 or later
4141* ` PyYAML ` version 3.11 or later
42-
42+ * ` progressbar2 ` for stress test progress reporting
43+
4344* options* :
4445* * - -host* --- postgres server host, default value is* localhost*
4546* * - -port* --- postgres server port, default value is* 5432*
4647* * - -database* --- database name, default value is* postgres*
4748* * - -user* --- user name, default value is* postgres*
4849* * - -password* --- user's password, default value is empty
4950
51+ Or run all tests in` Docker ` using:
52+
53+ ``` shell
54+ export LEVEL=stress
55+ export PG_VERSION=12
56+
57+ docker-compose build
58+ docker-compose run tests
59+ ```
60+
61+ There are different test levels:` hardcore ` ,` nightmare ` (runs tests under` valgrind ` ) and` stress ` (runs tests under` TPC-DS ` load).
62+
5063##Function pg\_ query\_ state
5164``` plpgsql
5265pg_query_state(integer pid,
@@ -92,11 +105,11 @@ This parameters is set on called side before running any queries whose states ar
92105
93106##Examples
94107Set maximum number of parallel workers on` gather ` node equals` 2 ` :
95- ```
108+ ``` sql
96109postgres= # set max_parallel_workers_per_gather = 2;
97110```
98111Assume one backend with pid = 49265 performs a simple query:
99- ```
112+ ``` sql
100113postgres= # select pg_backend_pid();
101114 pg_backend_pid
102115-- --------------
@@ -105,7 +118,7 @@ postgres=# select pg_backend_pid();
105118postgres= # select count(*) from foo join bar on foo.c1=bar.c1;
106119```
107120Other backend can extract intermediate state of execution that query:
108- ```
121+ ``` sql
109122postgres= # \x
110123postgres= # select * from pg_query_state(49265);
111124- [ RECORD1 ]+ -- -----------------------------------------------------------------------------------------------------------------------
@@ -150,11 +163,11 @@ In example above working backend spawns two parallel workers with pids `49324` a
150163` Seq Scan ` node has statistics on passed loops (average number of rows delivered to` Nested Loop ` and number of passed loops are shown) and statistics on current loop. Other nodes has statistics only for current loop as this loop is first (` loop number ` = 1).
151164
152165Assume first backend executes some function:
153- ```
166+ ``` sql
154167postgres= # select n_join_foo_bar();
155168```
156169Other backend can get the follow output:
157- ```
170+ ``` sql
158171postgres= # select * from pg_query_state(49265);
159172- [ RECORD1 ]+ -- ----------------------------------------------------------------------------------------------------------------
160173pid |49265
@@ -180,7 +193,7 @@ leader_pid | (null)
180193First row corresponds to function call, second - to query which is in the body of that function.
181194
182195We can get result plans in different format (e.g.` json ` ):
183- ```
196+ ``` sql
184197postgres= # select * from pg_query_state(pid := 49265, format := 'json');
185198- [ RECORD1 ]+ -- ----------------------------------------------------------
186199pid |49265