pg_catalog.pg_statio_all_tables è tuo amico. Tutto ciò che dovresti fare è eseguire periodicamente il polling di pg_statio_all_tables per le tabelle in questione. Modifica delle statistiche ~ tabella attiva, statistiche non modificabili ~ tabella potenzialmente inutilizzata. Fai solo attenzione a nessuno select pg_stat_reset () ;nel mezzo del monitoraggio.
Per esempio:
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)
inserti:
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)
Seleziona:
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)
Elimina:
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)
aggiornamento-- 2011-09-01
Ulteriori test indicano che vacuumsembra aumentare leggermente i valori in pg_statio_all_tables, il che è sfortunato per l'uso desiderato. Sebbene vacuumnon usi inutilmente pg_statio_all_tables, rende l'interpretazione dei risultati un po 'più sfacciata.
Forse un posto migliore da monitorare è pg_catalog.pg_stat_all_tables (almeno con le versioni più recenti di Pg). Sto guardando la versione 8.4 e che ha conteggi per le tuple inserite, lette, aggiornate ed eliminate-- ISTR 8.2 non ha tutto questo e non so di 8.3 quindi YMMV a seconda della versione di Pg che sei utilizzando.
Una terza opzione (per attività di inserimento, aggiornamento ed eliminazione) è quella di guardare i timestamp dei file nella directory $ PGDATA / base / $ datid. Il nome file deve essere mappato sull'oid della tabella, quindi è possibile utilizzarlo per identificare le tabelle che non ottengono inserimenti, aggiornamenti o eliminazioni. Sfortunatamente, questo non affronta le tabelle da cui si sta ancora selezionando, e l'uso di tablespace causerà ulteriori complicazioni (poiché quei file non saranno sotto $ PGDATA / base / $ datid). I timestamp non si aggiorneranno fino a quando non vengono cancellate eventuali modifiche in sospeso, ma se il file non è cambiato da mesi, le probabilità di una modifica attualmente in sospeso sono probabilmente piccole.
select. Hai preso in considerazione la registrazione ?