PG中文社区 /
mdi-home
首页 社区新闻 中文文档 加入ACE {{ item.text }} 登录
mdi-home 首页 mdi-chat-processing 社区新闻 mdi-book-open-variant 中文文档 mdi-account-multiple-check 加入ACE mdi-file-multiple-outline 相关资料 mdi-blank {{item.text}} mdi-exit-to-app 退出账号
PostgreSQL 收缩膨胀表或索引

原作者:digoal/德哥  创作时间:2016-11-21 18:42:42+08  
doudou586 发布于2016-11-21 18:42:42           评论: 3   浏览: 13770   顶: 3423  踩: 3877 

PostgreSQL 收缩膨胀表或索引

作者: digoal

日期: 2016-11-20

标签: PostgreSQL , 膨胀表, 膨胀索引 , pg_reorg, pg_repack , vacuum , 锁冲突


背景

PostgreSQL的表或索引发生膨胀后,用户可以使用vacuum full或rewrite table(如cluster)的方式重建表。

但是vacuum full或者rewrite都需要持有排它锁,会堵塞读操作。

为了减少锁冲突,社区有一个名为pg_reorg或pg_repack的插件,使用了增量的方式重组数据,最后通过切换FILENODE完成数据重组。

仅仅在切换FILENODE时需要持有排他锁,非常短暂,影响比VACUUM FULL和rewrite的方式小多了。

但是pg_reorg或pg_repack都需要建触发器,记录下增量重组时,原表产生的增量数据。 https://github.com/reorg/pg_repack

因此重组时,触发器会带来一定的开销,对被重组的表,有一定的DML性能影响。

本文将要介绍另一个重组插件,名为pg_squeeze,它使用REDO和logical replication实现增量重组,不需要建立触发器,但是要求表上面有PK或者UK。

pg_squeeze的优点

相比pg_repack或pg_reorg,pg_squeeze不需要建触发器,所以在重组时对原表的DML几乎没有性能影响。

pg_squeeze支持自动的重组,即通过设置阈值、比较用户表与阈值,自动启动WORKER进程,将数据复制到重组表,最后加锁,切换FILENODE。
http://www.cybertec.at/en/products/pg_squeeze-postgresql-extension-to-auto-rebuild-bloated-tables/
http://www.cybertec.at/download/pg_squeeze-1.0beta1.tar.gz

pg_squeeze 使用注意

由于pg_squeeze需要使用logical replication,所以必须设置足够多的slots,而且必须注意可能与STANDBY争抢SLOTS,必须预留足够的SLOTS。

另外由于pg_squeeze可以自动,也可以不设置自动的收缩。 对于自动的收缩,建议不要对繁忙的数据库开启,以免在高峰期触发,带来一定的性能影响。

参考

pg_squeeze, an open-source PostgreSQL extension from Cybertec, enables automatic and transparent fixing of one of the few weak points of PostgreSQL – bloated tables.

Unlike with built-in commands “VACUUM FULL” or “CLUSTER”, with “pg_squeeze” there are no extended periods of full table locking,thus reads and writes are not blocked during the rebuild!

Also the rebuilding process is very efficient due to a novel approach of using transaction log files and logical decoding (instead of triggers) to capture possible data changes to the table being rebuild.

This helps to save firstly on disk space and IO throughput and even more importantly enables very short locking-times, making it a perfect fit for mission-critical OLTP systems.

How does pg_squeeze work?

The extension is implemented as a background worker process (a framework introduced in version 9.4) that periodically monitors user-defined tables and when it detects that a table exceeded the “bloat threshold”, it kicks in and rebuilds that table automatically! Rebuilding happens concurrently in the background with minimal storage and computational overhead due to use of Postgres’ built-in replication slots together with logical decoding to extract possible table changes happening during the rebuild from XLOG.

Bloat threshold is of course configurable and bloat ratio calculation is based on the Free Space Map (taking also FILLFACTOR into account) or under certain conditions on the “pgstattuple” extension when it’s available. Additionally many customization parameters like “minimum table size” can be set, with non-suitable tables being ignored. Also reordering by an index or moving the table or indexes to new tablespace is possible.




/images/news/2016/pg_bot_banner.jpg


评论:3   浏览: 13770                   顶: 3423  踩: 3877 

请在登录后发表评论,否则无法保存。

1# __ xcvxcvsdf 回答于 2024-10-22 20:18:00+08
https://changshushi.tiancebbs.cn/qths/473180.html https://sh.tiancebbs.cn/hjzl/470458.html https://su.tiancebbs.cn/hjzl/459506.html https://www.tiancebbs.cn/ershoufang/471260.html https://su.tiancebbs.cn/hjzl/460949.html https://taicang.tiancebbs.cn/hjzl/459756.html https://www.tiancebbs.cn/ershoufang/469393.html https://su.tiancebbs.cn/hjzl/467099.html https://taicang.tiancebbs.cn/hjzl/458232.html https://aihuishou.tiancebbs.cn/sh/4870.html https://ln.tiancebbs.cn/qths/470500.html https://su.tiancebbs.cn/hjzl/471203.html https://aihuishou.tiancebbs.cn/sh/800.html https://www.tiancebbs.cn/ershoufang/471931.html https://yl.tiancebbs.cn/qths/463012.html https://aihuishou.tiancebbs.cn/sh/801.html https://su.tiancebbs.cn/hjzl/469102.html

2# __ xcvxcvsdf 回答于 2024-10-13 11:16:27+08
http://wutai.cqtcxxw.cn/guigang/ http://jinqiang.ahtcbmw.cn/ezhou/ http://ly.shtcxxw.cn/beijing/ https://qianguo.tiancebbs.cn/ http://shengshun.njtcbmw.cn/dongguan/ http://huaguang.jxtcbmw.cn/jiaxing/ http://taiying.njtcbmw.cn/tyqxzr/ http://js.sytcxxw.cn/esnyjx/ http://taiying.njtcbmw.cn/gspl/ http://nalei.zjtcbmw.cn/xunwu/ https://guangfubeilu.tiancebbs.cn/ http://huaguang.jxtcbmw.cn/zhejiang/ https://kaifeng.tiancebbs.cn/ http://jinqiang.ahtcbmw.cn/xinganmeng/ https://shayibake.tiancebbs.cn/ http://js.sytcxxw.cn/ahhz/ https://fenlei.tiancebbs.cn/jiadingqu/

3# __ xiaowu 回答于 2024-04-22 09:28:21+08
幸福的一家:https://www.nanss.com/xuexi/2162.html 辞职报告书:https://www.nanss.com/gongzuo/2297.html 动物的作文:https://www.nanss.com/xuexi/2170.html 祝福长辈的吉祥话8字:https://www.nanss.com/yulu/2095.html 晒晒我们班的牛人600字初一:https://www.nanss.com/xuexi/2060.html 林黛玉阴阳怪气语录:https://www.nanss.com/xuexi/2281.html 带玲字的有深意的网名:https://www.nanss.com/mingcheng/2229.html 朋友作文:https://www.nanss.com/xuexi/2182.html 休息一天的说说朋友圈:https://www.nanss.com/wenan/2377.html 做不到人人满意经典话:https://www.nanss.com/yulu/2416.html 感恩母亲演讲稿:https://www.nanss.com/xuexi/2313.html 电影雷锋观后感:https://www.nanss.com/xuexi/2113.html 下雪的唯美短句:https://www.nanss.com/yulu/2156.html 退房申请书:https://www.nanss.com/shenghuo/2456.html 王网名:https://www.nanss.com/mingcheng/1610.html 做人太难做好人更难的说说:https://www.nanss.com/wenan/1893.html 学生入党申请书:https://www.nanss.com/xuexi/2364.html 用玲的寓意取微信名:https://www.nanss.com/mingcheng/2007.html 植树作文:https://www.nanss.com/xuexi/2269.html 愿所有人都平安健康的句子:https://www.nanss.com/yulu/2241.html 垃圾分类的好处:https://www.nanss.com/xuexi/2019.html 乔布斯传读后感:https://www.nanss.com/xuexi/2144.html 传统文化的作文:https://www.nanss.com/xuexi/2310.html 暗恋的惊艳短句:https://www.nanss.com/yulu/2202.html 托物言志的作文:https://www.nanss.com/xuexi/2477.html 一起玩一起嗨的句子:https://www.nanss.com/wenan/1568.html 科技创新作文:https://www.nanss.com/xuexi/2268.html 形容爱到骨子里的句子:https://www.nanss.com/yulu/2471.html 劳动感悟:https://www.nanss.com/xuexi/2373.html 梅花作文:https://www.nanss.com/xuexi/2183.html



发表评论:
加入我们
QQ群1:5276420
QQ群2:3336901
QQ群3:254622631
文档群:150657323
文档翻译平台:按此访问
社区邮件列表:按此订阅
商业支持
扫码关注
加入我们
QQ群1:5276420
QQ群2:3336901
QQ群3:254622631
文档群:150657323
文档翻译平台:按此访问
社区邮件列表:按此订阅
商业支持
扫码关注
© PostgreSQL中文社区 ... (自2010年起)