On 29th of June, Andres Freund committed patch:

Add cluster_name GUC which is included in process titles if set.
 
When running several postgres clusters on one OS instance it's often
inconveniently hard to identify which "postgres" process belongs to
which postgres instance.
 
Add the cluster_name GUC, whose value will be included as part of the
process titles if set. With that processes can more easily identified
using tools like 'ps'.
 
To avoid problems with encoding mismatches between postgresql.conf,
consoles, and individual databases replace non-ASCII chars in the name
with question marks. The length is limited to NAMEDATALEN to make it
less likely to truncate important information at the end of the
status.
 
Thomas Munro, with some adjustments by me and review by a host of people.

This is simple, but helpful addition. If you ever ran multiple PostgreSQL instances (clusters) on the same machine – it can be problematic to find out which processes are related to which Pg.

Now, this is no longer a problem.

Normally, ps output looks like this:

$ ps -u pgdba uwf
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pgdba    26438  0.0  0.0 105652  2272 ?        S    22:07   0:00 sshd: pgdba@pts/11
pgdba    26439  0.0  0.0  25792  5880 pts/11   Ss+  22:07   0:00  \_ -bash
pgdba    26947  0.0  0.0 178480 13440 pts/11   S    22:14   0:00 /home/pgdba/work/bin/postgres
pgdba    26955  0.0  0.0  31532   740 ?        Ss   22:14   0:00  \_ postgres: logger process
pgdba    26957  0.0  0.0 178480  1052 ?        Ss   22:14   0:00  \_ postgres: checkpointer process
pgdba    26958  0.0  0.0 178480  1056 ?        Ss   22:14   0:00  \_ postgres: writer process
pgdba    26959  0.0  0.0 178480  1052 ?        Ss   22:14   0:00  \_ postgres: wal writer process
pgdba    26960  0.0  0.0 178888  1944 ?        Ss   22:14   0:00  \_ postgres: autovacuum launcher process
pgdba    26961  0.0  0.0  33624   780 ?        Ss   22:14   0:00  \_ postgres: archiver process
pgdba    26962  0.0  0.0  33784  1232 ?        Ss   22:14   0:00  \_ postgres: stats collector process

But after setting in postgresql.conf:

cluster_name = 'depesz-devel'

and restarting PostgreSQL (reload is not enough), I see:

$ ps -u pgdba uwf
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
pgdba    26438  0.0  0.0 105652  2272 ?        S    22:07   0:00 sshd: pgdba@pts/11
pgdba    26439  0.0  0.0  25760  5852 pts/11   Ss+  22:07   0:00  \_ -bash
pgdba    26598  0.0  0.0 178480 13464 pts/11   S    22:09   0:00 /home/pgdba/work/bin/postgres
pgdba    26602  0.0  0.0  31532  1168 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: logger process
pgdba    26604  0.0  0.0 178480  1364 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: checkpointer process
pgdba    26605  0.0  0.0 178620  2644 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: writer process
pgdba    26606  0.0  0.0 178480  5460 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: wal writer process
pgdba    26607  0.0  0.0 179000  2228 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: autovacuum launcher process
pgdba    26608  0.0  0.0  33624  1168 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: archiver process
pgdba    26609  0.0  0.0  33912  1608 ?        Ss   22:09   0:00  \_ postgres: depesz-devel: stats collector process

Looks nice. I wish the cluster_name was added to postmaster (main process) too, and that there would be log_line_prefix %-escape that would print it. But still – it's really cool. Thanks Thomas, and “a host of people" 🙂

Leave a comment