postgresql模拟死锁

news/2024/7/2 21:39:42 标签: SQL, database, postgresql

今天教你模拟postgresql实现死锁。

1准备

create table t1(id int primary key,info character varying(20));
insert into dss_pmart.t1 values(22,'hello');
insert into dss_pmart.t1 values(23,'world');

 

2模拟死锁

session1,在命令窗口A,输入以下信息:

--命令窗口A
begin;
select * from t1 where id =23 for update;

session2,在命令窗口B,输入以下信息:

--命令窗口B
begin;
select * from t1 where id in (22,23) for update;

session1,回到命令窗口A,继续输入以下信息:

--命令窗口A
select * from t1 where id =22 for update;

3模拟结果

ERROR: deadlock detected
SQL 状态: 40P01
详细:Process 3202 waits for ShareLock on transaction 19236551; blocked by process 3559.
Process 3559 waits for ShareLock on transaction 19236550; blocked by process 3202.
指导建议:See server log for query details.

 


http://www.niftyadmin.cn/n/1573808.html

相关文章

小程序input联想输入 多个侯选值

wxml文件如下: <view><input class="textinput" bindinput="bindinput" value="{{inputValue}}" placeholder="请输入内容" /> </view><scroll-view scroll-y="true" class="scrollview" …

什么是SAP GUI的client

我们用SAPGUI登录某个系统时&#xff0c;除了用户名和密码外&#xff0c;还要指定一个必填字段client&#xff1a; 这个client是什么东东&#xff1f; 看文档: SAP Client is the highest hierarchical organizational unit within an SAP system that contains master records…

mysql的索引:MyISAM和InnoDB的索引方式以及区别与选择

https://blog.csdn.net/LJFPHP/article/details/80029968 https://blog.csdn.net/qq_36071795/article/details/83956125

Python提取支付宝和微信支付二维码

本文首发于我的个人博客&#xff0c;更多 Python 和 django 开发教程&#xff0c;请访问 追梦人物的博客。 支付宝或者微信支付导出的收款二维码&#xff0c;除了二维码部分&#xff0c;还有很大一块背景图案&#xff0c;例如下面就是微信支付的收款二维码&#xff1a; 有时候我…

如果无法衡量,就无法优化提高

If you cant measure it, you cant improve it! 数据驱动产品决策、精细化运营&#xff0c;的前提是知道如何全方位的衡量自己的现状。 如果不能量化自己&#xff0c;所谓的提升也就无从谈起。

PAT A1030 动态规划

这道题是动态规划几大问题的其中一种&#xff0c;为最长回文子串问题&#xff1b; 动态规划个人来说&#xff0c;觉得最重要的就是建立状态转移方程。对于方程变量&#xff0c;我认为最重要的是有几个构成的关键变量&#xff1b; 对于这道题&#xff0c;我们着手于i~j个字符&am…

决策需要数据,数据需要分析,分析需要决策

生活无时不刻需要决策&#xff0c;决策需要数据来驱动&#xff0c;如何驱动&#xff0c;需要分析来帮忙&#xff0c;然而最具戏剧性的是&#xff1a;分析也是有策略的——分析也需要决策。 例子 举个例子&#xff0c;随着年龄的增长&#xff0c;见识了越来越的年轻人由于不看…