postgresql事务并发的测试脚本 [英] Test script for transaction concurrency for postgresql

查看:378
本文介绍了postgresql事务并发的测试脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PostgreSQL中测试事务并发的一些变体,因为我需要一个脚本,这将强制两个事务在完全相同的时间开始。不需要手动干预的东西)
任何想法?

I would like to test some variants of transaction concurrency in PostgreSQL and for that I need a script which would force two transaction to start at exactly the same time. Something that does not requires manual intervention ;) Any ideas?

推荐答案

c $ c> LOCK ,设置您的事务,然后通过回滚获得锁的事务来释放锁定。有关此方法的详细信息,请参见此先前答案及其链接。虽然我演示了它使用三个 psql 会话,它同样可行的bash协同进程,一个Python脚本使用 psycopg2 multiprocessing threading 模块等等。 更新:实际上这里是一个例子

You can homebrew this by taking a LOCK on a table, setting up your transactions, then releasing the lock by rolling back the transaction that got the lock. See this prior answer and its links for details on this approach. While I demonstrated it using three psql sessions it's equally viable to do it with bash co-processes, a Python script using psycopg2 and the multiprocessing or threading modules, etc. Fairly simple to do. Update: In fact here's an example I just wrote in python3.

对于更复杂的测试,抓住PostgreSQL源代码,并使用 src /测试/隔离,它允许您编写执行命令的复杂排序的配方。它不支持使用 PGXS (虽然这样的支持可能是相当微不足道的添加)构建,所以你必须编译整个PostgreSQL源代码树,但这是足够快。

For more sophisticated tests, grab the PostgreSQL source code and use the "isolationtester" tool in src/test/isolation which lets you write recipes that do complex orderings of commands. It doesn't support being built with PGXS (though such support would probably be pretty trivial to add) so you have to compile the whole PostgreSQL source tree, but that's quick enough. It'll run against your existing PostgreSQL so there's no need to install the one you compiled.

请参阅 src / test / isolation / README 。文档在地上有点薄,因为它是一个内部测试工具,但现有的测试用例应该可以帮助你开始。随意改善它,以满足您的需要和提交修补程序:)

See src/test/isolation/README for more about the isolationtester tool. The docs are a little thin on the ground since it's an internal testing tool, but the existing tests cases should help you get started. Feel free to improve it to meet your needs and submit patches :)

这篇关于postgresql事务并发的测试脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆