Monitor Amazon RDS PostgreSQL Table Size with hot_standby_feedback

amazon-rdspostgresql

I have a postgresql Master-Slave replication scheme and because of query cancelation due to conflict with wal I need to set the following setting to each replica:

hot_standby_feedback = on

But because this can cause the tables on my master server to have overly large amounts of data that are about to be deleted but not deleted yet, I need to be able to monitor the table size in order to force manually an autovacumm policy on mergency situations (storage starvation or overprice because of storage size).

Therefore, how do I monitor the table size on my database? Also, how I can enforce the AUTOVACUMM in case of my tables having way too much size.

Best Answer

force manually an autovacumm policy on mergency situations

This is not going to work. hot_standby_feedback doesn't prevent autovacuum from running. It lets it run but prevents it from removing rows that are not "dead enough". No amount of vacuuming is going to help if you don't get the long running queries on the replicas to go away first.

You can use pg_total_relation_size to get the table size. You can take a query like the below, and just plug it into our favorite monitoring solution.

select pg_total_relation_size('pgbench_accounts');

But that still leaves the question of what to do about it.