關於您的第一點,contrib模塊「pg_buffercache」允許您檢查緩衝區緩存的內容。我喜歡這樣定義:
create or replace view util.buffercache_hogs as
select case
when pg_buffercache.reldatabase = 0
then '- global'
when pg_buffercache.reldatabase <> (select pg_database.oid from pg_database where pg_database.datname = current_database())
then '- database ' || quote_literal(pg_database.datname)
when pg_namespace.nspname = 'pg_catalog'
then '- system catalogues'
when pg_class.oid is null and pg_buffercache.relfilenode > 0
then '- unknown file ' || pg_buffercache.relfilenode
when pg_namespace.nspname = 'pg_toast' and pg_class.relname ~ '^pg_toast_[0-9]+$'
then (substring(pg_class.relname, 10)::oid)::regclass || ' TOAST'::text
when pg_namespace.nspname = 'pg_toast' and pg_class.relname ~ '^pg_toast_[0-9]+_index$'
then ((rtrim(substring(pg_class.relname, 10), '_index'))::oid)::regclass || ' TOAST index'
else pg_class.oid::regclass::text
end as key,
count(*) as buffers, sum(case when pg_buffercache.isdirty then 1 else 0 end) as dirty_buffers,
round(count(*)/(SELECT pg_settings.setting FROM pg_settings WHERE pg_settings.name = 'shared_buffers')::numeric, 4) as hog_factor
from pg_buffercache
left join pg_database on pg_database.oid = pg_buffercache.reldatabase
left join pg_class on pg_class.relfilenode = pg_buffercache.relfilenode
left join pg_namespace on pg_namespace.oid = pg_class.relnamespace
group by 1
order by 2 desc;
此外,「pageinspect」的contrib模塊,使您可以從一個關係訪問特定頁面,所以我想你可以簡單地通過關係中的所有頁面循環抓住他們呢?
select count(get_raw_page('information_schema.sql_features', n))
from generate_series(0,
(select relpages-1 from pg_class where relname = 'sql_features')) n;
這會將所有information_schema.sql_features
加載到緩存中。
問題是我無法猜測用戶的查詢,認爲「亞馬遜」 - 接下來的10000個查詢會是什麼?所以我會喜歡運行一些將特定表和索引拖入緩存的東西。 – 2009-06-01 12:55:16
不要猜測。從最近5分鐘或最近10'000個查詢中獲取實際日誌。我曾在「一家領先的搜索引擎提供商」工作,這很好。 或者,如果您的服務器已啓動並正在運行,並且您想預熱新服務器,則可以將查詢鏡像到要預熱的服務器。 – Thomas 2009-06-01 19:59:52