Look up backend type in pg_signal_backend() more cheaply. Commit ccd38024bc, which introduced the pg_signal_autovacuum_worker role, added a call to pgstat_get_beentry_by_proc_number() for the purpose of determining whether the process is an autovacuum worker. This function calls pgstat_read_current_status(), which can be fairly expensive and may return cached, out-of-date information. Since we just need to look up the target backend's BackendType, and we already know its ProcNumber, we can instead inspect the BackendStatusArray directly, which is much less expensive and possibly more up-to-date. There are some caveats with this approach (which are documented in the code), but it's still substantially better than before.
Reported-by: Andres Freund Reviewed-by: Andres Freund Discussion: https://postgr.es/m/ujenaa2uabzfkwxwmfifawzdozh3ljr7geozlhftsuosgm7n7q%40g3utqqyyosb6 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/61171a632d10ad7abe1d7ad891176266cc5ef0e1 Modified Files -------------- src/backend/storage/ipc/signalfuncs.c | 4 ++-- src/backend/utils/activity/backend_status.c | 25 +++++++++++++++++++++++++ src/include/utils/backend_status.h | 1 + 3 files changed, 28 insertions(+), 2 deletions(-)