From a112e210d6098e7b1e5036c260974315e0c0be61 Mon Sep 17 00:00:00 2001 From: Ivan Leskin Date: Fri, 4 Sep 2020 16:17:32 +0300 Subject: [PATCH] Reposition PostgreSQL GUC declaration GUC variables must be declared before any other actions are made by diskquota. In particular, the value of 'diskquota_max_active_tables' (GUC 'diskquota.max_active_tables') is used in 'DiskQuotaShmemSize()'. The late GUC variable declaration caused this variable to be '0', thus leading to allocation of insufficient amount of memory. Fix this: 1. Move GUC declarations to a separate static function 2. Call this function before any other actions performed in _PG_init() --- diskquota.c | 86 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/diskquota.c b/diskquota.c index f411d212..5e998f24 100644 --- a/diskquota.c +++ b/diskquota.c @@ -95,6 +95,7 @@ void disk_quota_launcher_main(Datum); static void disk_quota_sigterm(SIGNAL_ARGS); static void disk_quota_sighup(SIGNAL_ARGS); +static void define_guc_variables(void); static bool start_worker_by_dboid(Oid dbid); static void start_workers_from_dblist(void); static void create_monitor_db_table(void); @@ -128,48 +129,13 @@ _PG_init(void) if (!process_shared_preload_libraries_in_progress) ereport(ERROR, (errmsg("diskquota.so not in shared_preload_libraries."))); + /* values are used in later calls */ + define_guc_variables(); + init_disk_quota_shmem(); init_disk_quota_enforcement(); init_active_table_hook(); - /* get the configuration */ - DefineCustomIntVariable("diskquota.naptime", - "Duration between each check (in seconds).", - NULL, - &diskquota_naptime, - 2, - 1, - INT_MAX, - PGC_SIGHUP, - 0, - NULL, - NULL, - NULL); - - DefineCustomIntVariable("diskquota.max_active_tables", - "max number of active tables monitored by disk-quota", - NULL, - &diskquota_max_active_tables, - 1 * 1024 * 1024, - 1, - INT_MAX, - PGC_SIGHUP, - 0, - NULL, - NULL, - NULL); - - DefineCustomBoolVariable("diskquota.enable_hardlimit", - "Use in-query diskquota enforcement", - NULL, - &diskquota_enable_hardlimit, - false, - PGC_SIGHUP, - 0, - NULL, - NULL, - NULL); - /* start disk quota launcher only on master */ if (!IS_QUERY_DISPATCHER()) { @@ -250,6 +216,50 @@ disk_quota_sigusr1(SIGNAL_ARGS) errno = save_errno; } +/* + * Define GUC variables used by diskquota + */ +static void +define_guc_variables(void) +{ + DefineCustomIntVariable("diskquota.naptime", + "Duration between each check (in seconds).", + NULL, + &diskquota_naptime, + 2, + 1, + INT_MAX, + PGC_SIGHUP, + 0, + NULL, + NULL, + NULL); + + DefineCustomIntVariable("diskquota.max_active_tables", + "max number of active tables monitored by disk-quota", + NULL, + &diskquota_max_active_tables, + 1 * 1024 * 1024, + 1, + INT_MAX, + PGC_SIGHUP, + 0, + NULL, + NULL, + NULL); + + DefineCustomBoolVariable("diskquota.enable_hardlimit", + "Use in-query diskquota enforcement", + NULL, + &diskquota_enable_hardlimit, + false, + PGC_SIGHUP, + 0, + NULL, + NULL, + NULL); +} + /* ---- Functions for disk quota worker process ---- */ /*