Skip to content

Commit

Permalink
Change bgw_log_level to use PGC_SUSET
Browse files Browse the repository at this point in the history
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.

Since we want to allow configuration to be reloaded without restarting
the server, we are limited to `PGC_SUSET` and `PGC_SIGHUP`.
  • Loading branch information
mkindahl committed Dec 7, 2023
1 parent 9276312 commit d661580
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .unreleased/fix_6384
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes: #6384 Change bgw_log_level to use PGC_SUSET
2 changes: 1 addition & 1 deletion src/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ _guc_init(void)
/* valueAddr= */ &ts_guc_bgw_log_level,
/* bootValue= */ WARNING,
/* options= */ loglevel_options,
/* context= */ PGC_SIGHUP,
/* context= */ PGC_SUSET,
0,
NULL,
NULL,
Expand Down
10 changes: 8 additions & 2 deletions tsl/test/expected/bgw_scheduler_control.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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;
-- 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);
Expand Down Expand Up @@ -40,7 +41,7 @@ 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';
ALTER DATABASE :TEST_DBNAME SET timescaledb.bgw_log_level = 'DEBUG1';
SELECT pg_reload_conf();
pg_reload_conf
----------------
Expand Down Expand Up @@ -94,7 +95,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
----------------
Expand Down Expand Up @@ -126,3 +127,8 @@ SELECT delete_job(:job_id);

(1 row)

-- Make sure we can set the variable using ALTER SYSTEM. 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;
12 changes: 10 additions & 2 deletions tsl/test/sql/bgw_scheduler_control.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ 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;

-- 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);
Expand Down Expand Up @@ -44,7 +46,7 @@ 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';
ALTER DATABASE :TEST_DBNAME SET timescaledb.bgw_log_level = 'DEBUG1';
SELECT pg_reload_conf();

SELECT ts_bgw_params_reset_time(0, false);
Expand Down Expand Up @@ -75,7 +77,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;
Expand All @@ -84,3 +86,9 @@ SELECT ts_bgw_db_scheduler_test_run_and_wait_for_scheduler_finish(25, 0);
SELECT * FROM cleaned_bgw_log;

SELECT delete_job(:job_id);

-- Make sure we can set the variable using ALTER SYSTEM. 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;

0 comments on commit d661580

Please sign in to comment.