Skip to content

Commit

Permalink
Reposition PostgreSQL GUC declaration
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
Ivan Leskin committed Sep 4, 2020
1 parent 362fb52 commit a112e21
Showing 1 changed file with 48 additions and 38 deletions.
86 changes: 48 additions & 38 deletions diskquota.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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 ---- */

/*
Expand Down

0 comments on commit a112e21

Please sign in to comment.