Skip to content

Commit af930e6

Browse files
committed
Again fix initialization of auto-tuned effective_cache_size.
The previous method was overly complex and underly correct; in particular, by assigning the default value with PGC_S_OVERRIDE, it prevented later attempts to change the setting in postgresql.conf, as noted by Jeff Janes. We should just assign the default value with source PGC_S_DYNAMIC_DEFAULT, which will have the desired priority relative to the boot_val as well as user-set values. There is still a gap in this method: if there's an explicit assignment of effective_cache_size = -1 in the postgresql.conf file, and that assignment appears before shared_buffers is assigned, the code will substitute 4 times the bootstrap default for shared_buffers, and that value will then persist (since it will have source PGC_S_FILE). I don't see any very nice way to avoid that though, and it's not a case to be expected in practice. The existing comments in guc-file.l look forward to a redesign of the DYNAMIC_DEFAULT mechanism; if that ever happens, we should consider this case as one of the things we'd like to improve.
1 parent a4c8f14 commit af930e6

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/backend/optimizer/path/costsize.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4107,16 +4107,7 @@ check_effective_cache_size(int *newval, void **extra, GucSource source)
41074107
if (*newval <= 0)
41084108
{
41094109
/*
4110-
* If we haven't yet changed the initial default of -1, just let it
4111-
* be. We'll fix it later on during GUC initialization, when
4112-
* set_default_effective_cache_size is called. (If we try to do it
4113-
* immediately, we may not be looking at the final value of NBuffers.)
4114-
*/
4115-
if (effective_cache_size == -1)
4116-
return true;
4117-
4118-
/*
4119-
* Otherwise, substitute the auto-tune value, being wary of overflow.
4110+
* Substitute the auto-tune value, being wary of overflow.
41204111
*/
41214112
if (NBuffers < INT_MAX / 4)
41224113
*newval = NBuffers * 4;
@@ -4130,22 +4121,22 @@ check_effective_cache_size(int *newval, void **extra, GucSource source)
41304121
}
41314122

41324123
/*
4133-
* initialize effective_cache_size at the end of GUC startup
4124+
* Initialize effective_cache_size at the end of GUC startup, or when
4125+
* a setting in postgresql.conf is removed.
4126+
*
4127+
* Note: check_effective_cache_size() will have been called when the boot_val
4128+
* was installed, but we will not have known the final value of NBuffers at
4129+
* that time, which is why this has to be called at the end of GUC startup.
41344130
*/
41354131
void
41364132
set_default_effective_cache_size(void)
41374133
{
41384134
/*
4139-
* If the value of effective_cache_size is still -1 (or zero), replace it
4140-
* with the auto-tune value.
4135+
* We let check_effective_cache_size() compute the actual setting. Note
4136+
* that this call is a no-op if the user has supplied a setting (since
4137+
* that will have a higher priority than PGC_S_DYNAMIC_DEFAULT).
41414138
*/
4142-
if (effective_cache_size <= 0)
4143-
{
4144-
/* disable the short-circuit in check_effective_cache_size */
4145-
effective_cache_size = 0;
4146-
/* and let check_effective_cache_size() compute the setting */
4147-
SetConfigOption("effective_cache_size", "-1",
4148-
PGC_POSTMASTER, PGC_S_OVERRIDE);
4149-
}
4139+
SetConfigOption("effective_cache_size", "-1",
4140+
PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
41504141
Assert(effective_cache_size > 0);
41514142
}

src/backend/utils/misc/guc-file.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ ProcessConfigFile(GucContext context)
298298
{
299299
InitializeGUCOptionsFromEnvironment();
300300
pg_timezone_abbrev_initialize();
301+
set_default_effective_cache_size();
301302
/* this selects SQL_ASCII in processes not connected to a database */
302303
SetConfigOption("client_encoding", GetDatabaseEncodingName(),
303304
PGC_BACKEND, PGC_S_DYNAMIC_DEFAULT);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy