Hi, Attached is a patch of pg_reload_backend that is a function signaling SIGHUP to a specific backend. The original idea is from Michael Paquier[1]. The documatation isn't included in this patch yet.
We can change some parameters of other backend using the function as bellow. postgres=# alter system set log_min_messages to debug2; ALTER SYSTEM postgres=# select pg_reload_backend(18375); pg_reload_backend ------------------- t (1 row) There are some usecases. For example: - changing log configuration in other backends temporally. - changing cost parameters for planner in other backends. - changing autovacuum parameters of an already running autovacuum worker. Hoever, this function need the superuser previlige to execute as well as pg_reload_conf(). Although we can grant the execution to public, it is useless for normal users bacause only superuser can change postgresql.conf. To allow normal users to change parameters in ohter backends, instead we might want another feature, for example, a function like set_config() than can change other backend's parameters using shared memory and SIGUSR1. Any comments would be appreciated. Regards, [1] https://www.postgresql.org/message-id/CAB7nPqT4y8-QoGKEugk99_tFuEOtAshcs5kxOeZ_0w27UtdGyA%40mail.gmail.com -- Yugo Nagata <nag...@sraoss.co.jp>
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 0fdad0c..3a9a020 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1128,6 +1128,7 @@ REVOKE EXECUTE ON FUNCTION pg_wal_replay_pause() FROM public; REVOKE EXECUTE ON FUNCTION pg_wal_replay_resume() FROM public; REVOKE EXECUTE ON FUNCTION pg_rotate_logfile() FROM public; REVOKE EXECUTE ON FUNCTION pg_reload_conf() FROM public; +REVOKE EXECUTE ON FUNCTION pg_reload_backend(int) FROM public; REVOKE EXECUTE ON FUNCTION pg_current_logfile() FROM public; REVOKE EXECUTE ON FUNCTION pg_current_logfile(text) FROM public; diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 62341b8..83b6c45 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -339,6 +339,36 @@ pg_reload_conf(PG_FUNCTION_ARGS) PG_RETURN_BOOL(true); } +/* + * Signal to reload the database configuration for a specified backend + * + * Permission checking for this function is managed through the normal + * GRANT system. + */ +Datum +pg_reload_backend(PG_FUNCTION_ARGS) +{ + int pid = PG_GETARG_INT32(0); + int r = pg_signal_backend(pid, SIGHUP); + + if (r == SIGNAL_BACKEND_NOSUPERUSER) + ereport(WARNING, + (errmsg("must be a superuser to reload superuser process"))); + + if (r == SIGNAL_BACKEND_NOPERMISSION) + ereport(WARNING, + (errmsg("must be a member of the role whose process is being reloaded or member of pg_signal_backend"))); + + if (r) + { + ereport(WARNING, + (errmsg("failed to send signal to backend: %d", pid))); + PG_RETURN_BOOL(false); + } + + PG_RETURN_BOOL(true); +} + /* * Rotate log file diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 1191b4a..a05e78a 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -3255,6 +3255,8 @@ DESCR("true if wal replay is paused"); DATA(insert OID = 2621 ( pg_reload_conf PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 16 "" _null_ _null_ _null_ _null_ _null_ pg_reload_conf _null_ _null_ _null_ )); DESCR("reload configuration files"); +DATA(insert OID = 3409 ( pg_reload_backend PGNSP PGUID 12 1 0 0 0 f f f f t f v s 1 0 16 "23" _null_ _null_ _null_ _null_ _null_ pg_reload_backend _null_ _null_ _null_ )); +DESCR("reload configuration files"); DATA(insert OID = 2622 ( pg_rotate_logfile PGNSP PGUID 12 1 0 0 0 f f f f t f v s 0 0 16 "" _null_ _null_ _null_ _null_ _null_ pg_rotate_logfile _null_ _null_ _null_ )); DESCR("rotate log file"); DATA(insert OID = 3800 ( pg_current_logfile PGNSP PGUID 12 1 0 0 0 f f f f f f v s 0 0 25 "" _null_ _null_ _null_ _null_ _null_ pg_current_logfile _null_ _null_ _null_ ));
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers