Skip to content

Commit a16d421

Browse files
committed
Revert "Auto-tune effective_cache size to be 4x shared buffers"
This reverts commit ee1e566, as well as a remarkably large number of followup commits, which were mostly concerned with the fact that the implementation didn't work terribly well. It still doesn't: we probably need some rather basic work in the GUC infrastructure if we want to fully support GUCs whose default varies depending on the value of another GUC. Meanwhile, it also emerged that there wasn't really consensus in favor of the definition the patch tried to implement (ie, effective_cache_size should default to 4 times shared_buffers). So whack it all back to where it was. In a followup commit, I'll do what was recently agreed to, which is to simply change the default to a higher value.
1 parent 08c8e89 commit a16d421

File tree

9 files changed

+8
-74
lines changed

9 files changed

+8
-74
lines changed

doc/src/sgml/config.sgml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,16 +3194,8 @@ include 'filename'
31943194
memory allocated by <productname>PostgreSQL</productname>, nor
31953195
does it reserve kernel disk cache; it is used only for estimation
31963196
purposes. The system also does not assume data remains in
3197-
the disk cache between queries.
3198-
</para>
3199-
3200-
<para>
3201-
If <varname>effective_cache_size</> is set to -1, which is the
3202-
default, the value is replaced by an automatically selected value,
3203-
currently four times the size of <xref linkend="guc-shared-buffers">.
3204-
For recommended settings of <varname>shared_buffers</>, this should
3205-
give reasonable results if this database cluster can use most of the
3206-
memory on the server.
3197+
the disk cache between queries. The default is 128 megabytes
3198+
(<literal>128MB</>).
32073199
</para>
32083200
</listitem>
32093201
</varlistentry>

src/backend/optimizer/path/costsize.c

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
#ifdef _MSC_VER
7272
#include <float.h> /* for _isnan */
7373
#endif
74-
#include <limits.h>
7574
#include <math.h>
7675

7776
#include "access/htup_details.h"
@@ -88,7 +87,6 @@
8887
#include "optimizer/planmain.h"
8988
#include "optimizer/restrictinfo.h"
9089
#include "parser/parsetree.h"
91-
#include "utils/guc.h"
9290
#include "utils/lsyscache.h"
9391
#include "utils/selfuncs.h"
9492
#include "utils/spccache.h"
@@ -104,7 +102,7 @@ double cpu_tuple_cost = DEFAULT_CPU_TUPLE_COST;
104102
double cpu_index_tuple_cost = DEFAULT_CPU_INDEX_TUPLE_COST;
105103
double cpu_operator_cost = DEFAULT_CPU_OPERATOR_COST;
106104

107-
int effective_cache_size = -1; /* will get replaced */
105+
int effective_cache_size = DEFAULT_EFFECTIVE_CACHE_SIZE;
108106

109107
Cost disable_cost = 1.0e10;
110108

@@ -4093,50 +4091,3 @@ page_size(double tuples, int width)
40934091
{
40944092
return ceil(relation_byte_size(tuples, width) / BLCKSZ);
40954093
}
4096-
4097-
/*
4098-
* GUC check_hook for effective_cache_size
4099-
*/
4100-
bool
4101-
check_effective_cache_size(int *newval, void **extra, GucSource source)
4102-
{
4103-
/*
4104-
* -1 is the documented way of requesting auto-tune, but we also treat
4105-
* zero as meaning that, since we don't consider zero a valid setting.
4106-
*/
4107-
if (*newval <= 0)
4108-
{
4109-
/*
4110-
* Substitute the auto-tune value, being wary of overflow.
4111-
*/
4112-
if (NBuffers < INT_MAX / 4)
4113-
*newval = NBuffers * 4;
4114-
else
4115-
*newval = INT_MAX;
4116-
}
4117-
4118-
Assert(*newval > 0);
4119-
4120-
return true;
4121-
}
4122-
4123-
/*
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.
4130-
*/
4131-
void
4132-
set_default_effective_cache_size(void)
4133-
{
4134-
/*
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).
4138-
*/
4139-
SetConfigOption("effective_cache_size", "-1",
4140-
PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT);
4141-
Assert(effective_cache_size > 0);
4142-
}

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

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

src/backend/utils/misc/guc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,8 +2512,8 @@ static struct config_int ConfigureNamesInt[] =
25122512
GUC_UNIT_BLOCKS,
25132513
},
25142514
&effective_cache_size,
2515-
-1, -1, INT_MAX,
2516-
check_effective_cache_size, NULL, NULL
2515+
DEFAULT_EFFECTIVE_CACHE_SIZE, 1, INT_MAX,
2516+
NULL, NULL, NULL
25172517
},
25182518

25192519
{
@@ -4372,9 +4372,6 @@ SelectConfigFiles(const char *userDoption, const char *progname)
43724372
*/
43734373
pg_timezone_abbrev_initialize();
43744374

4375-
/* Also install the correct value for effective_cache_size */
4376-
set_default_effective_cache_size();
4377-
43784375
/*
43794376
* Figure out where pg_hba.conf is, and make sure the path is absolute.
43804377
*/

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
#cpu_tuple_cost = 0.01 # same scale as above
284284
#cpu_index_tuple_cost = 0.005 # same scale as above
285285
#cpu_operator_cost = 0.0025 # same scale as above
286-
#effective_cache_size = -1 # -1 selects auto-tuned default
286+
#effective_cache_size = 128MB
287287

288288
# - Genetic Query Optimizer -
289289

src/include/optimizer/cost.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define DEFAULT_CPU_INDEX_TUPLE_COST 0.005
2828
#define DEFAULT_CPU_OPERATOR_COST 0.0025
2929

30+
#define DEFAULT_EFFECTIVE_CACHE_SIZE 16384 /* measured in pages */
31+
3032
typedef enum
3133
{
3234
CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */

src/include/utils/guc.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,4 @@ extern void assign_search_path(const char *newval, void *extra);
389389
extern bool check_wal_buffers(int *newval, void **extra, GucSource source);
390390
extern void assign_xlog_sync_method(int new_sync_method, void *extra);
391391

392-
/* in optimizer/path/costsize.c */
393-
extern bool check_effective_cache_size(int *newval, void **extra, GucSource source);
394-
extern void set_default_effective_cache_size(void);
395-
396392
#endif /* GUC_H */

src/test/regress/expected/join.out

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,6 @@ select * from tenk1 a join tenk1 b on
27592759
--
27602760
-- test placement of movable quals in a parameterized join tree
27612761
--
2762-
set effective_cache_size = '128MB';
27632762
explain (costs off)
27642763
select * from tenk1 t1 left join
27652764
(tenk1 t2 join tenk1 t3 on t2.thousand = t3.unique2)

src/test/regress/sql/join.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,8 +721,6 @@ select * from tenk1 a join tenk1 b on
721721
-- test placement of movable quals in a parameterized join tree
722722
--
723723

724-
set effective_cache_size = '128MB';
725-
726724
explain (costs off)
727725
select * from tenk1 t1 left join
728726
(tenk1 t2 join tenk1 t3 on t2.thousand = t3.unique2)

0 commit comments

Comments
 (0)