Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91728fa

Browse files
committed
Add temp_buffers GUC variable to allow users to determine the size
of the local buffer arena for temporary table access.
1 parentd65522a commit91728fa

File tree

8 files changed

+89
-28
lines changed

8 files changed

+89
-28
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.309 2005/03/14 06:49:48 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.310 2005/03/19 23:27:04 tgl Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -1038,6 +1038,33 @@ SET ENABLE_SEQSCAN TO OFF;
10381038
</listitem>
10391039
</varlistentry>
10401040

1041+
<varlistentry id="guc-temp-buffers" xreflabel="temp_buffers">
1042+
<term><varname>temp_buffers</varname> (<type>integer</type>)</term>
1043+
<indexterm>
1044+
<primary><varname>temp_buffers</> configuration parameter</primary>
1045+
</indexterm>
1046+
<listitem>
1047+
<para>
1048+
Sets the maximum number of temporary buffers used by each database
1049+
session. These are session-local buffers used only for access
1050+
to temporary tables. The default is 1000. The setting can
1051+
be changed within individual sessions, but only up until the
1052+
first use of temporary tables within a session; subsequent
1053+
attempts to change the value will have no effect on that session.
1054+
</para>
1055+
1056+
<para>
1057+
A session will allocate temporary buffers as needed up to the limit
1058+
given by <varname>temp_buffers</>. The cost of setting a large
1059+
value in sessions that do not actually need a lot of temporary
1060+
buffers is only a buffer descriptor, or about 64 bytes, per
1061+
increment in <varname>temp_buffers</>. However if a buffer is
1062+
actually used an additional 8192 bytes will be consumed for it
1063+
(or in general <symbol>BLCKSZ</symbol> bytes).
1064+
</para>
1065+
</listitem>
1066+
</varlistentry>
1067+
10411068
<varlistentry id="guc-work-mem" xreflabel="work_mem">
10421069
<term><varname>work_mem</varname> (<type>integer</type>)</term>
10431070
<indexterm>

‎src/backend/storage/buffer/localbuf.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.65 2005/03/1917:39:43 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.66 2005/03/1923:27:05 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -18,6 +18,7 @@
1818
#include"storage/buf_internals.h"
1919
#include"storage/bufmgr.h"
2020
#include"storage/smgr.h"
21+
#include"utils/guc.h"
2122
#include"utils/memutils.h"
2223
#include"utils/resowner.h"
2324

@@ -46,6 +47,9 @@ static intnextFreeLocalBuf = 0;
4647
staticHTAB*LocalBufHash=NULL;
4748

4849

50+
staticvoidInitLocalBuffers(void);
51+
52+
4953
/*
5054
* LocalBufferAlloc -
5155
* Find or create a local buffer for the given page of the given relation.
@@ -66,6 +70,10 @@ LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
6670

6771
INIT_BUFFERTAG(newTag,reln,blockNum);
6872

73+
/* Initialize local buffers if first request in this session */
74+
if (LocalBufHash==NULL)
75+
InitLocalBuffers();
76+
6977
/* See if the desired buffer already exists */
7078
hresult= (LocalBufferLookupEnt*)
7179
hash_search(LocalBufHash, (void*)&newTag,HASH_FIND,NULL);
@@ -238,32 +246,18 @@ WriteLocalBuffer(Buffer buffer, bool release)
238246
}
239247

240248
/*
241-
*InitLocalBuffer -
249+
*InitLocalBuffers -
242250
* init the local buffer cache. Since most queries (esp. multi-user ones)
243251
* don't involve local buffers, we delay allocating actual memory for the
244252
* buffers until we need them; just make the buffer headers here.
245253
*/
246-
void
247-
InitLocalBuffer(void)
254+
staticvoid
255+
InitLocalBuffers(void)
248256
{
249-
intnbufs=64;/* should be from a GUC var */
257+
intnbufs=num_temp_buffers;
250258
HASHCTLinfo;
251259
inti;
252260

253-
/* Create the lookup hash table */
254-
MemSet(&info,0,sizeof(info));
255-
info.keysize=sizeof(BufferTag);
256-
info.entrysize=sizeof(LocalBufferLookupEnt);
257-
info.hash=tag_hash;
258-
259-
LocalBufHash=hash_create("Local Buffer Lookup Table",
260-
nbufs,
261-
&info,
262-
HASH_ELEM |HASH_FUNCTION);
263-
264-
if (!LocalBufHash)
265-
elog(ERROR,"could not initialize local buffer hash table");
266-
267261
/* Allocate and zero buffer headers and auxiliary arrays */
268262
LocalBufferDescriptors= (BufferDesc*)
269263
MemoryContextAllocZero(TopMemoryContext,
@@ -291,6 +285,20 @@ InitLocalBuffer(void)
291285
buf->buf_id=-i-2;
292286
}
293287

288+
/* Create the lookup hash table */
289+
MemSet(&info,0,sizeof(info));
290+
info.keysize=sizeof(BufferTag);
291+
info.entrysize=sizeof(LocalBufferLookupEnt);
292+
info.hash=tag_hash;
293+
294+
LocalBufHash=hash_create("Local Buffer Lookup Table",
295+
nbufs,
296+
&info,
297+
HASH_ELEM |HASH_FUNCTION);
298+
299+
if (!LocalBufHash)
300+
elog(ERROR,"could not initialize local buffer hash table");
301+
294302
/* Initialization done, mark buffers allocated */
295303
NLocBuffer=nbufs;
296304
}

‎src/backend/utils/init/postinit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.143 2005/03/18 16:16:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.144 2005/03/19 23:27:06 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -257,7 +257,6 @@ BaseInit(void)
257257
/* Do local initialization of storage and buffer managers */
258258
smgrinit();
259259
InitBufferPoolAccess();
260-
InitLocalBuffer();
261260
}
262261

263262

‎src/backend/utils/misc/guc.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.255 2005/03/13 09:36:31 neilc Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.256 2005/03/19 23:27:07 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -104,6 +104,7 @@ static const char *assign_log_error_verbosity(const char *newval, bool doit,
104104
GucSourcesource);
105105
staticconstchar*assign_log_statement(constchar*newval,booldoit,
106106
GucSourcesource);
107+
staticconstchar*show_num_temp_buffers(void);
107108
staticboolassign_phony_autocommit(boolnewval,booldoit,GucSourcesource);
108109
staticconstchar*assign_custom_variable_classes(constchar*newval,booldoit,
109110
GucSourcesource);
@@ -144,9 +145,10 @@ booldefault_with_oids = false;
144145
intlog_min_error_statement=PANIC;
145146
intlog_min_messages=NOTICE;
146147
intclient_min_messages=NOTICE;
147-
148148
intlog_min_duration_statement=-1;
149149

150+
intnum_temp_buffers=1000;
151+
150152
char*ConfigFileName;
151153
char*HbaFileName;
152154
char*IdentFileName;
@@ -966,6 +968,15 @@ static struct config_int ConfigureNamesInt[] =
966968
1000,16,INT_MAX /BLCKSZ,NULL,NULL
967969
},
968970

971+
{
972+
{"temp_buffers",PGC_USERSET,RESOURCES_MEM,
973+
gettext_noop("Sets the maximum number of temporary buffers used by each session."),
974+
NULL
975+
},
976+
&num_temp_buffers,
977+
1000,100,INT_MAX /BLCKSZ,NULL,show_num_temp_buffers
978+
},
979+
969980
{
970981
{"port",PGC_POSTMASTER,CONN_AUTH_SETTINGS,
971982
gettext_noop("Sets the TCP port the server listens on."),
@@ -5496,6 +5507,19 @@ assign_log_statement(const char *newval, bool doit, GucSource source)
54965507
returnnewval;/* OK */
54975508
}
54985509

5510+
staticconstchar*
5511+
show_num_temp_buffers(void)
5512+
{
5513+
/*
5514+
* We show the GUC var until local buffers have been initialized,
5515+
* and NLocBuffer afterwards.
5516+
*/
5517+
staticcharnbuf[32];
5518+
5519+
sprintf(nbuf,"%d",NLocBuffer ?NLocBuffer :num_temp_buffers);
5520+
returnnbuf;
5521+
}
5522+
54995523
staticbool
55005524
assign_phony_autocommit(boolnewval,booldoit,GucSourcesource)
55015525
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
# - Memory -
7575

7676
#shared_buffers = 1000# min 16, at least max_connections*2, 8KB each
77+
#temp_buffers = 1000# min 100, 8KB each
7778
#work_mem = 1024# min 64, size in KB
7879
#maintenance_work_mem = 16384# min 1024, size in KB
7980
#max_stack_depth = 2048# min 100, size in KB

‎src/bin/psql/tab-complete.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.121 2005/01/23 15:58:50 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/tab-complete.c,v 1.122 2005/03/19 23:27:08 tgl Exp $
77
*/
88

99
/*----------------------------------------------------------------------
@@ -594,6 +594,7 @@ psql_completion(char *text, int start, int end)
594594
"superuser_reserved_connections",
595595
"syslog_facility",
596596
"syslog_ident",
597+
"temp_buffers",
597598
"TimeZone",
598599
"trace_notify",
599600
"transform_null_equals",

‎src/include/storage/bufmgr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.91 2005/03/18 16:16:09 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/bufmgr.h,v 1.92 2005/03/19 23:27:10 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -157,7 +157,6 @@ extern void BufmgrCommit(void);
157157
externvoidBufferSync(void);
158158
externvoidBgBufferSync(void);
159159

160-
externvoidInitLocalBuffer(void);
161160
externvoidAtProcExit_LocalBuffers(void);
162161

163162
/* in freelist.c */

‎src/include/utils/guc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
88
* Written by Peter Eisentraut <peter_e@gmx.net>.
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.58 2005/01/01 05:43:09 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/guc.h,v 1.59 2005/03/19 23:27:11 tgl Exp $
1111
*--------------------------------------------------------------------
1212
*/
1313
#ifndefGUC_H
@@ -126,6 +126,8 @@ extern intlog_min_messages;
126126
externintclient_min_messages;
127127
externintlog_min_duration_statement;
128128

129+
externintnum_temp_buffers;
130+
129131
externchar*ConfigFileName;
130132
externchar*HbaFileName;
131133
externchar*IdentFileName;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp