繁体   English   中英

PostgreSQL。 缓慢准备交易并提交准备

[英]PostgreSQL. Slow Prepare Transaction and Commit Prepared

我刚遇到一个奇怪的问题。 我在pgfourine中做了一个报告,发现我的XA事务开始非常缓慢。 准备事务和提交准备的总和从13.2秒中占12.55秒。 但为什么?

#####  Overall statistics  #####

Number of unique normalized queries: 175
Number of queries:     268,772
Total query duration:  13m2s


#####  Queries by type  #####

SELECT:    116493     43.3%
INSERT:     15926      5.9%
UPDATE:      7935      3.0%
DELETE:      4923      1.8%


#####  Queries that took up the most time (N)  #####

1) 6m32s - 26,338 - COMMIT PREPARED ''
--
2) 6m23s - 25,972 - PREPARE TRANSACTION ''
--
3) 0.6s - 3,848 - update avatar set lfa_position=NULL where Id=0
.....
7) 0.3s - 21,514 - COMMIT
.....

我有一个理论,但没有证据。.我的光盘慢,我关闭了sync_commit。 也许PostgreSQL必须在“准备事务”期间进行fsync,即使sync_commit已关闭?

fsync = on 
synchronous_commit = off

有任何想法吗?

更新

与相同的测试

fsync = off
synchronous_commit = off


#####  Overall statistics  #####

Number of unique normalized queries: 155
Number of queries:     186,838
Total query duration:  6.6s


#####  Queries by type  #####

SELECT:     84367     45.2%
INSERT:      9197      4.9%
UPDATE:      5486      2.9%
DELETE:      2996      1.6%


#####  Queries that took up the most time (N)  #####

1) 1.8s - 16,972 - PREPARE TRANSACTION ''
--
2) 1.1s - 16,965 - COMMIT PREPARED ''
--
3) 0.4s - 2,904 - update avatar set lfa_position=NULL where Id=0
--
4) 0.2s - 16,031 - COMMIT

看起来fsync花费了大量时间,但不是所有时间。 16k提交-0.2秒,17k准备+提交2.9秒。

悲剧。 看起来XA提交花费的时间是本地提交时间的15倍,并且没有考虑到sync_commit设置。 fsync = off对于生产用途不安全。 因此,如果我想使用XA事务,则必须谨慎使用它,并使用具有高IOPS的优质SSD驱动器。

立即同步PREPARE TRANSACTION的理论是正确的,并且在文档中提到:

摘录自http://www.postgresql.org/docs/9.1/static/wal-async-commit.html

支持两阶段提交的命令(例如PREPARE TRANSACTION)也总是同步的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM