-
Notifications
You must be signed in to change notification settings - Fork 0
bash script to automate analyze and vacuum analyze
License
commandprompt/pg_refreshstats
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This script executes vacuum analyze or just analyze commands based on input parameters Inputs: all fields are optional except database and type. -h <hostname or IP address> -d <database> -n <schema> -p <PORT> -t <type> -u <db user> -l <load threshold> -w <max rows> -c [vacuum analyze] -r [dry run] -v [verbose output] TYPE values: * EXTENSIVE (all user tables in the database or schema will be refreshed) * SMART (only tables that need to be refreshed will be refreshed) Examples: -- vacuum analyze for all user tables in the database but only if load is less than 20% and rows < 1 mil ./pg_refreshstats.sh -h localhost -d test -p 5433 -t extensive -u postgres -l 20 -w 1000000 -c -v -- smart analyze for all user tables in specific schema, but only if load is less than 40% and rows < 1 mil ./pg_refreshstats.sh -h localhost -d test -n public -p 5433 -t smart -u postgres -l 40 -w 1000000 -v Assumptions: 1. db user defaults to postgres if not provided as parameter. 2. Max rows defaults to 10 million if not provided as parameter 3. Password must be in local .pgpass file or trust/peer client authentication. 4. psql must be in the user's path 5. action defaults to analyze unless option, -c, is specified, indicating to use vacuum analyze instead. 6. Load detection assumes that you are running this script from the database host. 7. SMART type will only consider tables whose pg_class.reltuples value is greater than zero. This value can be zero even if a few rows are in the table, because pg_class.reltuples is also a close estimate. SMART TYPE dictates a filter algorithm to determine what tables will qualify for the stats refresh. 1. Refresh tables with no recent analyze or autovacuum_analyze in the last 30 days. 2. Refresh tables where pg_stat_user_tables.n_live_tup is less than half of pg_class.reltuples Tables with over MAXROWS rows are not refreshed and are output in file, /tmp/PROGRAMPID_refreshstats_deferred.sql, for manual intervention.
About
bash script to automate analyze and vacuum analyze
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published