Postgresql – How to reset the counters from pg_stat_database view

postgresqlpostgresql-9.3statistics

I know I can reset some counters by running:

select pg_stat_reset()

but some counters like xact_commit aren't reset.

How can I do it?

I've tried also:

pg_stat_reset_shared('database')

but doesn't work. 🙁

Any ideas, please?

I could store the last counters and substract for the next time.

Best Answer

The solution is simple, store previous values and substract. No need to reset anything in Postgres. In this way meaningful stats can be obtained:

(newValue-oldValue)/numberOfSeconds