idspgmaint
Run idspgmaint to maintain the ISVD PostgreSQL database.
Description
- Requires privileges to VACUUM/ANALYZE/REINDEX the target objects (plus permission to alter DB connect/limit when doing FULL).
- Designed for PostgreSQL 14 and later versions.
- It counts with progress views feature.
- For VACUUM FULL, the idspgmaint utility enters an "exclusive DB mode". It keeps 1 persistent connection, blocks new connections, terminates others, and runs all FULL tasks in that same session.
- Bloat heuristic:
- Runs VACUUM FULL only for tables whose bloat exceeds the threshold (defaults to 20% if you pass --full-only-on-bloat[=N] without a value).
- Prefers pgstattuple_approx if the pgstattuple extension is installed.
- It uses the pgstattuple extension for a fast and more accurate estimate of dead tuples.
- Else falls back to a dead-tuple ratio using pg_stat_all_tables.
- Decision Tree for VACUUM Usage:
- Here’s a simplified decision tree

Key points:
- VACUUM: Use for routine cleanup; safe online.
- ANALYZE: Use when data distribution changes significantly.
- VACUUM FULL: Use only when reclaiming OS disk space or after heavy bloat; requires downtime.
Usage
- Connection:
-
-d <database>, -U <user>, -h <host>, -p <port>(will use 'idsldap', $PGUSER, $PGHOST, $PGPORT respectively if they are not supplied)
- Selection:
-
-n [,schema...] -t [,table...](if neither -n nor -t is supplied => all user schemas/tables)
--exclude [,table...]Exclude table(s) by name or glob pattern (*, ?). It accepts schema-qualified (schema.table) or unqualified. Can be repeated.
- Logging policy:
-
-l <log-dir> | --log-dir <log-dir>Log directory (overrides the default)
Default log-dir: /var/isvd/data/logs/pgmaint_logger/
If the specified directory is unusable, the system warns and falls back to the default directory.
If the default directory is also unusable, the system warns again and falls back to writing to stdout-only.
--require-log-dirFail only if both the specified
--log-dir(if any) and the defaultlog-dirare unusable. In that case, do not fall back to stdout-only - Autovacuum conflict policy:
-
--autovacuum-conflict {wait|cancel|skip|ignore}Default policy = cancel (escalates to terminate after timeout)
--autovacuum-timeoutMax time to wait for workers to stop; with policy=cancel (overrides the default 600)
--autovacuum-show-settingsShow autovacuum GUCs and per-table reloptions (optional diagnostics in pre-check)
- -Vacuum/Analyze:
--fullForce VACUUM FULL on all targeted tables. For safety, it blocks new connections (REVOKE CONNECTIONS), terminates other sessions, and runs FULL
--full-only-on-bloat[=N]VACUUM FULL only if bloat >= N% (default 20 when flag passed w/o value)
--analyzeANALYZE after vacuum/full
--analyze-onlyOnly ANALYZE (no VACUUM)
- REINDEX:
-
--reindexRun REINDEX after maintenance (or with --analyze-only)
--reindex-concurrentlyUse REINDEX CONCURRENTLY (lower locking, longer runtime)
--reindex-only-on-bloat[=N]REINDEX only when BTREE index-bloat >= N% (default 20). Uses
pgstatindex()ifpgstattupleis available; else a catalog-based fallback estimator (no extensions). - Progress:
-
--watchShow live progress for VACUUM Online and REINDEX
--watch-quietShow more concise progress (implies --watch)
--watch-interval <sec>Poll interval (default: 15)
- Planning:
-
--dry-runPreview actions, plan ONLY (no changes). It still connects read-only to enumerate/estimate.
- Other:
-V, --versionPrint the
idspgmaintutility version and last updated date, then exit.-H, --helpShow the usage of the idspgmaint utility and its help options.
- Examples:
- For example, maintenance was required on the
ibmentryuuid,ldap_desc,ldap_entry,objectclass, andtitletables in theidsldapschema. Thetitletable was excluded because its maintenance was less urgent.
- Example 1:
- To ensure the reported tables truly require maintenance, we will utilize the only-on-bloat options. Always run
--dry-runfirst to test in staging and confirm the plan first.$ idspgmaint -n idsldap -t ibmentryuuid,ldap_desc,ldap_entry,objectclass,title --exclude idsldap.title --full-only-on-bloat --reindex-only-on-bloat --dry-run
- Example 2:
-
After checking and confirming the
--dry-runplan, execute it, watching the progress with the default every 15 seconds.$ idspgmaint -n idsldap -t ibmentryuuid,ldap_desc,ldap_entry,objectclass,title --exclude idsldap.title --full-only-on-bloat --reindex-only-on-bloat –watch - Example 3:
- Choose a different destination path for the recorded log, and use --require-log-dir if logs are mandatory for compliance.
$ idspgmaint -n idsldap -t ibmentryuuid,ldap_desc,ldap_entry,objectclass,title --exclude idsldap.title -l /var/isvd/logs --require-log-dir --full-only-on-bloat --reindex-only-on-bloat –watch - Example 4:
- After
VACUUMandREINDEX, it is always advisable to runANALYZElast.$ idspgmaint -n idsldap -t ibmentryuuid,ldap_desc,ldap_entry,objectclass,title --exclude idsldap.title --analyze-only --watch - Example 5:
- When downtime is unacceptable, avoid
VACUUM FULLand perform an onlineVACUUMfollowed byANALYZE.$ idspgmaint -n idsldap -t ibmentryuuid,ldap_desc,ldap_entry,objectclass,title --exclude idsldap.title --analyze –watch
If you use the --reindex-only-on-bloat option and the pgstattuple extension is not installed, you may need to adjust the reindex bloat estimate. Otherwise, the idspgmaint utility can indicate that a table requires reindexing even after it has already been reindexed. To adjust the reindex bloat estimate, use the following environment variables:
- REINDEX_MIN_INDEX_PAGES:
-
- Default value is '8'.
- Skip tables whose largest index < 8 pages (64kB).
- REINDEX_MIN_SAVED_PAGES:
-
- Default is '3'.
- Require at least 3 pages (24kB) of potential savings.
- REINDEX_TINY_INDEX_PAGES_MAX:
-
- Treat indexes with total pages
<= <int>as "tiny". Default: 2 (root + 1 leaf). - Tiny indexes are treated as 0.00% bloat (and 0 saved pages).
- Treat indexes with total pages
- REINDEX_DAMP_MODE:
-
- Default value is 'product'.
- From more to less aggressive damping ordered mode:
power|product|min|division|max|none - Value 'none' won't adjust raw
bloat_pctobtained without'pgstattuple'.
- REINDEX_DAMP_GAMMA:
-
- Default value is '2.0'.
- Exponent for 'power' mode (>=1.0). Exponent 1.0 aggressiveness ≈ 'min' mode.
- Exponent 2.0 aggressiveness ≈ 'product' mode. Exponent greater than 2.0 aggressiveness > 'product' mode.