mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 01:53:41 +08:00
Change bgw_log_level to use PGC_SUSET
Right now `bgw_log_level` requires `ALTER SYSTEM` since it is using `PGC_SIGHUP` but we want to make sure that it is possible to set the scheduler log level using `ALTER DATABASE` which allows it to be replicated and also allows the database owner to set the value rather than requiring superuser privileges or explicit grants. Since we want to allow configuration to be reloaded without restarting the server, we are limited to `PGC_SUSET` and `PGC_SIGHUP` and tests are added for PG15 and later to make sure that we can grant privileges to use `ALTER SYSTEM` and `ALTER DATABASE` to set the parameter.
This commit is contained in:
parent
2f6d1b68da
commit
0d0290c830
1
.unreleased/fix_6384
Normal file
1
.unreleased/fix_6384
Normal file
@ -0,0 +1 @@
|
||||
Fixes: #6384 Change bgw_log_level to use PGC_SUSET
|
@ -574,7 +574,7 @@ _guc_init(void)
|
||||
/* valueAddr= */ &ts_guc_bgw_log_level,
|
||||
/* bootValue= */ WARNING,
|
||||
/* options= */ loglevel_options,
|
||||
/* context= */ PGC_SIGHUP,
|
||||
/* context= */ PGC_SUSET,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
|
@ -10,6 +10,9 @@ CREATE FUNCTION ts_bgw_params_destroy() RETURNS VOID
|
||||
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
|
||||
CREATE FUNCTION ts_bgw_params_reset_time(set_time BIGINT, wait BOOLEAN) RETURNS VOID
|
||||
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
|
||||
ALTER DATABASE :TEST_DBNAME OWNER TO :ROLE_DEFAULT_PERM_USER;
|
||||
GRANT EXECUTE ON FUNCTION pg_reload_conf TO :ROLE_DEFAULT_PERM_USER;
|
||||
GRANT ALTER SYSTEM, SET ON PARAMETER timescaledb.bgw_log_level TO :ROLE_DEFAULT_PERM_USER;
|
||||
-- These are needed to set up the test scheduler
|
||||
CREATE TABLE public.bgw_dsm_handle_store(handle BIGINT);
|
||||
INSERT INTO public.bgw_dsm_handle_store VALUES (0);
|
||||
@ -39,14 +42,18 @@ TRUNCATE _timescaledb_internal.bgw_job_stat;
|
||||
--
|
||||
-- Debug messages should be in log now which it wasn't before.
|
||||
--
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
ALTER SYSTEM SET timescaledb.bgw_log_level = 'DEBUG1';
|
||||
-- We change user to make sure that granting SET and ALTER SYSTEM
|
||||
-- privileges to the default user actually works.
|
||||
--
|
||||
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
||||
ALTER DATABASE :TEST_DBNAME SET timescaledb.bgw_log_level = 'DEBUG1';
|
||||
SELECT pg_reload_conf();
|
||||
pg_reload_conf
|
||||
----------------
|
||||
t
|
||||
(1 row)
|
||||
|
||||
RESET ROLE;
|
||||
SELECT ts_bgw_params_reset_time(0, false);
|
||||
ts_bgw_params_reset_time
|
||||
--------------------------
|
||||
@ -94,7 +101,7 @@ SELECT * FROM cleaned_bgw_log;
|
||||
4 | DB Scheduler | database scheduler for database (RANDOM) exiting
|
||||
(7 rows)
|
||||
|
||||
ALTER SYSTEM RESET timescaledb.bgw_log_level;
|
||||
ALTER DATABASE :TEST_DBNAME RESET timescaledb.bgw_log_level;
|
||||
SELECT pg_reload_conf();
|
||||
pg_reload_conf
|
||||
----------------
|
||||
@ -126,3 +133,9 @@ SELECT delete_job(:job_id);
|
||||
|
||||
(1 row)
|
||||
|
||||
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
||||
-- Make sure we can set the variable using ALTER SYSTEM using the
|
||||
-- previous grants. We don't bother about checking that it has an
|
||||
-- effect here since we already knows it works from the above code.
|
||||
ALTER SYSTEM SET timescaledb.bgw_log_level TO 'DEBUG2';
|
||||
ALTER SYSTEM RESET timescaledb.bgw_log_level;
|
||||
|
@ -44,7 +44,6 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
APPEND
|
||||
TEST_FILES
|
||||
bgw_db_scheduler.sql
|
||||
bgw_scheduler_control.sql
|
||||
job_errors_permissions.sql
|
||||
troubleshooting_job_errors.sql
|
||||
bgw_db_scheduler_fixed.sql
|
||||
@ -95,6 +94,9 @@ if((${PG_VERSION_MAJOR} GREATER_EQUAL "14"))
|
||||
endif()
|
||||
|
||||
if((${PG_VERSION_MAJOR} GREATER_EQUAL "15"))
|
||||
if(CMAKE_BUILD_TYPE MATCHES Debug)
|
||||
list(APPEND TEST_FILES bgw_scheduler_control.sql)
|
||||
endif()
|
||||
list(APPEND TEST_FILES merge_compress.sql)
|
||||
endif()
|
||||
|
||||
|
@ -15,6 +15,10 @@ AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
|
||||
CREATE FUNCTION ts_bgw_params_reset_time(set_time BIGINT, wait BOOLEAN) RETURNS VOID
|
||||
AS :MODULE_PATHNAME LANGUAGE C VOLATILE;
|
||||
|
||||
ALTER DATABASE :TEST_DBNAME OWNER TO :ROLE_DEFAULT_PERM_USER;
|
||||
GRANT EXECUTE ON FUNCTION pg_reload_conf TO :ROLE_DEFAULT_PERM_USER;
|
||||
GRANT ALTER SYSTEM, SET ON PARAMETER timescaledb.bgw_log_level TO :ROLE_DEFAULT_PERM_USER;
|
||||
|
||||
-- These are needed to set up the test scheduler
|
||||
CREATE TABLE public.bgw_dsm_handle_store(handle BIGINT);
|
||||
INSERT INTO public.bgw_dsm_handle_store VALUES (0);
|
||||
@ -43,10 +47,14 @@ TRUNCATE _timescaledb_internal.bgw_job_stat;
|
||||
--
|
||||
-- Debug messages should be in log now which it wasn't before.
|
||||
--
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
ALTER SYSTEM SET timescaledb.bgw_log_level = 'DEBUG1';
|
||||
-- We change user to make sure that granting SET and ALTER SYSTEM
|
||||
-- privileges to the default user actually works.
|
||||
--
|
||||
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
||||
ALTER DATABASE :TEST_DBNAME SET timescaledb.bgw_log_level = 'DEBUG1';
|
||||
SELECT pg_reload_conf();
|
||||
|
||||
RESET ROLE;
|
||||
SELECT ts_bgw_params_reset_time(0, false);
|
||||
INSERT INTO _timescaledb_config.bgw_job(
|
||||
application_name,
|
||||
@ -75,7 +83,7 @@ INSERT INTO _timescaledb_config.bgw_job(
|
||||
SELECT ts_bgw_db_scheduler_test_run_and_wait_for_scheduler_finish(25, 0);
|
||||
SELECT * FROM cleaned_bgw_log;
|
||||
|
||||
ALTER SYSTEM RESET timescaledb.bgw_log_level;
|
||||
ALTER DATABASE :TEST_DBNAME RESET timescaledb.bgw_log_level;
|
||||
SELECT pg_reload_conf();
|
||||
|
||||
TRUNCATE bgw_log;
|
||||
@ -84,3 +92,11 @@ SELECT ts_bgw_db_scheduler_test_run_and_wait_for_scheduler_finish(25, 0);
|
||||
SELECT * FROM cleaned_bgw_log;
|
||||
|
||||
SELECT delete_job(:job_id);
|
||||
|
||||
SET ROLE :ROLE_DEFAULT_PERM_USER;
|
||||
|
||||
-- Make sure we can set the variable using ALTER SYSTEM using the
|
||||
-- previous grants. We don't bother about checking that it has an
|
||||
-- effect here since we already knows it works from the above code.
|
||||
ALTER SYSTEM SET timescaledb.bgw_log_level TO 'DEBUG2';
|
||||
ALTER SYSTEM RESET timescaledb.bgw_log_level;
|
||||
|
Loading…
x
Reference in New Issue
Block a user