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>