High Performance PostgreSQL for Rails: How to show autovacuum_vacuum_scale_factor per table (p. 171)

@andatki

On page 171, it shows how to change the autovacuum scale factor for a particular table, eg:

ALTER TABLE trips SET (autovacuum_vacuum_scale_factor = 0.01);

It’s also possible to show from in a psql console what the global value is for the scale factor:

SHOW autovacuum_vacuum_scale_factor;

My question is: How to show the table-specific values? i.e. suppose someone else has gone in and updated this for various tables, and you just want to know what all the current values are before making further changes?

1 Like

Hey Daniela! Good question. I’m adding a query (thanks ChatGPT) you can run on your DB to find this information. We can query the pg_class system catalog to get it. To test this, I set the AV scale factor using the command you listed and made sure the expected option name and value appeared in the result.

Because this seems generally useful, I’ve added this query to my pg_scrips repository on GitHub. There’s also a commented out section showing the result when run on my local Rideshare DB.

https://github.com/andyatkinson/pg_scripts/blob/main/per_table_options_reloptions_all_regular_tables.sql

Besides querying this information, another tactic could be adding these changes to your local dev DB, since they’re dumped into the db/structure.sql.

Here’s a snippet below where Autovacuum was disabled for a table, showing the line it adds to db/structure.sql.

While this AV change wouldn’t likely wouldn’t be necessary locally, documenting a change like this in the db/structure.sql could be helpful on a team of people interested in this info.

“+WITH (autovacuum_enabled='false');”

Hope that helps!

That query is helpful, thanks for adding it!