Linux command
vacuumdb 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Vacuum a database
vacuumdb [database]
Vacuum all databases
vacuumdb --all
Vacuum and update optimizer statistics
vacuumdb --analyze [database]
Full vacuum
vacuumdb --full [database]
Vacuum a specific table
vacuumdb -t [table_name] [database]
Run vacuum in parallel
vacuumdb -j [4] [database]
Freeze tuples aggressively
vacuumdb --freeze [database]
Only update statistics
vacuumdb --analyze-only [database]
Vacuum on a remote server
vacuumdb -h [hostname] -p [5432] -U [username] [database]
说明
vacuumdb cleans and analyzes PostgreSQL databases. It is a wrapper around the SQL VACUUM and ANALYZE commands, providing convenient options for scripting and cron jobs. Regular vacuum marks dead tuples for reuse. It doesn't reclaim disk space but prevents table bloat from growing indefinitely. Full vacuum rewrites tables, reclaiming disk space. It requires an exclusive lock on the table and more time than regular vacuum. Analyze updates statistics used by the query planner. Accurate statistics lead to better query plans and performance. Parallel vacuuming with -j processes multiple tables simultaneously. The -P option controls the number of parallel workers within each vacuum operation.
参数
- -a, --all
- Vacuum all databases.
- -d _DBNAME_, --dbname _DBNAME_
- Database to clean or analyze.
- -z, --analyze
- Also calculate statistics for use by the optimizer.
- -Z, --analyze-only
- Only calculate statistics, do not vacuum.
- --analyze-in-stages
- Analyze in three stages with increasing statistics targets. Useful for databases with no or wholly incorrect statistics.
- -f, --full
- Perform full vacuuming (rewrites tables, reclaims disk space).
- -F, --freeze
- Aggressively freeze tuples to prevent transaction ID wraparound.
- -t _TABLE_, --table _TABLE_
- Vacuum specific table only. Can be specified multiple times.
- -n _SCHEMA_, --schema _SCHEMA_
- Clean or analyze all tables in the specified schema only. Can be specified multiple times.
- -N _SCHEMA_, --exclude-schema _SCHEMA_
- Exclude tables in the specified schema.
- -j _N_, --jobs _N_
- Run vacuum or analyze commands in parallel by running N jobs simultaneously.
- -P _N_, --parallel _N_
- Specify the number of parallel workers for each vacuum operation.
- --skip-locked
- Skip relations that cannot be immediately locked for processing.
- --no-index-cleanup
- Do not remove index entries pointing to dead tuples.
- --no-truncate
- Do not truncate empty pages at the end of the table.
- --disable-page-skipping
- Disable skipping pages based on the visibility map.
- --min-xid-age _AGE_
- Only process tables with a transaction ID age of at least AGE.
- --min-mxid-age _AGE_
- Only process tables with a multixact ID age of at least AGE.
- -e, --echo
- Echo the commands sent to the server.
- -q, --quiet
- Do not display progress messages.
- -v, --verbose
- Print detailed information during processing.
- -h _HOST_, --host _HOST_
- Database server host.
- -p _PORT_, --port _PORT_
- Server port.
- -U _USER_, --username _USER_
- Username to connect as.
FAQ
What is the vacuumdb command used for?
vacuumdb cleans and analyzes PostgreSQL databases. It is a wrapper around the SQL VACUUM and ANALYZE commands, providing convenient options for scripting and cron jobs. Regular vacuum marks dead tuples for reuse. It doesn't reclaim disk space but prevents table bloat from growing indefinitely. Full vacuum rewrites tables, reclaiming disk space. It requires an exclusive lock on the table and more time than regular vacuum. Analyze updates statistics used by the query planner. Accurate statistics lead to better query plans and performance. Parallel vacuuming with -j processes multiple tables simultaneously. The -P option controls the number of parallel workers within each vacuum operation.
How do I run a basic vacuumdb example?
Run `vacuumdb [database]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -a, --all do in vacuumdb?
Vacuum all databases.