我正在使用pg_buffercache
模块查找占用RAM缓存的生猪。例如,当我运行此查询时:
SELECT c.relname, count(*) AS buffers
FROM pg_buffercache b INNER JOIN pg_class c
ON b.relfilenode = c.relfilenode AND
b.reldatabase IN (0, (SELECT oid FROM pg_database WHERE datname = current_database()))
GROUP BY c.relname
ORDER BY 2 DESC
LIMIT 10;
我发现sample_table
正在使用120个缓冲区。
120个缓冲区的字节数是多少?
答案 0 :(得分:1)
PostgreSQL的硬编码块大小为 8192 字节 - 请参阅pre-defined block_size variable。这曾经是编辑配置以指定shared_buffers
等时要记住的数字,但配置现在支持MB
之类的后缀,它将为您进行转换。
通过努力工作,可以将block_size更改为其他值。对于少数应用程序,可能存在更优化的大小,但代码对大小进行假设的位置数量很大。
答案 1 :(得分:0)
根据Edmund的说法,我们可以在我们的方案数据库中进行选择:
SELECT c.relname,
Pg_size_pretty(Count(*) * 8192)
AS buffered,
Round(100.0 * Count(*) / (SELECT setting
FROM pg_settings
WHERE name = 'shared_buffers') :: INTEGER, 1)
AS
buffers_percent,
Round(100.0 * Count(*) * 8192 / Pg_relation_size(c.oid), 1)
AS
percent_of_relation
FROM pg_class c
INNER JOIN pg_buffercache b
ON b.relfilenode = c.relfilenode
INNER JOIN pg_database d
ON ( b.reldatabase = d.oid
AND d.datname = Current_database() )
WHERE Pg_relation_size(c.oid) > 0
GROUP BY c.oid,
c.relname
ORDER BY 3 DESC
LIMIT 10;