PostgreSQL 9.4 new feature: Replication slots

本文涉及的产品
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
简介:
PostgreSQL 9.4 新增的一个特写, replication slot, 
1. 可以被流复制的sender节点用于自动识别它xlog中的数据在下面的standby中是否还需要(例如, standby断开连接后, 还未接收到的XLOG), 如果还需要的话, 那么这些XLOG将不会被删除.
2. 对于tuples, 如果standby 配置了hot_standby_feedback=on, 那么发生冲突的tuples将不会在sender端被vacuum回收. 用于规避冲突.
配置比较简单, 需要在sender端使用函数创建slot, 在receiver端配置对应的slot name即可.
Introduce replication slots.
author	Robert Haas <rhaas@postgresql.org>	
	Sat, 1 Feb 2014 03:45:17 +0000 (22:45 -0500)
committer	Robert Haas <rhaas@postgresql.org>	
	Sat, 1 Feb 2014 03:45:36 +0000 (22:45 -0500)
commit	858ec11858a914d4c380971985709b6d6b7dd6fc
tree	59eb508185cd8544c3485919a25dee15f3818c21	tree | snapshot
parent	5bdef38b8917cfbe206d14969c61a5d38fc822b6	commit | diff
Introduce replication slots.

Replication slots are a crash-safe data structure which can be created
on either a master or a standby to prevent premature removal of
write-ahead log segments needed by a standby, as well as (with
hot_standby_feedback=on) pruning of tuples whose removal would cause
replication conflicts.  Slots have some advantages over existing
techniques, as explained in the documentation.

In a few places, we refer to the type of replication slots introduced
by this patch as "physical" slots, because forthcoming patches for
logical decoding will also have slots, but with somewhat different
properties.

Andres Freund and Robert Haas


功能介绍请参考 : 
相关参数
postgresql.conf  - sender server config
max_replication_slots (integer)

Specifies the maximum number of replication slots (see Section 25.2.6 that the server can support. The default is zero. This parameter can only be set at server start. wal_level must be set to archive or higher to allow replication slots to be used. Setting it to a lower value than the number of currently existing replication slots will prevent the server from starting.

recovery.conf
+# If set, the PostgreSQL server will use the specified replication slot when
+# connecting to the primary via streaming replication to control resource
+# removal on the upstream node. This setting has no effect if primary_conninfo
+# is not set.
+#
+#primary_slotname = ''

相关函数, 视图

Table 9-67. Replication SQL Functions

Function Return Type Description
pg_create_physical_replication_slot(slotnametext, plugin text) (slotname text,xlog_positiontext) Creates a new physical replication slot named slotname. Streaming changes from a physical slot is only possible with the walsender protocol - see Section 48.3. Corresponds to the walsender protocol command CREATE_REPLICATION_SLOT ... PHYSICAL.
pg_drop_replication_slot(slotname text) (slotname text) Drops the physical or logical replication slot named slotname. Same as walsender protocol command DROP_REPLICATION_SLOT.

You can create a replication slot like this:

postgres=# SELECT * FROM pg_create_physical_replication_slot('node_a_slot');
  slotname   | xlog_position
-------------+---------------
 node_a_slot |

postgres=# SELECT * FROM pg_replication_slots;
  slot_name  | slot_type | datoid | database | active | xmin | restart_lsn
-------------+-----------+--------+----------+--------+------+-------------
 node_a_slot | physical  |      0 |          | f      |      |
(1 row)

To configure the standby to use this slot, primary_slotname should be configured in the standby's recovery.conf. Here is a simple example:

standby_mode = 'on'
primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
primary_slotname = 'node_a_slot'
流复制协议也做了相应的改进 : 

使用slot的好处 : 
1. 在没有replication slot这个特性以前, 有两种方法来保持standby需要的xlog, wal keep或者归档, 因为主节点不知道standby到底需要哪些XLOG信息, 配置一般需要较大的余量. slot可以解决这个浪费sender端存储wal空间的问题, 因为sender可以做到保留更精准的wal信息.
2. 配合standby节点的feedback使用, 可以避免vacuum带来的冲突.

[参考]
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
存储 关系型数据库 数据库
How to Optimize PostgreSQL Logical Replication
How to Optimize PostgreSQL Logical Replication
269 0
How to Optimize PostgreSQL Logical Replication
|
关系型数据库 PostgreSQL
PostgreSQL update returning NEW|OLD column value 在对账|购票|防纂改|原子操作中的妙用
标签 PostgreSQL , update , returning , NEW , OLD 背景 在数据库中更新记录时,有时为了对账,或者防纂改的目的,需要在更新后立即返回更新前和更新后的值。 例如以set bit为例,假设使用BIT串作为火车的每个位置,每个BIT代表一张票,0表示未售卖,1表示已售卖。 购票时,使用set bit=1的操作,为了确保不出现重复售票的问题,必须确保
2497 0
|
存储 NoSQL 关系型数据库
An Overview of PostgreSQL & MySQL Cross Replication
An Overview of PostgreSQL & MySQL Cross Replication
307 0
|
存储 缓存 关系型数据库
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(1)
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(1)
494 0
|
存储 SQL 算法
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(2)
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(2)
360 0
|
算法 关系型数据库 分布式数据库
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(3)
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(3)
294 0
|
Oracle 容灾 算法
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(4)
《PolarDB for PostgreSQL源码与应用实战》——PolarDB-PostgreSQL开源核心Feature介绍(4)
328 0
|
弹性计算 关系型数据库 PostgreSQL
PostgreSQL PostGIS 性能提升 - by new GEOS代码
标签 PostgreSQL , PostGIS , geos 背景 http://lin-ear-th-inking.blogspot.com/2019/02/betterfaster-stpointonsurface-for.html 使用GEOS新的代码,提升PostGIS重计算的函数性能。 The improved ST_PointOnSurface runs 13 times
856 0
|
关系型数据库 数据库 SQL
PostgreSQL Logical Replication
限制及特性 1、只支持普通表生效,不支持序列、视图、物化视图、外部表、分区表和大对象 2、只支持普通表的DML(INSERT、UPDATE、DELETE)操作,不支持truncate、DDL操作 3、需要同步的表必须设置REPLICA IDENTITY 不能为noting(默认值是default).
8913 0
|
SQL Web App开发 关系型数据库

推荐镜像

更多