postgresql 自治事务(autonomous_transaction)的介绍之三 pragma autonomous_transaction

os: centos 7.4
db: postgresql 10.10

自治事务,它将记录独立于数据库主线事务运行,并且不关心主线事务的最终结果。

oracle 通过 添加 pragma autonomous_transaction 实现自治事务,可以很安全的实现写日志的安全性。参考
<<Oracle 的自治事务 AUTONOMOUS TRANSACTION>>

那么 postgresql 如何处理自治事务了?

目前有如下三种方式:
pg_background
dblink
pragma autonomous_transaction

其中 pragma autonomous_transaction 是通过一个补丁的方式实现,先介绍下这个.

版本

# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core) 
# 
# su - postgres
Last login: Sat Oct 26 22:55:25 CST 2019 on pts/0
$
$ psql -c "select version();"
                                                 version                                                  
----------------------------------------------------------------------------------------------------------
 PostgreSQL 10.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)

下载安装补丁

源码安装

# yum install patch
# su - postgres
$ wget https://ftp.postgresql.org/pub/source/v10.10/postgresql-10.10.tar.gz
$ tar -zxvf ./postgresql-10.10.tar.gz
$ 
$ wget https://www.postgresql.org/message-id/attachment/45863/autonomous.patch
$ cd postgresql-10.10
$ patch -p1 < ../autonomous.patch 

也是一堆的报错,这个patch 现在也没有下文了,估计也是没有下文了。

同时也有个问题,如果是 yum 安装的 postgresql 怎么安装这个补丁了?

# yum list installed |grep -i postgresql
postgresql10.x86_64                10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-contrib.x86_64        10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-debuginfo.x86_64      10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-devel.x86_64          10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-docs.x86_64           10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-libs.x86_64           10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-odbc.x86_64           11.01.0000-1PGDG.rhel7              @pgdg10  
postgresql10-plperl.x86_64         10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-plpython.x86_64       10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-pltcl.x86_64          10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-server.x86_64         10.10-1PGDG.rhel7                   @pgdg10  
postgresql10-tcl.x86_64            2.4.0-1.rhel7                       @pgdg10  
postgresql10-tcl-debuginfo.x86_64  2.3.1-1.rhel7                       @pgdg10  
postgresql10-test.x86_64           10.10-1PGDG.rhel7                   @pgdg10 

参考:
https://www.postgresql.org/message-id/attachment/45863/autonomous.patch
https://www.postgresql-archive.org/autonomous-transactions-tp5918627p5918645.html
https://my.oschina.net/innovation/blog/782635

http://blog.dalibo.com/2016/08/19/Autonoumous_transactions_support_in_PostgreSQL.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据库人生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值