Skip to content

Commit 681a9c5

Browse files
committed
Add the xmin horizon to running query display
The xmin horizon was added in 9.4 in commit [1]. [1] postgres/postgres@dd1a3bc
1 parent 15bffac commit 681a9c5

26 files changed

+166
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
configuration.
1212
* Add a `y` command to copy focused query to the system clipboard, using
1313
OSC 52 escape sequence (#311).
14+
* Add the `xmin` column to the query display (#425).
1415

1516
### Fixed
1617

docs/man/pg_activity.1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ The running queries panel shows all running queries, transactions or backends
182182
.IP "\- \fBPID\fR: process id of the backend which executes the query;" 2
183183
.IX Item "- PID: process id of the backend which executes the query;"
184184
.PD 0
185+
.IP "\- \fBXMIN\fR: xmin horizon of the backend;" 2
186+
.IX Item "- XMIN: xmin horizon of the backend;"
185187
.IP "\- \fBDATABASE\fR: database specified in the connection string;" 2
186188
.IX Item "- DATABASE: database specified in the connection string;"
187189
.IP "\- \fBAPP\fR: application name specified in the connection string;" 2
@@ -364,6 +366,11 @@ required by another session. It shows following information:
364366
.Vb 1
365367
\& Enable/disable PID.
366368
.Ve
369+
.IP "\fB\-\-xmin\fR, \fB\-\-no\-xmin\fR" 2
370+
.IX Item "--xmin, --no-xmin"
371+
.Vb 1
372+
\& Enable/disable XMIN.
373+
.Ve
367374
.IP "\fB\-\-database\fR, \fB\-\-no\-database\fR" 2
368375
.IX Item "--database, --no-database"
369376
.Vb 1

docs/man/pg_activity.pod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ B<min duration> seconds. It displays the following information:
136136

137137
=item - B<PID>: process id of the backend which executes the query;
138138

139+
=item - B<XMIN>: xmin horizon of the backend;
140+
139141
=item - B<DATABASE>: database specified in the connection string;
140142

141143
=item - B<APP>: application name specified in the connection string;
@@ -322,6 +324,10 @@ required by another session. It shows following information:
322324

323325
Enable/disable PID.
324326

327+
=item B<--xmin>, B<--no-xmin>
328+
329+
Enable/disable XMIN.
330+
325331
=item B<--database>, B<--no-database>
326332

327333
Enable/disable DATABASE.

pgactivity/activities.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
151151
>>> processes = [
152152
... LocalRunningProcess(
153153
... pid="6240",
154+
... xmin="1234",
154155
... application_name="pgbench",
155156
... database="pgbench",
156157
... user="postgres",
@@ -170,6 +171,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
170171
... ),
171172
... LocalRunningProcess(
172173
... pid="6239",
174+
... xmin="2345",
173175
... application_name="pgbench",
174176
... database="pgbench",
175177
... user="postgres",
@@ -189,6 +191,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
189191
... ),
190192
... LocalRunningProcess(
191193
... pid="6228",
194+
... xmin="3456",
192195
... application_name="pgbench",
193196
... database="pgbench",
194197
... user="postgres",
@@ -225,6 +228,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
225228
>>> processes = [
226229
... LocalRunningProcess(
227230
... pid="6240",
231+
... xmin="1234",
228232
... application_name="pgbench",
229233
... database="pgbench",
230234
... user="postgres",
@@ -244,6 +248,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
244248
... ),
245249
... LocalRunningProcess(
246250
... pid="6239",
251+
... xmin="2345",
247252
... application_name="pgbench",
248253
... database="pgbench",
249254
... user="postgres",
@@ -263,6 +268,7 @@ def sorted(processes: list[T], *, key: SortKey, reverse: bool = False) -> list[T
263268
... ),
264269
... LocalRunningProcess(
265270
... pid="6228",
271+
... xmin="3456",
266272
... application_name="pgbench",
267273
... database="pgbench",
268274
... user="postgres",

pgactivity/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def get_parser() -> argparse.ArgumentParser:
221221
"These options may be used hide some columns from the processes table.",
222222
)
223223
flag(group, "--pid", dest="pid", feature="PID")
224+
flag(group, "--xmin", dest="xmin", feature="XMIN")
224225
flag(group, "--database", dest="database", feature="DATABASE")
225226
flag(group, "--user", dest="user", feature="USER")
226227
flag(group, "--client", dest="client", feature="CLIENT")

pgactivity/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ class Flag(enum.Flag):
6262
"""Column flag.
6363
6464
>>> Flag.names()
65-
['database', 'appname', 'client', 'user', 'cpu', 'mem', 'read', 'write', 'time', 'wait', 'relation', 'type', 'mode', 'iowait', 'pid']
65+
['database', 'appname', 'client', 'user', 'cpu', 'mem', 'read', 'write', 'time', 'wait', 'relation', 'type', 'mode', 'iowait', 'pid', 'xmin']
6666
>>> Flag.all() # doctest: +ELLIPSIS
67-
<Flag...: 32767>
67+
<Flag...: 65535>
6868
"""
6969

7070
DATABASE = enum.auto()
@@ -82,6 +82,7 @@ class Flag(enum.Flag):
8282
MODE = enum.auto()
8383
IOWAIT = enum.auto()
8484
PID = enum.auto()
85+
XMIN = enum.auto()
8586

8687
@classmethod
8788
def names(cls) -> list[str]:
@@ -131,6 +132,7 @@ def load(
131132
user: bool | None,
132133
wait: bool | None,
133134
write: bool | None,
135+
xmin: bool | None,
134136
**kwargs: Any,
135137
) -> Flag:
136138
"""Build a Flag value from command line options."""
@@ -150,6 +152,7 @@ def load(
150152
(user, cls.USER),
151153
(wait, cls.WAIT),
152154
(write, cls.WRITE),
155+
(xmin, cls.XMIN),
153156
):
154157
if opt is True:
155158
flag |= value

pgactivity/profiles/minimal.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ show_instance = no
33
show_system = no
44
show_workers = no
55

6+
[xmin]
7+
hidden = yes
8+
69
[database]
710
hidden = yes
811

pgactivity/profiles/narrow.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[xmin]
2+
hidden = yes
3+
14
[database]
25
hidden = yes
36

pgactivity/profiles/wide.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[xmin]
2+
hidden = no
3+
14
[database]
25
hidden = no
36

pgactivity/queries/get_pg_activity_oldest.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Get data from pg_activity before pg 9.2
22
SELECT
33
a.procpid AS pid,
4+
NULL AS xmin,
45
'<unknown>' AS application_name,
56
a.datname AS database,
67
a.client_addr AS client,

0 commit comments

Comments
 (0)