Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to change the value of PostgreSQL configuration parameters

Shulou Source: shulou.com Published: 2022-06-02 02:09:31 11月14日 Update

Today, I will talk to you about how to change the values of PostgreSQL configuration parameters, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Configuration parameters (or GUC variables, grand unified configuration) are common settings that appear in postgresql.conf. For more information, please see document 19. Server Configuration. I focus on how they are set and play a role in the code.

1. Parameter value change function definition

VoidSetConfigOption (const char * name, const char * value, GucContext context, GucSource source)

The first parameter is the parameter name, the second is the value represented by the string, the third is the context of the modified action in which it is called, and the fourth is the parameter source.

2. Two examples of initialization

SetConfigOption ("transaction_deferrable", "no", PGC_POSTMASTER, PGC_S_OVERRIDE)

And read environment variables (InitializeGUCOptionsFromEnvironment ())

SetConfigOption ("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR)

When you read that a config_generic structure member vartype is PGC_BOOL, you can know that it actually points to a config_bool type structure.

While SetConfigOption just encapsulates the call set_config_option, let's look at the role of each definition of the parameter from the code logic of the latter.

3. The third parameter of the function set_config_option

We mentioned the parameter context earlier, and we all know that some parameters are not allowed to be modified after startup, which is the context control:

Else if (context! = PGC_POSTMASTER) {ereport (elevel, (errcode (ERRCODE_CANT_CHANGE_RUNTIME_PARAM), errmsg ("parameter\"% s\ "cannot be changed without restarting the server", name); return 0;}

You can know how the parameter is modified (such as the SET command) and the context of the modification. Compared with the definition of the parameter, it is easy to know whether to accept or reject the new value.

4. Analytical conversion of parameter values.

The values you set are all strings, that is, the second parameter, const char * value, which needs to be converted to corresponding values, such as enumerations. Go back to the definition of the enumeration parameters:

{{"backslash_quote", PGC_USERSET, COMPAT_OPTIONS_PREVIOUS, gettext_noop ("Sets whether\"\'\ "is allowed in string literals."), NULL}, & backslash_quote, BACKSLASH_QUOTE_SAFE_ENCODING, backslash_quote_options, NULL, NULL, NULL}

Let's take a look at backslash_quote_options:

Static const struct config_enum_entry backslash_quote_options [] = {{"safe_encoding", BACKSLASH_QUOTE_SAFE_ENCODING, false}, {"on", BACKSLASH_QUOTE_ON, false}, {"off", BACKSLASH_QUOTE_OFF, false}, {"true", BACKSLASH_QUOTE_ON, true}, {"false", BACKSLASH_QUOTE_OFF, true}, {"yes", BACKSLASH_QUOTE_ON, true} {"no", BACKSLASH_QUOTE_OFF, true}, {"1", BACKSLASH_QUOTE_ON, true}, {"0", BACKSLASH_QUOTE_OFF, true}, {NULL, 0, false}}

Finally, it is checked and parsed by the function parse_and_validate_value, and you can read the code by yourself if you are interested.

5. Value with unit

Shared_buffer = 128MB, which we should all have seen, is defined as an integer and is handled by the function parse_int. It is the memory unit (GUC_UNIT_BLOCKS), and the final size is calculated by converting the table memory_unit_conversion_table, which is the transformation definition of shared_buffer: 1MB = 1024 / (BLCKSZ / 1024) blocks.

After reading the above, do you have any further understanding of how to change the values of PostgreSQL configuration parameters? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Parameters up and down context function configuration code content three that is function unit variable character string that is way more structure two examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Microsoft MySQL Shulou Tech Info Apple