SlideShare uma empresa Scribd logo
1 de 40
PostgreSQL 10 New Feature
@ COSCUP 2017
Taiwan PostgreSQL User Group
林宗禧
Outline
• About Me
• History: PostgreSQL前世今生
• PostgreSQL 10 新特性
• PostgreSQL Ecosystem
• 台灣PostgreSQL使用者社群
2Taiwan PostgreSQL User Group2017/8/11
About Me
• 我是林宗禧 (José Lin)
– 自Hadoop/HBase入門OSS
• 工作在研究分散式資料庫系統
– 熟PG與MongoDB
– 接觸多種NoSQL/NewSQL
• 成為PostgreSQL愛好者
– '13年起拜訪國內PG愛好者、認識日本JPUG
– '17年起著手PG社群 (感謝許多PG前輩& JPUG幫忙!!)
2017/8/11 3Taiwan PostgreSQL User Group
History: PostgreSQL前世今生
1973
Ingres
1985
Post-Ingres
Postgres
1994
Postgres95
42017/8/11
•與Eugene Wong在UC
Berkeley共同開發類似於
IBM System R 的DB。
•免費散佈Ingres代碼,
1980年止發行了1000份。
基於Ingres商業化:
•1984年 Informix
•1980-90年 Sybase
Michael Stonebraker
•1985年著手“後-Ingres”
計畫,稱為 “Postgres”
基於Postgres商業化:
•1990年成立Illustra,後
被Informix 併購
基於Ingres商業化:
•1987年 NonStop SQL
•1992年 Sybase 賣給微
軟變為Microsoft SQL
Server
Andrew Yu & Jolly Chen
•1994年Andrew Yu和
Jolly Chen在UC
Berkeley,增加SQL直譯
器,發布Postgres95。
•1996年計畫改名為
PostgreSQL。
History: PostgreSQL前世今生
1996
PostgreSQL 6
2000
PostgreSQL 7
2005
PostgreSQL 8
52017/8/11
•PostgreSQL第一次發行,
版本為6.0。
•透過Internet組成一組來
自世界各地的開發者。
•2001年Command
Prompt, Inc.釋出
Mammoth PostgreSQL
套件並且贊助支援社群。
基於Postgres商業化:
•2000年Red Hat投資籌
組Great Bridge公司來
商業化PostgreSQL。
•2001年因市場狀況不佳
Great Bridge倒閉。
•2005年11月昇陽宣布支援
PostgreSQL。
•2006年6月Solaris 10包含
PostgreSQL一起發布。
•8.0版在效能、管理、為運
已達24/7水準。
基於Postgres商業化:
•2005年EnterpriseDB (移
轉Oracle)、 Greenplum
(資料倉儲、商業智慧) 投入
商業化。
1999年6月JPUG成立 台灣建置大型PG案例
History: PostgreSQL前世今生
2010
PostgreSQL 9
2011~2016
PostgreSQL
9.1~9.6
2017
PostgreSQL
10
Taiwan PostgreSQL User Group 62017/8/11
•Streaming Replication
•Hot Standby
•64-bit Windows
•FDW
•GiST index
•JSON、JSONB
•Materialized Views
•UPSERT
基於Postgres商業化:
•2015年Pivotal開源
Greenplum。
•10之後的版號不會有第三
碼,下次版號為11
2017年6月TWPUG成立
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
2. 邏輯複製(Logical Replication)
3. 平行查詢強化 (Parallel Queries)
4. FDW強化(Additional FDW Push-Down)
5. 多節點同步寫入 (Quorum Commit)
6. ID欄位功能(Identity columns )
7. 安全認證提升(SCRAM-SHA-256 Authentication)
8. 多欄位關聯(Multi-column Correlation Statistics)
9. 全文檢索支持 JSON 和 JSONB
10. 新增 pg_hba_file_rules 項目
11. 新增 pg_stat_activity 監控項目
12. 新增 pg_sequence 系統表
13. Row層級的安全政策(Row-level security)
14. Schema 預設權限(Default permissions on schemas)
Taiwan PostgreSQL User Group 72017/8/11
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 82017/8/11
-- 建立主表
CREATE TABLE tbl( a INT, b VARCHAR(10));
-- 建立繼承表
CREATE TABLE tbl_1 (CHECK( a <= 1000 ) ) INHERITS (tbl);
CREATE TABLE tbl_2 (CHECK( a <= 10000 AND a >1000 ))
INHERITS (tbl);
CREATE TABLE tbl_3 ( CHECK( a <= 100000 AND a >10000 ))
INHERITS (tbl);
原始步驟:
1. 建立主表、繼承表
2. 建立 function
3. 建立 Trigger
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 92017/8/11
-- 建立function
CREATE OR REPLACE FUNCTION tbl_part_tg()
RETURNS TRIGGER AS $$
BEGIN
IF ( NEW. a <= 1000 ) THEN
INSERT INTO tbl_1 VALUES (NEW.*);
ELSIF ( NEW. a > 1000 and NEW.a <= 10000 ) THEN
INSERT INTO tbl_2 VALUES (NEW.*);
...(略,同上 tbl_3, tbl_4)
ELSE
RAISE EXCEPTION 'data out of range!';
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 102017/8/11
-- 建立trigger
CREATE TRIGGER insert_tbl_part_tg
BEFORE INSERT ON tbl
FOR EACH ROW EXECUTE PROCEDURE tbl_part_tg();
-- EXPLAIN
postgres=# explain select *from tbl where a =11111;
QUERY PLAN
-------------------------------------------------------------
Append (cost=0.00..24.50 rows=7 width=42)
-> Seq Scan on tbl (cost=0.00..0.00 rows=1 width=42)
Filter: (a = 11111)
-> Seq Scan on tbl_3 (cost=0.00..24.50 rows=6 width=42)
Filter: (a = 11111)
(5 rows)
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 112017/8/11
PG 9.6
• 建立主表、繼承表
• 建立 function
• 建立 Trigger
PG 10
• 建立主表
• PARTITION BY
• LIST
• RANGE
• HASH
• 建立繼承表
• 建立 function
• 建立 Trigger
(Not yet)
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 122017/8/11
-- Partition by LIST
CREATE TABLE list_parted (a int) PARTITION BY LIST (a);
CREATE TABLE part_1 PARTITION OF list_parted FOR VALUES IN (1);
CREATE TABLE part_2 PARTITION OF list_parted FOR VALUES IN (2);
CREATE TABLE part_3 PARTITION OF list_parted FOR VALUES IN (3);
CREATE TABLE part_4 PARTITION OF list_parted FOR VALUES IN (4);
CREATE TABLE part_5 PARTITION OF list_parted FOR VALUES IN (5);
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 132017/8/11
-- Partition by LIST
postgres=# insert into list_parted values(32); --failed
ERROR: no partition of relation "list_parted" found for row
DETAIL: Failing row contains (32).
postgres=# insert into part_1 values(1);
INSERT 0 1
postgres=# insert into part_1 values(2);--failed
ERROR: new row for relation "part_1" violates partition
constraint
DETAIL: Failing row contains (2).
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 142017/8/11
-- Partition by LIST
postgres=# explain select *from list_parted where a =1;
QUERY PLAN
---------------------------------------------------------------
--
Append (cost=0.00..41.88 rows=14 width=4)
-> Seq Scan on list_parted (cost=0.00..0.00 rows=1 width=4)
Filter: (a = 1)
-> Seq Scan on part_1 (cost=0.00..41.88 rows=13 width=4)
Filter: (a = 1)
(5 rows)
※ 主表不會查
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 152017/8/11
-- Partition by RANGE
CREATE TABLE range_parted ( a int ) PARTITION BY RANGE (a);
CREATE TABLE range_parted1 PARTITION OF range_parted FOR VALUES
from (1) TO (1000);
CREATE TABLE range_parted2 PARTITION OF range_parted FOR VALUES
FROM (1000) TO (10000);
CREATE TABLE range_parted3 PARTITION OF range_parted FOR VALUES
FROM (1000) TO (100000);
postgres=# insert into range_parted values(123);
INSERT 0 1
postgres=# insert into range_parted1 values(456);
INSERT 0 1
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 162017/8/11
-- Partition by RANGE
postgres=# explain select *from range_parted where a=32425;
QUERY PLAN
---------------------------------------------------------------
------
Append (cost=0.00..41.88 rows=14 width=4)
-> Seq Scan on range_parted (cost=0.00..0.00 rows=1
width=4)
Filter: (a = 32425)
-> Seq Scan on range_parted3 (cost=0.00..41.88 rows=13
width=4)
Filter: (a = 32425)
(5 rows)
※ 主表不會查
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 172017/8/11
-- ATTACH
postgres=# alter table range_parted ATTACH PARTITION
range_parted5 FOR VALUES FROM (100000) TO (1000000);
ALTER TABLE
-- DETACH
postgres=# alter table range_parted DETACH PARTITION
range_parted5 ;
ALTER TABLE
PostgreSQL 10 新特性
1. 資料表分割強化 (Table Partitioning)
Taiwan PostgreSQL User Group 182017/8/11
33.65 22.2
55.85
185.75
488.9
172 171
0 0
40.2
3.5 4.72
133.5 133.8
傳統方式 PG10
單位:秒
PostgreSQL 10 新特性
2. 邏輯複製(Logical Replication)
• 由2ndQuadrant回饋的功能
• PG9.0-9.6:Streaming Replication
– WAL Replication
• PG10:Logical Replication
– Table 層級顆粒細度 (以前需用Londiste3 實現)
Taiwan PostgreSQL User Group 192017/8/11
PostgreSQL 10 新特性
2. 邏輯複製(Logical Replication)
Taiwan PostgreSQL User Group 202017/8/11
$ psql -p 5432 -c "ALTER
SYSTEM SET wal_level =
'logical';" test
$ pg_ctl -p 5432 restart
$ psql -p 5432 test
CREATE TABLE test (x INT
PRIMARY KEY);
INSERT INTO test VALUES (1);
CREATE PUBLICATION mypub FOR
TABLE test;
$ psql -p 5433 test
CREATE TABLE test (x INT
PRIMARY KEY);
CREATE SUBSCRIPTION mysub
CONNECTION 'dbname=test
port=5432' PUBLICATION mypub;
Cluseter 1 Cluseter 2
PostgreSQL 10 新特性
2. 邏輯複製(Logical Replication)
• 邏輯複製允許:
– 資料表層級的顆粒細度
– 可從多台主機複製到集中的一台主機
– 可以從單一資料表複製到多台主機
Taiwan PostgreSQL User Group 212017/8/11
INSERT INTO test VALUES (2);
SELECT * FROM test;
1
SELECT * FROM test;
1
2
Cluseter 1 Cluseter 2
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
• PG 9.6 已有此功能
• PG 10 開始支援以下平行查詢
– B-tree index scans
– Bitmap heap scans
– Merge joins
– Procedural Languages
Taiwan PostgreSQL User Group 222017/8/11
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
Taiwan PostgreSQL User Group 232017/8/11
-- 建立測試資料表
create table test_big1(id int4 primary key, create_time
timestamp without time zone default clock_timestamp(), name
character varying(32));
-- 插入 1000萬筆資料
insert into test_big1(id,name) select n,n*random()*10000 from
generate_series(1,10000000) n ;
-- 資料插入後的資料表
postgres=# select * from test_big1 limit 3;
id | create_time | name
----+----------------------------+------------------
1 | 2017-05-21 16:02:24.921751 | 2298.13809040934
2 | 2017-05-21 16:02:24.922051 | 7580.18649183214
3 | 2017-05-21 16:02:24.922064 | 24218.4893181548
(3 rows)
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
Taiwan PostgreSQL User Group 242017/8/11
-- 查詢 max_parallel_workers
postgres=# show max_parallel_workers;
max_parallel_workers
----------------------
4
(1 row)
-- 在啟動平行查詢的狀態執行EXPLAIN
postgres=# explain analyze select count(*) from test_big1 where
id <1000000 ;
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
Taiwan PostgreSQL User Group 252017/8/11
QUERY PLAN
---------------------------------------------------------------
Finalize Aggregate (cost=18576.59..18576.60 rows=1 width=8)
(actual time=73.362..73.362 rows=1 loops=1)
-> Gather (cost=18576.17..18576.58 rows=4 width=8) (actual
time=73.200..73.355 rows=5 loops=1)
Workers Planned: 4
Workers Launched: 4
-> Partial Aggregate (cost=17576.17..17576.18 rows=1
width=8) (actual time=68.992..68.992 rows=1 loops=5)
-> Parallel Index Only Scan using
test_big1_pkey on test_big1 (cost=0.43..16947.37 rows=251523
width=0) (actual time=0.053..54.343 rows=200000 loops=5)
Index Cond: (id < 1000000)
Heap Fetches: 174195
Planning time: 0.105 ms
Execution time: 74.572 ms
(10 rows)
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
Taiwan PostgreSQL User Group 262017/8/11
-- 關閉 max_parallel_workers
postgres=# set max_parallel_workers=0;
SET
-- 關閉平行查詢後執行EXPLAIN
postgres=# explain analyze select count(*) from test_big1 where
id <1000000 ;
PostgreSQL 10 新特性
3. 平行查詢強化 (Parallel Queries)
Taiwan PostgreSQL User Group 272017/8/11
QUERY PLAN
---------------------------------------------------------------
Finalize Aggregate (cost=18576.59..18576.60 rows=1 width=8)
(actual time=257.585..257.585 rows=1 loops=1)
-> Gather (cost=18576.17..18576.58 rows=4 width=8) (actual
time=257.579..257.579 rows=1 loops=1)
Workers Planned: 4
Workers Launched: 0
-> Partial Aggregate (cost=17576.17..17576.18 rows=1
width=8) (actual time=257.251..257.251 rows=1 loops=1)
-> Parallel Index Only Scan using
test_big1_pkey on test_big1 (cost=0.43..16947.37 rows=251523
width=0) (actual time=0.042..183.384 rows=999999 loops=1)
Index Cond: (id < 1000000)
Heap Fetches: 999999
Planning time: 0.102 ms
Execution time: 257.717 ms
(10 rows)
※ 大約 74.572 ms 的4倍
PostgreSQL 10 新特性
4. FDW強化(Additional FDW Push-Down)
• PG9.1/9.2 FDW:SELECT
• PG9.3 FDW:INSERT/UPDATE/DELETE
• PG9.6 FDW:JOINS / SORTS
Taiwan PostgreSQL User Group 282017/8/11
PG
FDW
TBL
Foreign Server/Data Source
FTBL
PostgreSQL 10 新特性
4. FDW強化(Additional FDW Push-Down)
• PG10 FDW: Query Push-Down (Aggregation)
Taiwan PostgreSQL User Group 292017/8/11
PG 9.x
FDW
FTBL
TBL
All data
explain (analyze on,verbose on) select flag,count(*)
from ft_test_fdw3 group by flag;
Table,
Where
PG 10
FDW
FTBL
TBL
Selected
data
Table,
Where,
Group by,
Count()
…
Rows: 100,000
9.6 Time: 441.758 ms
10 Time: 19.928 ms
PostgreSQL 10 新特性
4. FDW強化(Additional FDW Push-Down)
Taiwan PostgreSQL User Group 302017/8/11
QUERY PLAN
---------------------------------------------------------------
------------------------------------------
Sort (cost=211.41..211.91 rows=200 width=12) (actual
time=19.662..19.662 rows=3 loops=1)
Output: flag, (count(*))
Sort Key: ft_test_fdw3.flag
Sort Method: quicksort Memory: 25kB
-> Foreign Scan (cost=129.25..203.76 rows=200 width=12)
(actual time=19.648..19.649 rows=3 loops=1)
Output: flag, (count(*))
Relations: Aggregate on (francs.ft_test_fdw3)
Remote SQL: SELECT flag, count(*) FROM
francs.test_fdw3 GROUP BY flag
Planning time: 0.212 ms
Execution time: 19.928
※ Push-down :
count(*)、Group By
※ 9.6: rows=100K
PostgreSQL 10 新特性
5.多節點同步寫入 (Quorum Commit)
• 有兩種方式:
– FIRST num_sync (standby_name [, ...])
– ANY num_sync (standby_name [, ...])
• num_sync 是指需要同步複製的備節點個數。
• standby_name 是指同步複製備節點的名稱。
Taiwan PostgreSQL User Group 312017/8/11
postgres=# ALTER SYSTEM SET synchronous_standby_names = 'FIRST
1 (s1, s2)';
postgres=# ALTER SYSTEM SET synchronous_standby_names = 'ANY 1
(s1, s2)' ;
postgres=# ALTER SYSTEM SET synchronous_standby_names = 'ANY 2
(s1, s2, s3)';
PostgreSQL 10 新特性
6. ID欄位功能(Identity columns )
• Identity 需要與 Serial 互相比較
Taiwan PostgreSQL User Group 322017/8/11
-- 示範Serial:複製 t_serial 資料表至 t_serial2
postgres=# create table t_serial2 (like t_serial including
all);
CREATE TABLE
postgres=# d t_serial2
Table "francs.t_serial2"
Column | Type | Collation | Nullable |
Default
--------+---------+-----------+----------+---------------------
id | integer | | not null |
nextval('t_serial_id_seq'::regclass)
name | text | | |
Indexes:
"t_serial2_pkey" PRIMARY KEY, btree (id)
PostgreSQL 10 新特性
6. ID欄位功能(Identity columns )
• Identity 需要與 Serial 互相比較
Taiwan PostgreSQL User Group 332017/8/11
-- 示範Identity:複製 t_identity資料表至 t_identity2
postgres=# create table t_identity2 ( like t_identity
including all);
CREATE TABLE
postgres=# d t_identity2
Table "francs.t_identity2"
Column | Type | Collation | Nullable | Default
--------+--------+-----------+----------+----------------------
------------
id | bigint | | not null | generated by default
as identity
name | text | | |
Indexes:
"t_identity2_pkey" PRIMARY KEY, btree (id)
PostgreSQL 10 新特性
7. 安全認證提升(SCRAM-SHA-256
Authentication)
• SCRAM-SHA-256 提供比 MD5 更安全的密
碼驗證功能:
– 降低連線重複率 (連線超過64K,MD5會產生機率
50% 的重複。)
– 被偷取的hashed密碼更難被重複使用
– 更難使用暴力破解法
Taiwan PostgreSQL User Group 342017/8/11
PostgreSQL 10 新特性
其他:
• 多欄位關聯(Multi-column Correlation Statistics)
• 全文檢索支持 JSON 和 JSONB
• 新增 pg_hba_file_rules 項目
• 新增 pg_stat_activity 監控項目
• 新增 pg_sequence 系統表
• Row層級的安全政策(Row-level security)
• Schema 預設權限(Default permissions on
schemas)
Taiwan PostgreSQL User Group 352017/8/11
PostgreSQL 10 新特性
• 參考資料/來源:
– http://www.postgres.cn/news/viewone/1/247
– http://francs3.blog.163.com/blog/
– https://momjian.us/main/writings/pgsql/feat
ures.pdf
Taiwan PostgreSQL User Group 362017/8/11
PostgreSQL Ecosystem
• Slony-I / Pgpool-II (multiple replication)
• Pglogical / Postgres-BDR (logical
replication)
• Postgres-XC / XL / X2 (Distributed)
• PgBouncer ( pooling )
• Barman (backup / recovery)
• PG-Storm (GPU computing)
• PgAdmin / PhpPgAdmin / PgStudio… (GUI)
• Lots of FDW tools…
Taiwan PostgreSQL User Group 372017/8/11
台灣PostgreSQL使用者社群
• Github: pgsql-tw
• FB: @pgsqlTaiwan
(from 郭朝益先生)
Taiwan PostgreSQL User Group 382017/8/11
台灣PostgreSQL使用者社群
• 為何要成立PostgreSQL台灣使用者社群?
– 惦惦吃三碗公
– 愛好者有點難找
– 高手藏身在民間
• 這個社群可以做什麼?
– 彼此交流、經驗分享
– 共同研究、合作開創新專案
– 或是任何跟PostgreSQL有關的都可以~
Taiwan PostgreSQL User Group 392017/8/11
Thank you.
歡迎加入台灣PostgreSQL使用者社群
Github : pgsql-tw
Website : pgsql-tw.github.io
Facebook : @pgsqlTaiwan
Taiwan PostgreSQL User Group 402017/8/11

Mais conteúdo relacionado

Mais procurados

11g新特性streams同步捕获
11g新特性streams同步捕获11g新特性streams同步捕获
11g新特性streams同步捕获maclean liu
 
配置Oracle 10g 双向流复制
配置Oracle 10g 双向流复制配置Oracle 10g 双向流复制
配置Oracle 10g 双向流复制maclean liu
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇小新 制造
 
分区表基础知识培训
分区表基础知识培训分区表基础知识培训
分区表基础知识培训maclean liu
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOpenSourceCamp
 
Oracle10g高级安全特性列加密技术
Oracle10g高级安全特性列加密技术Oracle10g高级安全特性列加密技术
Oracle10g高级安全特性列加密技术maclean liu
 
CKAN 技術介紹 (基礎篇)
CKAN 技術介紹 (基礎篇)CKAN 技術介紹 (基礎篇)
CKAN 技術介紹 (基礎篇)Chengjen Lee
 
MapReduce 簡單介紹與練習
MapReduce 簡單介紹與練習MapReduce 簡單介紹與練習
MapReduce 簡單介紹與練習孜羲 顏
 
Essential oracle security internal for dba
Essential oracle security internal for dbaEssential oracle security internal for dba
Essential oracle security internal for dbamaclean liu
 
10, OCP - flashback
10, OCP - flashback10, OCP - flashback
10, OCP - flashbackted-xu
 
Hadoop基线选定
Hadoop基线选定Hadoop基线选定
Hadoop基线选定baggioss
 
了解Oracle在线重定义online redefinition
了解Oracle在线重定义online redefinition了解Oracle在线重定义online redefinition
了解Oracle在线重定义online redefinitionmaclean liu
 
DNS协议与应用简介
DNS协议与应用简介DNS协议与应用简介
DNS协议与应用简介琛琳 饶
 
Oracle试题Exam Adminv1.1
Oracle试题Exam Adminv1.1Oracle试题Exam Adminv1.1
Oracle试题Exam Adminv1.1Zianed Hou
 
MySQL 6.0 下的cluster + replicate - 20080220
MySQL 6.0 下的cluster + replicate - 20080220MySQL 6.0 下的cluster + replicate - 20080220
MySQL 6.0 下的cluster + replicate - 20080220Jinrong Ye
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops琛琳 饶
 
Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例maclean liu
 
Mysql企业备份发展及实践
Mysql企业备份发展及实践Mysql企业备份发展及实践
Mysql企业备份发展及实践maclean liu
 
Cassandra的初步使用及一些简单的操作
Cassandra的初步使用及一些简单的操作Cassandra的初步使用及一些简单的操作
Cassandra的初步使用及一些简单的操作zhubin885
 

Mais procurados (20)

11g新特性streams同步捕获
11g新特性streams同步捕获11g新特性streams同步捕获
11g新特性streams同步捕获
 
配置Oracle 10g 双向流复制
配置Oracle 10g 双向流复制配置Oracle 10g 双向流复制
配置Oracle 10g 双向流复制
 
Altibase管理培训 安装篇
Altibase管理培训 安装篇Altibase管理培训 安装篇
Altibase管理培训 安装篇
 
分区表基础知识培训
分区表基础知识培训分区表基础知识培训
分区表基础知识培训
 
Osc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresqlOsc scott linux下的数据库优化for_postgresql
Osc scott linux下的数据库优化for_postgresql
 
Asm+aix
Asm+aixAsm+aix
Asm+aix
 
Oracle10g高级安全特性列加密技术
Oracle10g高级安全特性列加密技术Oracle10g高级安全特性列加密技术
Oracle10g高级安全特性列加密技术
 
CKAN 技術介紹 (基礎篇)
CKAN 技術介紹 (基礎篇)CKAN 技術介紹 (基礎篇)
CKAN 技術介紹 (基礎篇)
 
MapReduce 簡單介紹與練習
MapReduce 簡單介紹與練習MapReduce 簡單介紹與練習
MapReduce 簡單介紹與練習
 
Essential oracle security internal for dba
Essential oracle security internal for dbaEssential oracle security internal for dba
Essential oracle security internal for dba
 
10, OCP - flashback
10, OCP - flashback10, OCP - flashback
10, OCP - flashback
 
Hadoop基线选定
Hadoop基线选定Hadoop基线选定
Hadoop基线选定
 
了解Oracle在线重定义online redefinition
了解Oracle在线重定义online redefinition了解Oracle在线重定义online redefinition
了解Oracle在线重定义online redefinition
 
DNS协议与应用简介
DNS协议与应用简介DNS协议与应用简介
DNS协议与应用简介
 
Oracle试题Exam Adminv1.1
Oracle试题Exam Adminv1.1Oracle试题Exam Adminv1.1
Oracle试题Exam Adminv1.1
 
MySQL 6.0 下的cluster + replicate - 20080220
MySQL 6.0 下的cluster + replicate - 20080220MySQL 6.0 下的cluster + replicate - 20080220
MySQL 6.0 下的cluster + replicate - 20080220
 
Monitor is all for ops
Monitor is all for opsMonitor is all for ops
Monitor is all for ops
 
Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例Sql调优clustering factor影响数据删除速度一例
Sql调优clustering factor影响数据删除速度一例
 
Mysql企业备份发展及实践
Mysql企业备份发展及实践Mysql企业备份发展及实践
Mysql企业备份发展及实践
 
Cassandra的初步使用及一些简单的操作
Cassandra的初步使用及一些简单的操作Cassandra的初步使用及一些简单的操作
Cassandra的初步使用及一些简单的操作
 

Semelhante a PostgreSQL 10 New Features

快速了解PostgreSQL
快速了解PostgreSQL快速了解PostgreSQL
快速了解PostgreSQL正中 周
 
COSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumCOSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumOmni-Alex Chen
 
3小时 快速了解postgre sql
3小时 快速了解postgre sql3小时 快速了解postgre sql
3小时 快速了解postgre sqlMichael Fan
 
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC
 
第02章 线性表(java版)
第02章  线性表(java版)第02章  线性表(java版)
第02章 线性表(java版)Yan Li
 
诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础 诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础 maclean liu
 
Elasticsearch search engine_development_tips
Elasticsearch search engine_development_tipsElasticsearch search engine_development_tips
Elasticsearch search engine_development_tipsYI-CHING WU
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 Lheima911
 
5, OCP - oracle storage
5, OCP - oracle storage5, OCP - oracle storage
5, OCP - oracle storageted-xu
 
Study4.TW .NET Conf 2018 - Fp in c#
Study4.TW .NET Conf 2018  - Fp in c#Study4.TW .NET Conf 2018  - Fp in c#
Study4.TW .NET Conf 2018 - Fp in c#Chieh Kai Yang
 
为10g rac cluster添加节点
为10g rac cluster添加节点为10g rac cluster添加节点
为10g rac cluster添加节点maclean liu
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130Jinrong Ye
 
Itpub电子杂志第四期第二稿
Itpub电子杂志第四期第二稿Itpub电子杂志第四期第二稿
Itpub电子杂志第四期第二稿yiditushe
 
基于Lucene的站内搜索
基于Lucene的站内搜索基于Lucene的站内搜索
基于Lucene的站内搜索fulin tang
 
基于Lucene的站内搜索
基于Lucene的站内搜索基于Lucene的站内搜索
基于Lucene的站内搜索fulin tang
 
Oracle数据库升级前必要的准备工作
Oracle数据库升级前必要的准备工作Oracle数据库升级前必要的准备工作
Oracle数据库升级前必要的准备工作maclean liu
 
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUGYingSiang Geng
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南HonestQiao
 
PostgreSQL Search
PostgreSQL SearchPostgreSQL Search
PostgreSQL Searchguestb75c3a
 

Semelhante a PostgreSQL 10 New Features (20)

快速了解PostgreSQL
快速了解PostgreSQL快速了解PostgreSQL
快速了解PostgreSQL
 
COSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 GreenplumCOSCUP 2019 - 開源大數據引擎 Greenplum
COSCUP 2019 - 開源大數據引擎 Greenplum
 
3小时 快速了解postgre sql
3小时 快速了解postgre sql3小时 快速了解postgre sql
3小时 快速了解postgre sql
 
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
 
第02章 线性表(java版)
第02章  线性表(java版)第02章  线性表(java版)
第02章 线性表(java版)
 
诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础 诗檀软件 Oracle开发优化基础
诗檀软件 Oracle开发优化基础
 
Elasticsearch search engine_development_tips
Elasticsearch search engine_development_tipsElasticsearch search engine_development_tips
Elasticsearch search engine_development_tips
 
Install Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 LInstall Oracle11g For Aix 5 L
Install Oracle11g For Aix 5 L
 
5, OCP - oracle storage
5, OCP - oracle storage5, OCP - oracle storage
5, OCP - oracle storage
 
Study4.TW .NET Conf 2018 - Fp in c#
Study4.TW .NET Conf 2018  - Fp in c#Study4.TW .NET Conf 2018  - Fp in c#
Study4.TW .NET Conf 2018 - Fp in c#
 
为10g rac cluster添加节点
为10g rac cluster添加节点为10g rac cluster添加节点
为10g rac cluster添加节点
 
服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130服务器基准测试-叶金荣@CYOU-20121130
服务器基准测试-叶金荣@CYOU-20121130
 
Itpub电子杂志第四期第二稿
Itpub电子杂志第四期第二稿Itpub电子杂志第四期第二稿
Itpub电子杂志第四期第二稿
 
Optimzing mysql
Optimzing mysqlOptimzing mysql
Optimzing mysql
 
基于Lucene的站内搜索
基于Lucene的站内搜索基于Lucene的站内搜索
基于Lucene的站内搜索
 
基于Lucene的站内搜索
基于Lucene的站内搜索基于Lucene的站内搜索
基于Lucene的站内搜索
 
Oracle数据库升级前必要的准备工作
Oracle数据库升级前必要的准备工作Oracle数据库升级前必要的准备工作
Oracle数据库升级前必要的准备工作
 
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
探索 ISTIO 新型 DATA PLANE 架構 AMBIENT MESH - GOLANG TAIWAN GATHERING #77 X CNTUG
 
Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南Coreseek/Sphinx 全文检索实践指南
Coreseek/Sphinx 全文检索实践指南
 
PostgreSQL Search
PostgreSQL SearchPostgreSQL Search
PostgreSQL Search
 

Mais de José Lin

2023 COSCUP - Whats new in PostgreSQL 16
2023 COSCUP - Whats new in PostgreSQL 162023 COSCUP - Whats new in PostgreSQL 16
2023 COSCUP - Whats new in PostgreSQL 16José Lin
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptxJosé Lin
 
PostgreSQL ecosystem
PostgreSQL ecosystemPostgreSQL ecosystem
PostgreSQL ecosystemJosé Lin
 
PostgreSQL 13 New Features
PostgreSQL 13 New FeaturesPostgreSQL 13 New Features
PostgreSQL 13 New FeaturesJosé Lin
 
The Digital Experiences with Postgresql in Taiwan
The Digital Experiences with Postgresql in TaiwanThe Digital Experiences with Postgresql in Taiwan
The Digital Experiences with Postgresql in TaiwanJosé Lin
 
What's new in PostgreSQL 11 ?
What's new in PostgreSQL 11 ?What's new in PostgreSQL 11 ?
What's new in PostgreSQL 11 ?José Lin
 
2016-12-15 NewSQL資料庫在IoT的應用 - iServDB
2016-12-15 NewSQL資料庫在IoT的應用 - iServDB2016-12-15 NewSQL資料庫在IoT的應用 - iServDB
2016-12-15 NewSQL資料庫在IoT的應用 - iServDBJosé Lin
 
開源技術建構訂票交易資料庫
開源技術建構訂票交易資料庫開源技術建構訂票交易資料庫
開源技術建構訂票交易資料庫José Lin
 

Mais de José Lin (8)

2023 COSCUP - Whats new in PostgreSQL 16
2023 COSCUP - Whats new in PostgreSQL 162023 COSCUP - Whats new in PostgreSQL 16
2023 COSCUP - Whats new in PostgreSQL 16
 
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
2022 COSCUP - Let's speed up your PostgreSQL services!.pptx
 
PostgreSQL ecosystem
PostgreSQL ecosystemPostgreSQL ecosystem
PostgreSQL ecosystem
 
PostgreSQL 13 New Features
PostgreSQL 13 New FeaturesPostgreSQL 13 New Features
PostgreSQL 13 New Features
 
The Digital Experiences with Postgresql in Taiwan
The Digital Experiences with Postgresql in TaiwanThe Digital Experiences with Postgresql in Taiwan
The Digital Experiences with Postgresql in Taiwan
 
What's new in PostgreSQL 11 ?
What's new in PostgreSQL 11 ?What's new in PostgreSQL 11 ?
What's new in PostgreSQL 11 ?
 
2016-12-15 NewSQL資料庫在IoT的應用 - iServDB
2016-12-15 NewSQL資料庫在IoT的應用 - iServDB2016-12-15 NewSQL資料庫在IoT的應用 - iServDB
2016-12-15 NewSQL資料庫在IoT的應用 - iServDB
 
開源技術建構訂票交易資料庫
開源技術建構訂票交易資料庫開源技術建構訂票交易資料庫
開源技術建構訂票交易資料庫
 

PostgreSQL 10 New Features

  • 1. PostgreSQL 10 New Feature @ COSCUP 2017 Taiwan PostgreSQL User Group 林宗禧
  • 2. Outline • About Me • History: PostgreSQL前世今生 • PostgreSQL 10 新特性 • PostgreSQL Ecosystem • 台灣PostgreSQL使用者社群 2Taiwan PostgreSQL User Group2017/8/11
  • 3. About Me • 我是林宗禧 (José Lin) – 自Hadoop/HBase入門OSS • 工作在研究分散式資料庫系統 – 熟PG與MongoDB – 接觸多種NoSQL/NewSQL • 成為PostgreSQL愛好者 – '13年起拜訪國內PG愛好者、認識日本JPUG – '17年起著手PG社群 (感謝許多PG前輩& JPUG幫忙!!) 2017/8/11 3Taiwan PostgreSQL User Group
  • 4. History: PostgreSQL前世今生 1973 Ingres 1985 Post-Ingres Postgres 1994 Postgres95 42017/8/11 •與Eugene Wong在UC Berkeley共同開發類似於 IBM System R 的DB。 •免費散佈Ingres代碼, 1980年止發行了1000份。 基於Ingres商業化: •1984年 Informix •1980-90年 Sybase Michael Stonebraker •1985年著手“後-Ingres” 計畫,稱為 “Postgres” 基於Postgres商業化: •1990年成立Illustra,後 被Informix 併購 基於Ingres商業化: •1987年 NonStop SQL •1992年 Sybase 賣給微 軟變為Microsoft SQL Server Andrew Yu & Jolly Chen •1994年Andrew Yu和 Jolly Chen在UC Berkeley,增加SQL直譯 器,發布Postgres95。 •1996年計畫改名為 PostgreSQL。
  • 5. History: PostgreSQL前世今生 1996 PostgreSQL 6 2000 PostgreSQL 7 2005 PostgreSQL 8 52017/8/11 •PostgreSQL第一次發行, 版本為6.0。 •透過Internet組成一組來 自世界各地的開發者。 •2001年Command Prompt, Inc.釋出 Mammoth PostgreSQL 套件並且贊助支援社群。 基於Postgres商業化: •2000年Red Hat投資籌 組Great Bridge公司來 商業化PostgreSQL。 •2001年因市場狀況不佳 Great Bridge倒閉。 •2005年11月昇陽宣布支援 PostgreSQL。 •2006年6月Solaris 10包含 PostgreSQL一起發布。 •8.0版在效能、管理、為運 已達24/7水準。 基於Postgres商業化: •2005年EnterpriseDB (移 轉Oracle)、 Greenplum (資料倉儲、商業智慧) 投入 商業化。 1999年6月JPUG成立 台灣建置大型PG案例
  • 6. History: PostgreSQL前世今生 2010 PostgreSQL 9 2011~2016 PostgreSQL 9.1~9.6 2017 PostgreSQL 10 Taiwan PostgreSQL User Group 62017/8/11 •Streaming Replication •Hot Standby •64-bit Windows •FDW •GiST index •JSON、JSONB •Materialized Views •UPSERT 基於Postgres商業化: •2015年Pivotal開源 Greenplum。 •10之後的版號不會有第三 碼,下次版號為11 2017年6月TWPUG成立
  • 7. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) 2. 邏輯複製(Logical Replication) 3. 平行查詢強化 (Parallel Queries) 4. FDW強化(Additional FDW Push-Down) 5. 多節點同步寫入 (Quorum Commit) 6. ID欄位功能(Identity columns ) 7. 安全認證提升(SCRAM-SHA-256 Authentication) 8. 多欄位關聯(Multi-column Correlation Statistics) 9. 全文檢索支持 JSON 和 JSONB 10. 新增 pg_hba_file_rules 項目 11. 新增 pg_stat_activity 監控項目 12. 新增 pg_sequence 系統表 13. Row層級的安全政策(Row-level security) 14. Schema 預設權限(Default permissions on schemas) Taiwan PostgreSQL User Group 72017/8/11
  • 8. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 82017/8/11 -- 建立主表 CREATE TABLE tbl( a INT, b VARCHAR(10)); -- 建立繼承表 CREATE TABLE tbl_1 (CHECK( a <= 1000 ) ) INHERITS (tbl); CREATE TABLE tbl_2 (CHECK( a <= 10000 AND a >1000 )) INHERITS (tbl); CREATE TABLE tbl_3 ( CHECK( a <= 100000 AND a >10000 )) INHERITS (tbl); 原始步驟: 1. 建立主表、繼承表 2. 建立 function 3. 建立 Trigger
  • 9. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 92017/8/11 -- 建立function CREATE OR REPLACE FUNCTION tbl_part_tg() RETURNS TRIGGER AS $$ BEGIN IF ( NEW. a <= 1000 ) THEN INSERT INTO tbl_1 VALUES (NEW.*); ELSIF ( NEW. a > 1000 and NEW.a <= 10000 ) THEN INSERT INTO tbl_2 VALUES (NEW.*); ...(略,同上 tbl_3, tbl_4) ELSE RAISE EXCEPTION 'data out of range!'; END IF; RETURN NULL; END; $$ LANGUAGE plpgsql;
  • 10. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 102017/8/11 -- 建立trigger CREATE TRIGGER insert_tbl_part_tg BEFORE INSERT ON tbl FOR EACH ROW EXECUTE PROCEDURE tbl_part_tg(); -- EXPLAIN postgres=# explain select *from tbl where a =11111; QUERY PLAN ------------------------------------------------------------- Append (cost=0.00..24.50 rows=7 width=42) -> Seq Scan on tbl (cost=0.00..0.00 rows=1 width=42) Filter: (a = 11111) -> Seq Scan on tbl_3 (cost=0.00..24.50 rows=6 width=42) Filter: (a = 11111) (5 rows)
  • 11. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 112017/8/11 PG 9.6 • 建立主表、繼承表 • 建立 function • 建立 Trigger PG 10 • 建立主表 • PARTITION BY • LIST • RANGE • HASH • 建立繼承表 • 建立 function • 建立 Trigger (Not yet)
  • 12. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 122017/8/11 -- Partition by LIST CREATE TABLE list_parted (a int) PARTITION BY LIST (a); CREATE TABLE part_1 PARTITION OF list_parted FOR VALUES IN (1); CREATE TABLE part_2 PARTITION OF list_parted FOR VALUES IN (2); CREATE TABLE part_3 PARTITION OF list_parted FOR VALUES IN (3); CREATE TABLE part_4 PARTITION OF list_parted FOR VALUES IN (4); CREATE TABLE part_5 PARTITION OF list_parted FOR VALUES IN (5);
  • 13. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 132017/8/11 -- Partition by LIST postgres=# insert into list_parted values(32); --failed ERROR: no partition of relation "list_parted" found for row DETAIL: Failing row contains (32). postgres=# insert into part_1 values(1); INSERT 0 1 postgres=# insert into part_1 values(2);--failed ERROR: new row for relation "part_1" violates partition constraint DETAIL: Failing row contains (2).
  • 14. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 142017/8/11 -- Partition by LIST postgres=# explain select *from list_parted where a =1; QUERY PLAN --------------------------------------------------------------- -- Append (cost=0.00..41.88 rows=14 width=4) -> Seq Scan on list_parted (cost=0.00..0.00 rows=1 width=4) Filter: (a = 1) -> Seq Scan on part_1 (cost=0.00..41.88 rows=13 width=4) Filter: (a = 1) (5 rows) ※ 主表不會查
  • 15. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 152017/8/11 -- Partition by RANGE CREATE TABLE range_parted ( a int ) PARTITION BY RANGE (a); CREATE TABLE range_parted1 PARTITION OF range_parted FOR VALUES from (1) TO (1000); CREATE TABLE range_parted2 PARTITION OF range_parted FOR VALUES FROM (1000) TO (10000); CREATE TABLE range_parted3 PARTITION OF range_parted FOR VALUES FROM (1000) TO (100000); postgres=# insert into range_parted values(123); INSERT 0 1 postgres=# insert into range_parted1 values(456); INSERT 0 1
  • 16. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 162017/8/11 -- Partition by RANGE postgres=# explain select *from range_parted where a=32425; QUERY PLAN --------------------------------------------------------------- ------ Append (cost=0.00..41.88 rows=14 width=4) -> Seq Scan on range_parted (cost=0.00..0.00 rows=1 width=4) Filter: (a = 32425) -> Seq Scan on range_parted3 (cost=0.00..41.88 rows=13 width=4) Filter: (a = 32425) (5 rows) ※ 主表不會查
  • 17. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 172017/8/11 -- ATTACH postgres=# alter table range_parted ATTACH PARTITION range_parted5 FOR VALUES FROM (100000) TO (1000000); ALTER TABLE -- DETACH postgres=# alter table range_parted DETACH PARTITION range_parted5 ; ALTER TABLE
  • 18. PostgreSQL 10 新特性 1. 資料表分割強化 (Table Partitioning) Taiwan PostgreSQL User Group 182017/8/11 33.65 22.2 55.85 185.75 488.9 172 171 0 0 40.2 3.5 4.72 133.5 133.8 傳統方式 PG10 單位:秒
  • 19. PostgreSQL 10 新特性 2. 邏輯複製(Logical Replication) • 由2ndQuadrant回饋的功能 • PG9.0-9.6:Streaming Replication – WAL Replication • PG10:Logical Replication – Table 層級顆粒細度 (以前需用Londiste3 實現) Taiwan PostgreSQL User Group 192017/8/11
  • 20. PostgreSQL 10 新特性 2. 邏輯複製(Logical Replication) Taiwan PostgreSQL User Group 202017/8/11 $ psql -p 5432 -c "ALTER SYSTEM SET wal_level = 'logical';" test $ pg_ctl -p 5432 restart $ psql -p 5432 test CREATE TABLE test (x INT PRIMARY KEY); INSERT INTO test VALUES (1); CREATE PUBLICATION mypub FOR TABLE test; $ psql -p 5433 test CREATE TABLE test (x INT PRIMARY KEY); CREATE SUBSCRIPTION mysub CONNECTION 'dbname=test port=5432' PUBLICATION mypub; Cluseter 1 Cluseter 2
  • 21. PostgreSQL 10 新特性 2. 邏輯複製(Logical Replication) • 邏輯複製允許: – 資料表層級的顆粒細度 – 可從多台主機複製到集中的一台主機 – 可以從單一資料表複製到多台主機 Taiwan PostgreSQL User Group 212017/8/11 INSERT INTO test VALUES (2); SELECT * FROM test; 1 SELECT * FROM test; 1 2 Cluseter 1 Cluseter 2
  • 22. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) • PG 9.6 已有此功能 • PG 10 開始支援以下平行查詢 – B-tree index scans – Bitmap heap scans – Merge joins – Procedural Languages Taiwan PostgreSQL User Group 222017/8/11
  • 23. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) Taiwan PostgreSQL User Group 232017/8/11 -- 建立測試資料表 create table test_big1(id int4 primary key, create_time timestamp without time zone default clock_timestamp(), name character varying(32)); -- 插入 1000萬筆資料 insert into test_big1(id,name) select n,n*random()*10000 from generate_series(1,10000000) n ; -- 資料插入後的資料表 postgres=# select * from test_big1 limit 3; id | create_time | name ----+----------------------------+------------------ 1 | 2017-05-21 16:02:24.921751 | 2298.13809040934 2 | 2017-05-21 16:02:24.922051 | 7580.18649183214 3 | 2017-05-21 16:02:24.922064 | 24218.4893181548 (3 rows)
  • 24. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) Taiwan PostgreSQL User Group 242017/8/11 -- 查詢 max_parallel_workers postgres=# show max_parallel_workers; max_parallel_workers ---------------------- 4 (1 row) -- 在啟動平行查詢的狀態執行EXPLAIN postgres=# explain analyze select count(*) from test_big1 where id <1000000 ;
  • 25. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) Taiwan PostgreSQL User Group 252017/8/11 QUERY PLAN --------------------------------------------------------------- Finalize Aggregate (cost=18576.59..18576.60 rows=1 width=8) (actual time=73.362..73.362 rows=1 loops=1) -> Gather (cost=18576.17..18576.58 rows=4 width=8) (actual time=73.200..73.355 rows=5 loops=1) Workers Planned: 4 Workers Launched: 4 -> Partial Aggregate (cost=17576.17..17576.18 rows=1 width=8) (actual time=68.992..68.992 rows=1 loops=5) -> Parallel Index Only Scan using test_big1_pkey on test_big1 (cost=0.43..16947.37 rows=251523 width=0) (actual time=0.053..54.343 rows=200000 loops=5) Index Cond: (id < 1000000) Heap Fetches: 174195 Planning time: 0.105 ms Execution time: 74.572 ms (10 rows)
  • 26. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) Taiwan PostgreSQL User Group 262017/8/11 -- 關閉 max_parallel_workers postgres=# set max_parallel_workers=0; SET -- 關閉平行查詢後執行EXPLAIN postgres=# explain analyze select count(*) from test_big1 where id <1000000 ;
  • 27. PostgreSQL 10 新特性 3. 平行查詢強化 (Parallel Queries) Taiwan PostgreSQL User Group 272017/8/11 QUERY PLAN --------------------------------------------------------------- Finalize Aggregate (cost=18576.59..18576.60 rows=1 width=8) (actual time=257.585..257.585 rows=1 loops=1) -> Gather (cost=18576.17..18576.58 rows=4 width=8) (actual time=257.579..257.579 rows=1 loops=1) Workers Planned: 4 Workers Launched: 0 -> Partial Aggregate (cost=17576.17..17576.18 rows=1 width=8) (actual time=257.251..257.251 rows=1 loops=1) -> Parallel Index Only Scan using test_big1_pkey on test_big1 (cost=0.43..16947.37 rows=251523 width=0) (actual time=0.042..183.384 rows=999999 loops=1) Index Cond: (id < 1000000) Heap Fetches: 999999 Planning time: 0.102 ms Execution time: 257.717 ms (10 rows) ※ 大約 74.572 ms 的4倍
  • 28. PostgreSQL 10 新特性 4. FDW強化(Additional FDW Push-Down) • PG9.1/9.2 FDW:SELECT • PG9.3 FDW:INSERT/UPDATE/DELETE • PG9.6 FDW:JOINS / SORTS Taiwan PostgreSQL User Group 282017/8/11 PG FDW TBL Foreign Server/Data Source FTBL
  • 29. PostgreSQL 10 新特性 4. FDW強化(Additional FDW Push-Down) • PG10 FDW: Query Push-Down (Aggregation) Taiwan PostgreSQL User Group 292017/8/11 PG 9.x FDW FTBL TBL All data explain (analyze on,verbose on) select flag,count(*) from ft_test_fdw3 group by flag; Table, Where PG 10 FDW FTBL TBL Selected data Table, Where, Group by, Count() … Rows: 100,000 9.6 Time: 441.758 ms 10 Time: 19.928 ms
  • 30. PostgreSQL 10 新特性 4. FDW強化(Additional FDW Push-Down) Taiwan PostgreSQL User Group 302017/8/11 QUERY PLAN --------------------------------------------------------------- ------------------------------------------ Sort (cost=211.41..211.91 rows=200 width=12) (actual time=19.662..19.662 rows=3 loops=1) Output: flag, (count(*)) Sort Key: ft_test_fdw3.flag Sort Method: quicksort Memory: 25kB -> Foreign Scan (cost=129.25..203.76 rows=200 width=12) (actual time=19.648..19.649 rows=3 loops=1) Output: flag, (count(*)) Relations: Aggregate on (francs.ft_test_fdw3) Remote SQL: SELECT flag, count(*) FROM francs.test_fdw3 GROUP BY flag Planning time: 0.212 ms Execution time: 19.928 ※ Push-down : count(*)、Group By ※ 9.6: rows=100K
  • 31. PostgreSQL 10 新特性 5.多節點同步寫入 (Quorum Commit) • 有兩種方式: – FIRST num_sync (standby_name [, ...]) – ANY num_sync (standby_name [, ...]) • num_sync 是指需要同步複製的備節點個數。 • standby_name 是指同步複製備節點的名稱。 Taiwan PostgreSQL User Group 312017/8/11 postgres=# ALTER SYSTEM SET synchronous_standby_names = 'FIRST 1 (s1, s2)'; postgres=# ALTER SYSTEM SET synchronous_standby_names = 'ANY 1 (s1, s2)' ; postgres=# ALTER SYSTEM SET synchronous_standby_names = 'ANY 2 (s1, s2, s3)';
  • 32. PostgreSQL 10 新特性 6. ID欄位功能(Identity columns ) • Identity 需要與 Serial 互相比較 Taiwan PostgreSQL User Group 322017/8/11 -- 示範Serial:複製 t_serial 資料表至 t_serial2 postgres=# create table t_serial2 (like t_serial including all); CREATE TABLE postgres=# d t_serial2 Table "francs.t_serial2" Column | Type | Collation | Nullable | Default --------+---------+-----------+----------+--------------------- id | integer | | not null | nextval('t_serial_id_seq'::regclass) name | text | | | Indexes: "t_serial2_pkey" PRIMARY KEY, btree (id)
  • 33. PostgreSQL 10 新特性 6. ID欄位功能(Identity columns ) • Identity 需要與 Serial 互相比較 Taiwan PostgreSQL User Group 332017/8/11 -- 示範Identity:複製 t_identity資料表至 t_identity2 postgres=# create table t_identity2 ( like t_identity including all); CREATE TABLE postgres=# d t_identity2 Table "francs.t_identity2" Column | Type | Collation | Nullable | Default --------+--------+-----------+----------+---------------------- ------------ id | bigint | | not null | generated by default as identity name | text | | | Indexes: "t_identity2_pkey" PRIMARY KEY, btree (id)
  • 34. PostgreSQL 10 新特性 7. 安全認證提升(SCRAM-SHA-256 Authentication) • SCRAM-SHA-256 提供比 MD5 更安全的密 碼驗證功能: – 降低連線重複率 (連線超過64K,MD5會產生機率 50% 的重複。) – 被偷取的hashed密碼更難被重複使用 – 更難使用暴力破解法 Taiwan PostgreSQL User Group 342017/8/11
  • 35. PostgreSQL 10 新特性 其他: • 多欄位關聯(Multi-column Correlation Statistics) • 全文檢索支持 JSON 和 JSONB • 新增 pg_hba_file_rules 項目 • 新增 pg_stat_activity 監控項目 • 新增 pg_sequence 系統表 • Row層級的安全政策(Row-level security) • Schema 預設權限(Default permissions on schemas) Taiwan PostgreSQL User Group 352017/8/11
  • 36. PostgreSQL 10 新特性 • 參考資料/來源: – http://www.postgres.cn/news/viewone/1/247 – http://francs3.blog.163.com/blog/ – https://momjian.us/main/writings/pgsql/feat ures.pdf Taiwan PostgreSQL User Group 362017/8/11
  • 37. PostgreSQL Ecosystem • Slony-I / Pgpool-II (multiple replication) • Pglogical / Postgres-BDR (logical replication) • Postgres-XC / XL / X2 (Distributed) • PgBouncer ( pooling ) • Barman (backup / recovery) • PG-Storm (GPU computing) • PgAdmin / PhpPgAdmin / PgStudio… (GUI) • Lots of FDW tools… Taiwan PostgreSQL User Group 372017/8/11
  • 38. 台灣PostgreSQL使用者社群 • Github: pgsql-tw • FB: @pgsqlTaiwan (from 郭朝益先生) Taiwan PostgreSQL User Group 382017/8/11
  • 39. 台灣PostgreSQL使用者社群 • 為何要成立PostgreSQL台灣使用者社群? – 惦惦吃三碗公 – 愛好者有點難找 – 高手藏身在民間 • 這個社群可以做什麼? – 彼此交流、經驗分享 – 共同研究、合作開創新專案 – 或是任何跟PostgreSQL有關的都可以~ Taiwan PostgreSQL User Group 392017/8/11
  • 40. Thank you. 歡迎加入台灣PostgreSQL使用者社群 Github : pgsql-tw Website : pgsql-tw.github.io Facebook : @pgsqlTaiwan Taiwan PostgreSQL User Group 402017/8/11

Notas do Editor

  1. Postgres是個歷史悠久的RDB(幾乎是RDB開始時,這個OpenSource專案就跟著開始了) 但是一直都有更上時代的腳步 Postgres 前身是Ingres 發源於UC Berkeley 由 Michael Stonebraker跟他夥伴