mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Add pg_file_settings view and function
The function and view added here provide a way to look at all settings in postgresql.conf, any #include'd files, and postgresql.auto.conf (which is what backs the ALTER SYSTEM command). The information returned includes the configuration file name, line number in that file, sequence number indicating when the parameter is loaded (useful to see if it is later masked by another definition of the same parameter), parameter name, and what it is set to at that point. This information is updated on reload of the server. This is unfiltered, privileged, information and therefore access is restricted to superusers through the GRANT system. Author: Sawada Masahiko, various improvements by me. Reviewers: David Steele
This commit is contained in:
@@ -120,6 +120,7 @@ ProcessConfigFile(GucContext context)
|
||||
*head,
|
||||
*tail;
|
||||
int i;
|
||||
int file_variables_count = 0;
|
||||
|
||||
/*
|
||||
* Config files are processed on startup (by the postmaster only)
|
||||
@@ -255,6 +256,7 @@ ProcessConfigFile(GucContext context)
|
||||
error = true;
|
||||
ConfFileWithError = item->filename;
|
||||
}
|
||||
file_variables_count++;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -341,6 +343,54 @@ ProcessConfigFile(GucContext context)
|
||||
PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if we have allocated the array yet.
|
||||
*
|
||||
* If not, allocate it based on the number of file variables we have seen.
|
||||
*/
|
||||
if (!guc_file_variables)
|
||||
{
|
||||
/* For the first call */
|
||||
num_guc_file_variables = file_variables_count;
|
||||
guc_file_variables = (ConfigFileVariable *) guc_malloc(FATAL,
|
||||
num_guc_file_variables * sizeof(struct ConfigFileVariable));
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Free all of the previously allocated entries */
|
||||
for (i = 0; i < num_guc_file_variables; i++)
|
||||
{
|
||||
free(guc_file_variables[i].name);
|
||||
free(guc_file_variables[i].value);
|
||||
free(guc_file_variables[i].filename);
|
||||
}
|
||||
|
||||
/* Update the global count and realloc based on the new size */
|
||||
num_guc_file_variables = file_variables_count;
|
||||
guc_file_variables = (ConfigFileVariable *) guc_realloc(FATAL,
|
||||
guc_file_variables,
|
||||
num_guc_file_variables * sizeof(struct ConfigFileVariable));
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the settings which came from the files read into the
|
||||
* guc_file_variables array which backs the pg_show_file_settings()
|
||||
* function.
|
||||
*/
|
||||
for (item = head, i = 0; item && i < num_guc_file_variables;
|
||||
item = item->next, i++)
|
||||
{
|
||||
guc_file_variables[i].name = guc_strdup(FATAL, item->name);
|
||||
guc_file_variables[i].value = guc_strdup(FATAL, item->value);
|
||||
guc_file_variables[i].filename = guc_strdup(FATAL, item->filename);
|
||||
guc_file_variables[i].sourceline = item->sourceline;
|
||||
}
|
||||
|
||||
/* We had better have made it through the loop above to a clean ending. */
|
||||
Assert(!item && i == num_guc_file_variables);
|
||||
|
||||
/*
|
||||
* Now apply the values from the config file.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user