望达人分析说明下postgre 对内存等其他资源的利用
比如:temp_buffer,wal_buffers
temp_buffers 使用的是 shared_buffers 还是 新开的内存?
temp_buffer和shared_buffers是分开的.
GUC
{
{"temp_buffers", PGC_USERSET, RESOURCES_MEM,
gettext_noop("Sets the maximum number of temporary buffers used by each session."),
NULL,
GUC_UNIT_BLOCKS
},
&num_temp_buffers,
1024, 100, INT_MAX / 2,
check_temp_buffers, NULL, NULL
},
申请代码
/*
* InitLocalBuffers -
* init the local buffer cache. Since most queries (esp. multi-user ones)
* don't involve local buffers, we delay allocating actual memory for the
* buffers until we need them; just make the buffer headers here.
*/
static void
InitLocalBuffers(void)
{
int nbufs = num_temp_buffers;
HASHCTL info;
int i;
/* Allocate and zero buffer headers and auxiliary arrays */
LocalBufferDescriptors = (BufferDesc *) calloc(nbufs, sizeof(BufferDesc));
LocalBufferBlockPointers = (Block *) calloc(nbufs, sizeof(Block));
LocalRefCount = (int32 *) calloc(nbufs, sizeof(int32));
if (!LocalBufferDescriptors || !LocalBufferBlockPointers || !LocalRefCount)
ereport(FATAL,
(errcode(ERRCODE_OUT_OF_MEMORY),
errmsg("out of memory")));
nextFreeLocalBuf = 0;
/* initialize fields that need to start off nonzero */
for (i = 0; i < nbufs; i++)
{
BufferDesc *buf = &LocalBufferDescriptors[i];
/*
* negative to indicate local buffer. This is tricky: shared buffers
* start with 0. We have to start with -2. (Note that the routine
* BufferDescriptorGetBuffer adds 1 to buf_id so our first buffer id
* is -1.)
*/
buf->buf_id = -i - 2;
}
/* Create the lookup hash table */
MemSet(&info, 0, sizeof(info));
info.keysize = sizeof(BufferTag);
info.entrysize = sizeof(LocalBufferLookupEnt);
info.hash = tag_hash;
LocalBufHash = hash_create("Local Buffer Lookup Table",
nbufs,
&info,
HASH_ELEM | HASH_FUNCTION);
if (!LocalBufHash)
elog(ERROR, "could not initialize local buffer hash table");
/* Initialization done, mark buffers allocated */
NLocBuffer = nbufs;
}
十分感谢指教。我们公司也是阿里云用户,哈哈,
@明虚 感谢回复。
shared_buffers 是哪些会用到? 我看了很多网站是建议 物理内存的 1/4 - 1/5,
我不明白具体是什么会用到,设置什么才是会符合我们的业务。
tmp_buffers,也就是pg代码里面的local buffers,各个backend是不需要共享这部分内存的,所以这部分内存是在需要的时候malloc的私有内存,非shared_buffers内存。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。