天天看点

PostgreSQL 9.6 sharding based on FDW & pg_pathman

digoal

2016-10-26

postgresql , 分区表 , pg_pathman , custom scan api , sharding , fdw

可以阅读以下几篇文章先回顾一下fdw,基于fdw的shared以及高效的分区插件pg_pathman。

<a href="https://github.com/digoal/blog/blob/master/201610/20161004_01.md">《postgresql 9.6 单元化,sharding (based on postgres_fdw) - 内核层支持前传》</a>

<a href="https://github.com/digoal/blog/blob/master/201610/20161005_01.md">《postgresql 9.6 sharding + 单元化 (based on postgres_fdw) 最佳实践 - 通用水平分库场景设计与实践》</a>

<a href="https://github.com/digoal/blog/blob/master/201610/20161024_01.md">《postgresql 9.5+ 高效分区表实现 - pg_pathman》</a>

由于pg_pathman支持foreign table,所以拿它来做sharding也是理所当然的事情,同时它支持的hash partition不需要在query中带入constraint对应的clause,也能走分区查询。

依旧使用《postgresql 9.6 sharding + 单元化 (based on postgres_fdw) 最佳实践 - 通用水平分库场景设计与实践》文章中的例子。

例子使用1个路由节点,4个数据节点。

1. 配置目标库的pg_hba.conf

使用md5认证

2. 创建用户

3. 创建数据库

4. 配置数据库权限

5. 创建schema, 建议与user同名

6. 配置路由节点,需要用到postgres_fdw与pg_pathman插件

7. ddl建表语句 , ddl-1.sql

8. 初始化数据节点,创建数据表,注意表名最好全局唯一,方便使用import foreign schema的方式导入。

9. 初始化master

10. 插入压测

插入数据测试的函数

压测

直连测试

11. query测试

1. 基于fdw的shard,从功能上来讲还有哪些值得改进的点:

例如, 支持聚合下推(10.0已经支持)

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f5d6bce63ceb3c59a964814bb0df5a0648e750e5">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=f5d6bce63ceb3c59a964814bb0df5a0648e750e5</a>

<a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7012b132d07c2b4ea15b0b3cb1ea9f3278801d98">https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=7012b132d07c2b4ea15b0b3cb1ea9f3278801d98</a>

append的并行化,目前如果要扫描多个分区,是串行的,并不是并行扫描,非常影响效率。

2. 从性能方面来讲,还有哪些值得改进的点:

从profile的结果来看,目前的锁较重,有非常大的性能提升空间,需要花点时间看看代码。

当然如果当前的性能能满足你,或者你通过构建多个对等的master加上负载均衡,也能解决这个问题。

现在与直连单节点的性能差距还是较大的。

<a href="http://info.flagcounter.com/h9v1">count</a>