Proposal: Adding isbgworker column to pg_stat_activity

From: Paul Martinez <paulmtz(at)google(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Proposal: Adding isbgworker column to pg_stat_activity
Date: 2020-12-01 21:39:19
Message-ID: CACqFVBZgAmvCXtr_hk-xTneqCOMEyqoQzCUbeS5tDr8PkV7fGA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hey, all,

It is currently slightly difficult to determine how many background worker
processes are currently running, which is useful when trying to manage
the max_worker_processes parameter. It seems the best bet is to use the
backend_type column and filter out the many types that are defined in
miscinit.c:

https://github.com/postgres/postgres/blob/REL_13_1/src/backend/utils/init/miscinit.c#L201-L253

I would like to propose adding a simple column isbgworker, that simply
stores the value of the expression `beentry->st_backendType == B_BG_WORKER`,
which is used in pg_stat_get_activity.

https://github.com/postgres/postgres/blob/REL_13_1/src/backend/utils/adt/pgstatfuncs.c#L854-L867

Such a column would make it easier to determine a suitable value for the
max_worker_processes parameter. Similar internal resource parameters all
seem to have more straightforward ways to gauge their current usage:

max_wal_senders:
-> COUNT(*) FROM pg_stat_replication

max_parallel_workers:
-> COUNT(*) FROM pg_stat_activity WHERE backend_type = 'parallel worker'

max_replication_slots:
-> COUNT(*) FROM pg_replication_slots

max_connections:
-> COUNT(*) FROM pg_stat_activity WHERE backend_type = 'client backend'

Thoughts? I think it should be pretty easy to implement, and it would
also be beneficial to update the documentation for all of the above
parameters with notes about how to determine their current usage.

Thanks,
Paul

(Note: I asked a question related to this on pgsql-general:
https://www.postgresql.org/message-id/CACqFVBaH7OPT-smiE0xG6b_KVGkWNNhZ2-EoLNrbzLFSUgN2eQ%40mail.gmail.com
)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Patrick Handja 2020-12-01 21:42:56 Re: Setof RangeType returns
Previous Message Heikki Linnakangas 2020-12-01 20:59:22 Re: Index Skip Scan (new UniqueKeys)