@@ -27,26 +27,41 @@ Add module name to the `shared_preload_libraries` parameter in `postgresql.conf`
2727shared_preload_libraries = 'pg_query_state'
2828```
2929It is essential to restart the PostgreSQL instance. After that, execute the following query in psql:
30- ```
30+ ``` sql
3131CREATE EXTENSION pg_query_state;
3232```
3333Done!
3434
3535##Tests
36- Tests using parallel sessionsusing python 2.7 script:
37- ```
38- python tests/pg_qs_test_runner.py [OPTION]...
39- ```
36+ Test using parallel sessionswith Python 3+ compatible script:
37+ ``` shell
38+ python tests/pg_qs_test_runner.py [OPTION]...
39+ ```
4040* prerequisite packages* :
4141* ` psycopg2 ` version 2.6 or later
4242* ` PyYAML ` version 3.11 or later
43-
43+ * ` progressbar2 ` for stress test progress reporting
44+
4445* options* :
4546* * - -host* --- postgres server host, default value is* localhost*
4647* * - -port* --- postgres server port, default value is* 5432*
4748* * - -database* --- database name, default value is* postgres*
4849* * - -user* --- user name, default value is* postgres*
4950* * - -password* --- user's password, default value is empty
51+ * * - -tpc-ds* --- runs only stress tests on TPC-DS benchmark
52+
53+ Or run all tests in` Docker ` using:
54+
55+ ``` shell
56+ export LEVEL=hardcore
57+ export USE_TPCDS=1
58+ export PG_VERSION=12
59+
60+ docker-compose build
61+ docker-compose run tests
62+ ```
63+
64+ There are different test levels:` hardcore ` ,` nightmare ` (runs tests under` valgrind ` ) and` stress ` (runs tests under` TPC-DS ` load).
5065
5166##Function pg\_ query\_ state
5267``` plpgsql
@@ -93,11 +108,11 @@ This parameters is set on called side before running any queries whose states ar
93108
94109##Examples
95110Set maximum number of parallel workers on` gather ` node equals` 2 ` :
96- ```
111+ ``` sql
97112postgres= # set max_parallel_workers_per_gather = 2;
98113```
99114Assume one backend with pid = 49265 performs a simple query:
100- ```
115+ ``` sql
101116postgres= # select pg_backend_pid();
102117 pg_backend_pid
103118-- --------------
@@ -106,7 +121,7 @@ postgres=# select pg_backend_pid();
106121postgres= # select count(*) from foo join bar on foo.c1=bar.c1;
107122```
108123Other backend can extract intermediate state of execution that query:
109- ```
124+ ``` sql
110125postgres= # \x
111126postgres= # select * from pg_query_state(49265);
112127- [ RECORD1 ]+ -- -----------------------------------------------------------------------------------------------------------------------
@@ -151,11 +166,11 @@ In example above working backend spawns two parallel workers with pids `49324` a
151166` 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).
152167
153168Assume first backend executes some function:
154- ```
169+ ``` sql
155170postgres= # select n_join_foo_bar();
156171```
157172Other backend can get the follow output:
158- ```
173+ ``` sql
159174postgres= # select * from pg_query_state(49265);
160175- [ RECORD1 ]+ -- ----------------------------------------------------------------------------------------------------------------
161176pid |49265
@@ -181,7 +196,7 @@ leader_pid | (null)
181196First row corresponds to function call, second - to query which is in the body of that function.
182197
183198We can get result plans in different format (e.g.` json ` ):
184- ```
199+ ``` sql
185200postgres= # select * from pg_query_state(pid := 49265, format := 'json');
186201- [ RECORD1 ]+ -- ----------------------------------------------------------
187202pid |49265