Skip to content

Commit f4bcac2

Browse files
committedMar 9, 2024
new doc
1 parent f545e51 commit f4bcac2

File tree

4 files changed

+246
-0
lines changed

4 files changed

+246
-0
lines changed
 

‎202403/20240309_01.md

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
## PostgreSQL 17 preview - Add support for `DEFAULT` in `ALTER TABLE .. SET ACCESS METHOD`
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2024-03-09
8+
9+
### 标签
10+
PostgreSQL , PolarDB , DuckDB , table access method , default_table_access_method
11+
12+
----
13+
14+
## 背景
15+
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=d61a6cad6418f643a5773352038d0dfe5d3535b8
16+
17+
```
18+
Add support for DEFAULT in ALTER TABLE .. SET ACCESS METHOD
19+
20+
author Michael Paquier <michael@paquier.xyz>
21+
Fri, 8 Mar 2024 00:31:52 +0000 (09:31 +0900)
22+
committer Michael Paquier <michael@paquier.xyz>
23+
Fri, 8 Mar 2024 00:31:52 +0000 (09:31 +0900)
24+
commit d61a6cad6418f643a5773352038d0dfe5d3535b8
25+
tree 10791cac8cc32610b5784768d966b2eaa0109f67 tree
26+
parent 4f8c1e7aaf11c42fa658eeab9baef0a035e76fe2 commit | diff
27+
Add support for DEFAULT in ALTER TABLE .. SET ACCESS METHOD
28+
29+
This option can be used to switch a relation to use the access method
30+
set by default_table_access_method when running the command.
31+
32+
This has come up when discussing the possibility to support setting
33+
pg_class.relam for partitioned tables (left out here as future work),
34+
while being useful on its own for relations with physical storage as
35+
these must have an access method set.
36+
37+
Per suggestion from Justin Pryzby.
38+
39+
Author: Michael Paquier
40+
Reviewed-by: Justin Pryzby
41+
Discussion: https://postgr.es/m/ZeCZ89xAVFeOmrQC@pryzbyj2023
42+
```
43+
44+
例子
45+
```
46+
+-- DEFAULT access method
47+
+BEGIN;
48+
+SET LOCAL default_table_access_method TO heap2;
49+
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
50+
+SELECT amname FROM pg_class c, pg_am am
51+
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
52+
+ amname
53+
+--------
54+
+ heap2
55+
+(1 row)
56+
+
57+
+SET LOCAL default_table_access_method TO heap;
58+
+ALTER TABLE heaptable SET ACCESS METHOD DEFAULT;
59+
+SELECT amname FROM pg_class c, pg_am am
60+
+ WHERE c.relam = am.oid AND c.oid = 'heaptable'::regclass;
61+
+ amname
62+
+--------
63+
+ heap
64+
+(1 row)
65+
+
66+
+ROLLBACK;
67+
```
68+
69+
70+
#### [期望 PostgreSQL|开源PolarDB 增加什么功能?](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216")
71+
72+
73+
#### [PolarDB 开源数据库](https://openpolardb.com/home "57258f76c37864c6e6d23383d05714ea")
74+
75+
76+
#### [PolarDB 学习图谱](https://www.aliyun.com/database/openpolardb/activity "8642f60e04ed0c814bf9cb9677976bd4")
77+
78+
79+
#### [购买PolarDB云服务折扣活动进行中, 55元起](https://www.aliyun.com/activity/new/polardb-yunparter?userCode=bsb3t4al "e0495c413bedacabb75ff1e880be465a")
80+
81+
82+
#### [PostgreSQL 解决方案集合](../201706/20170601_02.md "40cff096e9ed7122c512b35d8561d9c8")
83+
84+
85+
#### [德哥 / digoal's Github - 公益是一辈子的事.](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
86+
87+
88+
#### [About 德哥](https://github.com/digoal/blog/blob/master/me/readme.md "a37735981e7704886ffd590565582dd0")
89+
90+
91+
![digoal's wechat](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
92+

‎202403/20240309_02.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
## PostgreSQL 17 preview - 增加GUC standby_slot_names , 保证这些standby已接收并flush所有逻辑slot向下游发送逻辑数据对应的WAL
2+
3+
### 作者
4+
digoal
5+
6+
### 日期
7+
2024-03-09
8+
9+
### 标签
10+
PostgreSQL , PolarDB , DuckDB , 逻辑复制 , 切换 , 堵塞wal sender
11+
12+
----
13+
14+
## 背景
15+
PostgreSQL 自从16版本开始支持standby开启逻辑复制, 17版本对这个功能进行了进一步的更新, 例如primary节点支持将逻辑复制slot的LSN状态同步给standby, 以便在数据库出现primary-standby HA 切换后新的primary下游逻辑subscriber可以不多不少的继续从slot订阅数据.
16+
17+
[《PostgreSQL 17 preview - Add a new slot sync worker to synchronize logical slots》](../202402/20240223_01.md)
18+
19+
[《PostgreSQL 17 preview - sync logical replication slot LSN, Failover & Switchover》](../202402/20240214_02.md)
20+
21+
[《PostgreSQL 17 preview - 支持逻辑复制槽failover to 流复制standby节点. `pg_create_logical_replication_slot(... failover = true|false ...)`](../202401/20240126_01.md)
22+
23+
[《PostgreSQL 16 preview - standby 支持 logical decoding》](../202304/20230410_07.md)
24+
25+
本文提到的patch Introduce a new GUC 'standby_slot_names' 就是要让数据库主从正常切换可以保证切换后新的primary下游逻辑subscriber可以不多不少的继续从slot订阅数据.
26+
27+
原理:
28+
- wal sender在向下游发送逻辑日志信息前, 必须保证在standby_slot_names中的standby已经接收并flush了逻辑日志对应的WAL.
29+
- 所以不要随意配置standby_slot_names, 最好是性能好、网络好、稳定的standby配置在里面, 否则逻辑复制容易出现堵塞或较大delay.
30+
31+
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=bf279ddd1c28ce0251446ee90043a4cb96e5db0f
32+
```
33+
Introduce a new GUC 'standby_slot_names'.
34+
35+
author Amit Kapila <akapila@postgresql.org>
36+
Fri, 8 Mar 2024 02:40:45 +0000 (08:10 +0530)
37+
committer Amit Kapila <akapila@postgresql.org>
38+
Fri, 8 Mar 2024 02:40:45 +0000 (08:10 +0530)
39+
commit bf279ddd1c28ce0251446ee90043a4cb96e5db0f
40+
tree 642eb01435995795793fc61cedcc66949c824f1d tree
41+
parent 453c46873774219243501b8efc16b2b5a5e9d194 commit | diff
42+
Introduce a new GUC 'standby_slot_names'.
43+
44+
This patch provides a way to ensure that physical standbys that are
45+
potential failover candidates have received and flushed changes before
46+
the primary server making them visible to subscribers. Doing so guarantees
47+
that the promoted standby server is not lagging behind the subscribers
48+
when a failover is necessary.
49+
50+
The logical walsender now guarantees that all local changes are sent and
51+
flushed to the standby servers corresponding to the replication slots
52+
specified in 'standby_slot_names' before sending those changes to the
53+
subscriber.
54+
55+
Additionally, the SQL functions pg_logical_slot_get_changes,
56+
pg_logical_slot_peek_changes and pg_replication_slot_advance are modified
57+
to ensure that they process changes for failover slots only after physical
58+
slots specified in 'standby_slot_names' have confirmed WAL receipt for those.
59+
60+
Author: Hou Zhijie and Shveta Malik
61+
Reviewed-by: Masahiko Sawada, Peter Smith, Bertrand Drouvot, Ajin Cherian, Nisha Moond, Amit Kapila
62+
Discussion: https://postgr.es/m/514f6f2f-6833-4539-39f1-96cd1e011f23@enterprisedb.com
63+
```
64+
65+
```
66+
+#standby_slot_names = '' # streaming replication standby server slot names that
67+
+ # logical walsender processes will wait for
68+
```
69+
70+
```
71+
+ <varlistentry id="guc-standby-slot-names" xreflabel="standby_slot_names">
72+
+ <term><varname>standby_slot_names</varname> (<type>string</type>)
73+
+ <indexterm>
74+
+ <primary><varname>standby_slot_names</varname> configuration parameter</primary>
75+
+ </indexterm>
76+
+ </term>
77+
+ <listitem>
78+
+ <para>
79+
+ A comma-separated list of streaming replication standby server slot names
80+
+ that logical WAL sender processes will wait for. Logical WAL sender processes
81+
+ will send decoded changes to plugins only after the specified replication
82+
+ slots confirm receiving WAL. This guarantees that logical replication
83+
+ failover slots do not consume changes until those changes are received
84+
+ and flushed to corresponding physical standbys. If a
85+
+ logical replication connection is meant to switch to a physical standby
86+
+ after the standby is promoted, the physical replication slot for the
87+
+ standby should be listed here. Note that logical replication will not
88+
+ proceed if the slots specified in the
89+
+ <varname>standby_slot_names</varname> do not exist or are invalidated.
90+
+ Additionally, the replication management functions
91+
+ <link linkend="pg-replication-slot-advance">
92+
+ <function>pg_replication_slot_advance</function></link>,
93+
+ <link linkend="pg-logical-slot-get-changes">
94+
+ <function>pg_logical_slot_get_changes</function></link>, and
95+
+ <link linkend="pg-logical-slot-peek-changes">
96+
+ <function>pg_logical_slot_peek_changes</function></link>,
97+
+ when used with logical failover slots, will block until all
98+
+ physical slots specified in <varname>standby_slot_names</varname> have
99+
+ confirmed WAL receipt.
100+
+ </para>
101+
+ <para>
102+
+ The standbys corresponding to the physical replication slots in
103+
+ <varname>standby_slot_names</varname> must configure
104+
+ <literal>sync_replication_slots = true</literal> so they can receive
105+
+ logical failover slot changes from the primary.
106+
+ </para>
107+
+ </listitem>
108+
+ </varlistentry>
109+
```
110+
111+
```
112+
+ It's highly recommended that the said physical replication slot is named in
113+
+ <link linkend="guc-standby-slot-names"><varname>standby_slot_names</varname></link>
114+
+ list on the primary, to prevent the subscriber from consuming changes
115+
+ faster than the hot standby. Even when correctly configured, some latency
116+
+ is expected when sending changes to logical subscribers due to the waiting
117+
+ on slots named in
118+
+ <link linkend="guc-standby-slot-names"><varname>standby_slot_names</varname></link>.
119+
+ When <varname>standby_slot_names</varname> is utilized, the
120+
+ primary server will not completely shut down until the corresponding
121+
+ standbys, associated with the physical replication slots specified
122+
+ in <varname>standby_slot_names</varname>, have confirmed
123+
+ receiving the WAL up to the latest flushed position on the primary server.
124+
```
125+
126+
127+
128+
#### [期望 PostgreSQL|开源PolarDB 增加什么功能?](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216")
129+
130+
131+
#### [PolarDB 开源数据库](https://openpolardb.com/home "57258f76c37864c6e6d23383d05714ea")
132+
133+
134+
#### [PolarDB 学习图谱](https://www.aliyun.com/database/openpolardb/activity "8642f60e04ed0c814bf9cb9677976bd4")
135+
136+
137+
#### [购买PolarDB云服务折扣活动进行中, 55元起](https://www.aliyun.com/activity/new/polardb-yunparter?userCode=bsb3t4al "e0495c413bedacabb75ff1e880be465a")
138+
139+
140+
#### [PostgreSQL 解决方案集合](../201706/20170601_02.md "40cff096e9ed7122c512b35d8561d9c8")
141+
142+
143+
#### [德哥 / digoal's Github - 公益是一辈子的事.](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
144+
145+
146+
#### [About 德哥](https://github.com/digoal/blog/blob/master/me/readme.md "a37735981e7704886ffd590565582dd0")
147+
148+
149+
![digoal's wechat](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
150+

‎202403/readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### 文章列表
44
----
5+
##### 20240309_02.md [《PostgreSQL 17 preview - 增加GUC standby_slot_names , 保证这些standby已接收并flush所有逻辑slot向下游发送逻辑数据对应的WAL》](20240309_02.md)
6+
##### 20240309_01.md [《PostgreSQL 17 preview - Add support for `DEFAULT` in `ALTER TABLE .. SET ACCESS METHOD`](20240309_01.md)
57
##### 20240308_01.md [《老白说PG有隐藏的安全隐患, 真的吗?》](20240308_01.md)
68
##### 20240306_02.md [《和总监们一起聊聊数据库三害》](20240306_02.md)
79
##### 20240306_01.md [《PostgreSQL 17 preview - Add `--copy-file-range` option to `pg_upgrade`](20240306_01.md)

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ digoal's|PostgreSQL|文章|归类
9898

9999
### 所有文档如下
100100
----
101+
##### 202403/20240309_02.md [《PostgreSQL 17 preview - 增加GUC standby_slot_names , 保证这些standby已接收并flush所有逻辑slot向下游发送逻辑数据对应的WAL》](202403/20240309_02.md)
102+
##### 202403/20240309_01.md [《PostgreSQL 17 preview - Add support for `DEFAULT` in `ALTER TABLE .. SET ACCESS METHOD`》](202403/20240309_01.md)
101103
##### 202403/20240308_01.md [《老白说PG有隐藏的安全隐患, 真的吗?》](202403/20240308_01.md)
102104
##### 202403/20240306_02.md [《和总监们一起聊聊数据库三害》](202403/20240306_02.md)
103105
##### 202403/20240306_01.md [《PostgreSQL 17 preview - Add `--copy-file-range` option to `pg_upgrade`》](202403/20240306_01.md)

0 commit comments

Comments
 (0)
Please sign in to comment.