1.Base基础/3.Icon图标/操作/search备份
1.Base基础/3.Icon图标/操作/search备份
EN
文档
关于AntDB
部署与升级
快速入门
使用教程
运维
调优
工具和插件
高级服务
数据安全
参考
  • 文档首页 /
  • 工具和插件 /
  • 集中式 /
  • pg_repack

pg_repack

更新时间:2024-07-01 14:39:41

pg_repack 插件描述

pg_repack 是一个 AntDB 扩展,能够在线清理表空间,有效解决因对全表大量更新等操作引起的表膨胀问题。

注意:

  • 只有超级用户才能使用这个扩展。
  • 目标 table 必须要有 PRIMARY KEY,或者至少在 NOT NULL 列上具有 UNIQUE 总索引。

使用准备

  • 修改配置文件后重启数据库
# 修改postgresql.conf文件
shared_preload_libraries = 'pg_repack'
  • 登陆数据库,执行 SQL 命令,创建扩展
CREATE EXTENSION pg_repack;

使用方法

pg_repack [OPTION]... [DBNAME]

选项:

Options:
  -a, --all                 repack all databases
  -t, --table=TABLE         repack specific table only
  -I, --parent-table=TABLE  repack specific parent table and its inheritors
  -c, --schema=SCHEMA       repack tables in specific schema only
  -s, --tablespace=TBLSPC   move repacked tables to a new tablespace
  -S, --moveidx             move repacked indexes to TBLSPC too
  -o, --order-by=COLUMNS    order by columns instead of cluster keys
  -n, --no-order            do vacuum full instead of cluster
  -N, --dry-run             print what would have been repacked
  -j, --jobs=NUM            Use this many parallel jobs for each table
  -i, --index=INDEX         move only the specified index
  -x, --only-indexes        move only indexes of the specified table
  -T, --wait-timeout=SECS   timeout to cancel other backends on conflict
  -D, --no-kill-backend     don't kill other backends when timed out
  -Z, --no-analyze          don't analyze at end
  -k, --no-superuser-check  skip superuser checks in client
  -C, --exclude-extension   don't repack tables which belong to specific extension

Connection options:
  -d, --dbname=DBNAME       database to connect
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt

Generic options:
  -e, --echo                echo queries
  -E, --elevel=LEVEL        set output message level
  --help                    show this help, then exit
  --version                 output version information, then exit

选项说明:

-a, --all
尝试repack集群的所有数据库。将跳过未安装pg_repack扩展的数据库。

-t TABLE, --table=TABLE
仅作用于指定的表。可以通过使用-t来指定多个表。默认情况下,将作用于目标数据库中所有符合条件的表。

-I TABLE, --parent-table=TABLE
指定表及其继承者。可以通过使用多个-I来指定多个表层次结构。

-c, --schema
仅作用于指定schema中的表。可以使用多个-c指定多个schema。可以与--tablespace结合使用,将表移动到不同的表空间。

-o COLUMNS [,...], --order-by=COLUMNS [,...]
按照指定的列执行联机CLUSTER。

-n, --no-order
执行在线VACUUM FULL。这是non-clustered表哥的默认设置。

-N, --dry-run
列出要repacked的内容并退出。

-j, --jobs
创建指定数量的到PostgreSQL的额外连接,并使用这些额外连接并行重建每个表上的索引。并行索引构建仅支持完整表的repack,而不支持--index或--only indexes选项。如果您的服务器有额外的核心和可用的磁盘I/O,这可能是加快pg_repack速度的一种有用方法。

-s TBLSPC, --tablespace=TBLSPC
Move the repacked tables to the specified tablespace: essentially an online version of ALTER TABLE ... SET TABLESPACE. The tables' indexes are left in the original tablespace unless --moveidx is specified too.
将repacked的表移动到指定的表空间:本质上是ALTER TABLE ... SET TABLESPACE的联机版本。除非也指定了--moveidx,否则表的索引将保留在原始表空间中。

-S, --moveidx
将repacked的表的索引移动到--tablespace选项指定的表空间。

-i, --index
仅repack指定的索引。可以通过设置多个-i开关来指定多个索引。可以与--tablespace结合使用,将索引移动到不同的表空间。

-x, --only-indexes
只repack指定表的索引,这些表必须使用--table或--parent表选项指定。

-T SECS, --wait-timeout=SECS
pg_repack需要在回收结束时获取一个独占锁。此设置控制pg_repack获取此锁将等待的秒数。如果在此持续时间之后无法获取锁,并且未指定--no kill后端选项,则pg_repack将强制取消冲突的查询。

-D, --no-kill-backend
Skip to repack table if the lock cannot be taken for duration specified --wait-timeout, instead of cancelling conflicting queries. The default is false.
如果在--wait-timeout指定的持续时间内无法获取锁,则跳过repack table,而不是取消冲突的查询。默认值为false。

-Z, --no-analyze
在对full-table资源回收后禁用ANALYZE。如果未指定,请在资源回收后运行ANALYZE。

-k, --no-superuser-check
跳过客户端中的超级用户检查。此设置对于在支持以非超级用户身份运行pg_repack的平台上使用它非常有用。

-C, --exclude-extension
跳过属于指定扩展名的表。一些扩展可能在规划时严重依赖于此类表等。



连接选项:
连接到服务器的选项。不能同时使用--all和--dbname或--table或--parent-table。

-a, --all
指定所有database

-d DBNAME, --dbname=DBNAME
指定要资源回收的的数据库的名称。如果未指定此项并且未使用-a(或-all),则从环境变量PGDATABASE中读取数据库名称。如果未设置,则使用为连接指定的用户名。

-h HOSTNAME, --host=HOSTNAME
Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket.
指定运行服务器的机器的主机名。如果这个值由一个斜线开始,它会被用作 Unix 域套接字的目录。

-p PORT, --port=PORT
指定服务器用于监听连接的 TCP 端口或者本地 Unix 域套接字文件扩展。默认是PGPORT环境变量的值。

-U USERNAME, --username=USERNAME
指定连接用户名

-w, --no-password
从不发出一个口令提示。如果服务器要求口令认证并且口令不能从其他来源(例如一个.pgpass文件)获得,那么连接尝试将失败。这个选项对于批处理任务和脚本有用,因为在其中没有一个用户来输入口令。

-W, --password
强制psql在连接到一个数据库之前提示要求一个口令,即使口令不会被使用。
这个选项从来都不是必需的,因为如果服务器要求进行密码身份验证,程序会自动提示输入密码。但是,pg_repack将浪费一次连接尝试来发现服务器需要密码。在某些情况下,键入-W以避免额外的连接尝试是值得的。


常规选项:
-e, --echo
回显发送到服务器的命令。

-E LEVEL, --elevel=LEVEL
从DEBUG、INFO、NOTICE、WARNING、ERROR、LOG、FATAL和PANIC中选择输出消息级别。默认值为INFO。

--help
显示关于pg_repack命令行参数的帮助并退出。

--version
显示pg_repack的版本信息。
问题反馈