admin

[运营交流] postgresql表分区

随着数据库慢慢增大,查询会变得越来越慢,下面介绍下表分区,用来提升查询速度,postgresql本身支持这个功能,但是今天写的是pg_pathman,一个阿里做的东西。

支持9.5+,易读默认装的是9.3,要升级下数据库。


过几天把安装脚本更新一下,装postgresql10。


在安装了10的前提下,进行下面的设置就可以启用了。


安装pg_pathman

yum -y install postgresql10-devel


git clone https://github.com/postgrespro/pg_pathman

#export PATH=/var/lib/pgsql/10:$PATH

export PATH=/usr/pgsql-10/bin/:$PATH



cd pg_pathman

make USE_PGXS=1

make USE_PGXS=1 install


修改配置文件,添加pg_pathman扩展

vi postgresql.conf

shared_preload_libraries = 'pg_pathman' 

创建扩张

create extension pg_pathman;

把articleno设置为非NULL。pg_pathman要求是非NULL的

ALTER TABLE t_chapter ALTER COLUMN articleno SET NOT NULL;

每个子表保存1000本小说的数据

select create_range_partitions('t_chapter'::regclass,'articleno',0,1000,77,false) ;

非阻塞转移数据

select partition_table_concurrently('t_chapter'::regclass,10000,1.0);

确认主表数据已经被转移到子表

select count(*) from only t_chapter;

禁用主表,都用子表去处理

select set_enable_parent('t_chapter'::regclass, false);

查看一下查询计划,看看是不是走的子表

explain select * from t_chapter where articleno = 45052;


测试结果,速度提升还是挺明显的。


可以参考下这里

https://yq.aliyun.com/articles/62314


#1楼
发帖时间:2017-12-26   |   查看数:0   |   回复数:2
admin
出现
usr/pgsql-10/include/server/libpq/libpq-be.h:23:25: fatal error: openssl/ssl.h: No such file or directory
错误的话,

yum install openssl-devel安装一下
2018-1-17 #2楼
toshow
mark
2019-11-14 #3楼
游客组