pg_catalog.pg_statio_all_tables arkadaşınız. Tek yapmanız gereken söz konusu tablolar için periyodik olarak pg_statio_all_tables anketidir. Değişen istatistikler ~ aktif tablo, değişmeyen istatistikler ~ potansiyel olarak kullanılmayan tablo. Sadece kimsenin select pg_stat_reset () ;izlemenizin ortasında bir şey yapmamasına dikkat edin .
Örneğin:
test_1=# create table test_stats (col1 integer);
CREATE TABLE
test_1=# select * from pg_catalog.pg_statio_all_tables
where schemaname not in ('pg_catalog', 'information_schema')
and relname = 'test_stats';
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
22957 | public | test_stats | 0 | 0 | [null] | [null] | [null] | [null] | [null] | [null]
(1 row)
ekler:
test_1=# insert into test_stats (col1) select generate_series( 1, 10000000);
INSERT 0 10000000
test_1=# select * from pg_catalog.pg_statio_all_tables
where schemaname not in ('pg_catalog', 'information_schema')
and relname = 'test_stats';
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
22957 | public | test_stats | 44260 | 10088481 | [null] | [null] | [null] | [null] | [null] | [null]
(1 row)
seçer:
test_1=# select count (*) from test_stats where col1 between 10000 and 50000;
count
-------
40001
(1 row)
test_1=# select * from pg_catalog.pg_statio_all_tables
where schemaname not in ('pg_catalog', 'information_schema')
and relname = 'test_stats';
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
22957 | public | test_stats | 85560 | 10091429 | [null] | [null] | [null] | [null] | [null] | [null]
(1 row)
Silinme:
test_1=# delete from test_stats where col1 between 10000 and 50000;
DELETE 40001
test_1=# select * from pg_catalog.pg_statio_all_tables
where schemaname not in ('pg_catalog', 'information_schema')
and relname = 'test_stats';
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+------------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
22957 | public | test_stats | 155075 | 10136163 | [null] | [null] | [null] | [null] | [null] | [null]
(1 row)
güncelleme-- 2011-09-01
Sonraki testler vacuum, pg_statio_all_tables içindeki değerleri bir şekilde arttırdığını gösteriyor ki bu da istediğiniz kullanım için talihsiz bir durum. İken vacuumpg_statio_all_tables kullanımını yararsız yapmaz, biraz fuzzier sonuçlarını yorumlama yapar.
Belki de izlenecek daha iyi bir yer pg_catalog.pg_stat_all_tables (en azından Pg'nin daha yeni sürümlerinde). Sürüm 8.4'e bakıyorum ve eklenen, okunan, güncellenen ve silinen tuples için sayıları var - ISTR 8.2 tüm bunlara sahip değil ve bu yüzden Pg sürümüne bağlı olarak 8.3 kadar YMMV bilmiyorum kullanarak.
Üçüncü seçenek (ekleme, güncelleme ve silme etkinliği için) $ PGDATA / base / $ datid dizinindeki dosya zaman damgalarını izlemektir. Dosya adı tablonun oid değeriyle eşleşmelidir; bu nedenle, ekler, güncellemeler veya silinmeyen tabloları tanımlamak için bunu kullanabilirsiniz. Ne yazık ki, bu hala seçilmekte olan tabloları ele almaz ve tablo alanlarını kullanmak ek komplikasyonlara neden olur (çünkü bu dosyalar $ PGDATA / base / $ datid altında olmayacaktır). Zaman damgaları, beklemedeki değişiklikler temizlenene kadar güncellenmez, ancak dosya aylar içinde değişmediyse, şu anda bekleyen bir değişiklik olasılığı muhtemelen düşüktür.
select. Eğer kabul mü günlüğü ?