2010-05-22 50 views
4

我正在使用pg_buffercache模塊來查找耗盡我的RAM緩存的大量模塊。該sample_table使用120個緩衝器PostgreSQL中的「緩衝區」有多大?

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; 

我發現:例如,當我運行此查詢。

120個緩衝區的字節數是多少?

回答

1

PostgreSQL的硬編碼塊大小爲字節 - 請參閱pre-defined block_size variable。當您編輯配置以指定shared_buffers等時,此過去一直是一個數字,但配置現在支持後綴,如MB,它將爲您完成轉換。

有可能,辛勤工作,將block_size更改爲其他值。對於少數應用程序,可能會有更優化的大小,但代碼對大小進行假設的位數很大。

+1

謝謝。是否shared_buffers = 2 GB意味着我有2 * 2^10^3/8192 = 262144個緩衝區? – 2010-05-22 08:31:00

+0

是!這在運行pg_buffer_cache時當然會導致性能問題,因爲它太多了。但是如果2GB是PG羣集的最佳緩存大小,那麼這是一個小的代價。 – Edmund 2010-05-22 09:27:04

0

根據什麼愛德蒙說,我們可以在我們的方案數據庫這個選擇:

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;