pg_squeeze安装及简单使用
环境:redhat 7.4 postgresql 12.3 pg_squeeze 1.2
pg_squeeze下载地址:https://github.com/cybertec-postgresql/pg_squeeze/
介绍:pg_squeeze是一个扩展,它从表中删除未使用的空间,并且可以选择根据特定索引对元组进行排序,一般当一个表膨胀时一般使用vacuum full或者cluster进行表重建,在这一过程中会加排他锁,导致该表无法进行读写,只有等整个过程完成后才可以进行正常使用。
pg_squeeze就是来解决这个问题的,它只会在最后切换filenode的过程中加锁,其他过程中是不影响读写的。
pg_squeeze的优点
相比pg_repack或pg_reorg,pg_squeeze不需要建触发器,所以在重组时对原表的DML几乎没有性能影响。安装
解压文件,安装即可
安装报错:
[postgres@localhost pg_squeeze-REL1_0_PG_10]$ make
make: --pgxs: Command not found
make: *** No targets. Stop.
解决方式:
找到pg_config所在路径
添加到Makefile文件中
PG_CONFIG=/opt/pg12/bin/pg_config如何查看本机PG_CONFIG可用目录位置:
sudo find / -name "pg_config" -print
[postgres@localhost pg_squeeze-master]$ make
[postgres@localhost pg_squeeze-master]$ make install
配置Posgresql,修改postgresql.conf添加如下配置wal_level = logicalmax_replication_slots = 1 # 大于等于1shared_preload_libraries = 'pg_squeeze'添加插件
[postgres@localhost data]$ psql
psql (12.3)
Type "help" for help.postgres=# create extension pg_squeeze;
CREATE EXTENSION查看插件安装情况
postgres=# \dxList of installed extensionsName | Version | Schema | Description
--------------------+---------+------------+-----------------------------------------------------------pg_squeeze | 1.2 | squeeze | A tool to remove unused space from a relation.pg_stat_statements | 1.7 | public | track execution statistics of all SQL statements executedplpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(3 rows)postgres=# \d squeeze.tables;Table "squeeze.tables"Column | Type | Collation | Nullable | Default
------------------+-----------------------+-----------+----------+------------------------------------id | integer | | not null | nextval('tables_id_seq'::regclass)tabschema | name | | not null | tabname | name | | not null | clustering_index | name | | | rel_tablespace | name | | | ind_tablespaces | name[] | | | schedule | time with time zone[] | | not null | free_space_extra | integer | | not null | 50min_size | real | | not null | 8vacuum_max_age | interval | | not null | '01:00:00'::intervalmax_retry | integer | | not null | 0skip_analyze | boolean | | not null | false
Indexes:"tables_pkey" PRIMARY KEY, btree (id)"tables_tabschema_tabname_key" UNIQUE CONSTRAINT, btree (tabschema, tabname)
Check constraints:"tables_free_space_extra_check" CHECK (free_space_extra >= 0 AND free_space_extra < 100)"tables_min_size_check" CHECK (min_size > 0.0::double precision)
Referenced by:TABLE "tables_internal" CONSTRAINT "tables_internal_table_id_fkey" FOREIGN KEY (table_id) REFERENCES tables(id) ON DELETE CASCADETABLE "tasks" CONSTRAINT "tasks_table_id_fkey" FOREIGN KEY (table_id) REFERENCES tables(id) ON DELETE CASCADE
Triggers:tables_internal_trig AFTER INSERT ON tables FOR EACH ROW EXECUTE FUNCTION tables_internal_trig_func()
参数解释:
tabschema和tabname分别是架构和表名。schedule:列告诉您应该在一天的什么时候检查表格。这样的检查可能导致新的处理任务。
注:此参数替代了之前版本的task_interval和first_check两个字段(task_interval :表示检查表膨胀是否超过阀值的时间间隔;first_check :表示第一次检查时间)free_space_extra:表示空闲空间超过多少时就会对表进行重建,默认是50。min_size:被处理的最小的表占用的磁盘空间,默认是8。vacuum_max_age:当进行一次vacuum后,认为fsm是有效的最大时间,默认1小时。max_retry:当重建表失败时最大的重新尝试的次数,默认是0(即不重试)。clustering_index:用来在表重构结束后对表元组做物理排序的索引。rel_tablespace:表示表重建时,移动到哪个表空间中,NULL表示该表应保留在原处。ind_tablespaces:是一个二维数组,其中每行指定索引的表空间映射。第一和第二列分别表示索引名称和表空间名称。所有未指定映射的索引将保留在原始表空间中。关于表空间,值得一提的是一种特殊情况:如果表空间是为表而不是索引指定的,则表将移至该表空间,但索引仍保留在原始表空间中(即表的表空间不是索引的默认值)正如人们所期望的那样。skip_analyze:表示不应在ANALYZE命令之后进行表处理。默认值为“ false”,表示默认情况下执行ANALYZE。
注册语句:
最简单的“注册”看起来像
INSERT INTO squeeze.tables (tabschema, tabname, schedule) VALUES ('public', 'test', '{22:30, 03:00}');
可以选择指定其他列,例如:
INSERT INTO squeeze.tables (tabschema, tabname, schedule,free_space_extra,vacuum_max_age,max_retry) VALUES ('public', 'test', '{22:30, 03:00}', 30, '2 hours', 2);
启动pg_squeeze的进程需要调用
SELECT squeeze.start_worker();
关闭
SELECT squeeze.stop_worker();
注册
postgres=# INSERT INTO squeeze.tables (tabschema, tabname, schedule,free_space_extra,vacuum_max_age,max_retry) VALUES ('public', 'test', '{22:30, 03:00}', 30, '2 hours', 2);
INSERT 0 1开启pg_squeeze
postgres=# SELECT squeeze.start_worker();start_worker
--------------4230
(1 row)
创建表
postgres=# create table test(id int primary key);
CREATE TABLE要求:表中必须要有一个主键或者是唯一键。
插入数据
postgres=# insert into test select generate_series(1,5000000);
INSERT 0 5000000
查看表大小
postgres=# \dt+ test;List of relationsSchema | Name | Type | Owner | Size | Description
--------+------+-------+----------+--------+-------------public | test | table | postgres | 173 MB |
(1 row)
删除数据
postgres=# delete from test where id < 2500000;
DELETE 2499999
查看当前表的膨胀情况
postgres=# select * from squeeze.tables_internal;table_id | class_id | class_id_toast | free_space | last_task_created | last_task_finished
----------+----------+----------------+------------+------------------------------+------------------------------1 | | | | 2020-06-22 11:26:41.69873+08 | 2020-06-22 11:26:41.82096+08
(1 row)postgres=# \dt+ test;List of relationsSchema | Name | Type | Owner | Size | Description
--------+------+-------+----------+--------+-------------public | test | table | postgres | 173 MB |
(1 row)postgres=# 2020-06-22 11:26:41.825 CST [4230] LOG: logical decoding found consistent point at 0/37487C40
2020-06-22 11:26:41.825 CST [4230] DETAIL: There are no running transactions.
2020-06-22 11:26:41.825 CST [4230] CONTEXT: SQL statement "SELECT squeeze.squeeze_table(v_tabschema, v_tabname,v_cl_index, v_rel_tbsp, v_ind_tbsps)"PL/pgSQL function squeeze.process_current_task() line 41 at PERFORMSQL statement "SELECT squeeze.process_current_task()"
查看当前的事务
postgres=# SELECT squeeze.process_current_task();
查看表空间
postgres=# \dt+ test;List of relationsSchema | Name | Type | Owner | Size | Description
--------+------+-------+----------+-------+-------------public | test | table | postgres | 86 MB |
(1 row)
表空间已经释放
参考:
https://github.com/cybertec-postgresql/pg_squeeze/
https://blog.csdn.net/u012551524/article/details/88802570
pg_squeeze安装及简单使用相关推荐
- docker-compose的安装与简单使用
docker-compose的安装与简单使用 docker-compose简介 屁话不这么多,直接开干 docker-compose安装步骤 由于docker-compose托管在github上面,所 ...
- 内核同步对性能的影响及perf的安装和简单的使用
更多文章目录:点击这里 GitHub地址:https://github.com/ljrkernel 内核同步对性能的影响及perf的安装和简单的使用 看了一篇关于多线程应用程序性能分析的外文,结合之前 ...
- cakephp 安装mysql_CakePHP的安装的简单方法
在对于CakePHP的作用有了初步认识后,我们可以下载CakePHP来进行一些使用.在安装前,要检查php的版本情况,防止CakePHP框架出现不适配的情况. 对于具体的框架组装,会涉及到依赖库和Co ...
- 怎么进入python官网-Python的安装及简单的使用
原标题:Python的安装及简单的使用 像我们想要抓住一门好的编程语言,如何开始学习呢?我来简单介绍下python Python特性:语法简单,入门上手快,很多女神也在学习,方便找个编程的妹纸---- ...
- 刚安装的python如何使用-Python requests的安装与简单运用
强烈推荐!requests官方文档已有了中文版,请见http://cn.python-requests.org/zh_CN/latest/ . requests是python的一个HTTP客户端库,跟 ...
- python requests的安装与简单运用
强烈推荐!requests官方文档已有了中文版,请见http://cn.python-requests.org/en/latest/. requests是python的一个HTTP客户端库,跟urll ...
- memcache的windows下的安装和简单使用
原文:memcache的windows下的安装和简单使用 memcache是为了解决网站访问量大,数据库压力倍增的解决方案之一,由于其简单实用,很多站点现在都在使用memcache,但是memcach ...
- Oracle数据库学习(一)安装和简单使用
新公司的新项目,需要用到Oracle数据库,所以现在便来解除此数据库,不得不说,这个数据库还这是麻烦. 安装倒是简单,就是中间会遇到各种问题. 安装步骤参考:https://blog.csdn.net ...
- 1.Vue 安装与简单使用
Hello,我是 Alex 007,一个热爱计算机编程和硬件设计的小白,为啥是007呢?因为叫 Alex 的人太多了,再加上每天007的生活,Alex 007就诞生了. 1.Vue的安装与简单使用 这 ...
最新文章
- squid服务器的代理
- Protoc Buffer 优化传输大小的一个细节
- 学科网站建设的尝试与思考
- Java 中静态代码块 static的作用及用法
- Go的GAPATH详解
- QT的QMutableHashIterator类的使用
- pip/pip3更换国内源
- HTML五合一收款码网站源码(带35套模板)
- zookeeper 日志查看_zookeeper 安装和集群配置
- 电科 | 传感器及其应用技术
- sas不能安装独立的java_SAS安装问题解决办法
- 发货100全功能网站系统源码
- mysql视图存放位置_MySQL基础备忘(2)之视图
- 云计算的三种服务模式的讲解
- 汽车之家APP车型口碑--参数分析
- 求职中的平常心——Leo网上答疑48
- 艾宾浩斯遗忘曲线PHP,2018考研作文_艾宾浩斯遗忘曲线——记忆与复习_沪江英语...
- 课程设计每日总结0820
- 三星android截屏快捷键是什么,三星截屏快捷键以及截屏方法
- 使用PP-TTS实现语音合成
热门文章
- android 解决微信登录白屏样式问题
- 年终奖没领到惨遭开除,Fabio机器人的苦逼之旅
- 华为路由器交换机常用命令(随时补充更新)
- 【Spring Boot】关于上传文件例子的剖析
- 在数据增强、蒸馏剪枝下ERNIE3.0分类模型性能提升
- 【C++】加油站加油
- Verilog语言语句介绍
- 对象可以创建数组吗_企业微信活码如何创建?活码可以统计渠道来源吗?
- 怎么设置织梦栏目html结尾,dedecms网站栏目地址url优化成.html结尾的而不是文件夹形式结尾的。请大家来帮忙。...
- 不用跑项目,组件效果所见即所得,绝了~