Process Monitoring

Postgres backend processes can be monitored with the C/C++ debugging tool “rr”
(record & replay) in Linux operating systems.
Postgres must be installed with the debugger option (details are available in the
installation steps from the enable-debug source code).

postgres@T470s:~$ rr record -M /pg/home/13.6/bin/postgres \

-D $PGDATA \

--log_line_prefix=”%m %p “ \

--effective_cache_size=1GB \

--random_page_cost=4.0 \

--work_mem=4MB \

--maintenance_work_mem=64MB \

--fsync=off \

--log_statement=all \

--log_min_messages=DEBUG5 \

--max_connections=50 \

--shared_buffers=1024MB

rr: Saving execution to trace directory `/pg/home/.local/share/
rr/postgres-3’.
[rr 28166 1310989] 07:21 28166 DEBUG: pg_toast_6000: vac: 0
(threshold 50), ins: 0 (threshold 1000), anl: 0 (threshold 50)
[rr 28166 1310993] 07:21 28166 DEBUG: pg_toast_2396: vac: 0
(threshold 50), ins: 0 (threshold 1000), anl: 0 (threshold 50)
[rr 28166 1310997] 07:21 28166 DEBUG: pg_toast_3592: vac: 0
(threshold 50), ins: 0 (threshold 1000), anl: 0 (threshold 50)
[rr 28166 1311001] 07:21 28166 DEBUG: pg_toast_6100: vac: 0
(threshold 50), ins: 0 (threshold 1000), anl: 0 (threshold 50)
[rr 28166 1311005] 07:21 28166 DEBUG: pg_toast_1213: vac: 0
(threshold 50), ins: 0 (threshold 1000), anl: 0 (threshold 50)

postgres=# SELECT pg_backend_pid() ;

pg_backend_pid

----------------

29557

postgres=# insert into heartbeat values (now());

[rr 29557 13106] DEBUG: StartTransaction(1) name: unnamed; blockState:
DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
[rr 29557 13110] LOG: statement: insert into heartbeat values (now());
[rr 29557 13130] DEBUG: CommitTransaction(1) name: unnamed;
blockState: STARTED; state: INPROGRESS, xid/subid/cid: 15764/1/0 (used)
[rr 29552 13156] DEBUG: snapshot of 0+0 running transaction ids (lsn
0/1088E4F0 oldest xid 15765 latest complete 15764 next xid 15765)
[rr 29557 14484] DEBUG: StartTransaction(1) name: unnamed; blockState:
DEFAULT; state: INPROGRESS, xid/subid/cid: 0/1/0
[rr 29557 14488] LOG: statement: commit ;
[rr 29557 14492] WARNING: there is no transaction in progress
[rr 29557 14496] DEBUG: CommitTransaction(1) name: unnamed;
blockState: STARTED; state: INPROGRESS, xid/subid/cid: 0/1/0

Can be terminated with CTRL C

or you can end with

pg_ctl -D /pg/data/13.6/ -l pg.log stop

# To go to a specific event ID

postgres@T470s:~$ rr replay -M -g 29557

# Auto pilot

postgres@T470s:~$ rr replay -M -a &> rr.log

# For detail

man rr

Logs are written to the home folder ($HOME/.local/share/rr/) of the executing
user. Log lines begin with square brackets. The first number is the PID (process ID), the
second number is the event number.
With Replay, it is possible to print the logs to the screen again.


postgres@T470s:~$ cd /pg/home/setup/postgresql-13.6

postgres@T470s:~$ make installcheck

…
test tuplesort ... ok 1366 ms
test explain ... ok 218 ms
test event_trigger ... ok 339 ms
test fast_default ... ok 489 ms
test stats ... ok 596 ms

=======================
All 201 tests passed.
=======================

make[1]: Leaving directory ‘/pg/home/setup/postgresql-13.6/src/test/regress’

When running Postgres with rr, general check can be done with make installcheck.
Thus, information is provided about how long it takes to complete a process.