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