解决postgresql数据库锁表问题
2021/12/14 19:18:26
本文主要是介绍解决postgresql数据库锁表问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
查询是否锁表了
create view viewlocks as SELECT waiting.locktype AS waiting_locktype, --可锁定对象的类型:relation, extend, page, tuple,transactionid, virtualxid,object, userlock, advisory waiting.relation::regclass AS waiting_table, --等待表 waiting_stm.query AS waiting_query, --等待查询 waiting.mode AS waiting_mode, --这个进程持有的或者是期望持有的锁模式 waiting.pid AS waiting_pid, --持有或者等待这个锁的服务器进程的进程ID ,如果锁是被一个预备事务持有的,那么为空 other.locktype AS previous_locktype, --当前锁的上层锁 other.relation::regclass AS previous_table, other_stm.query AS previous_query, other_stm.state AS previous_state, other.mode AS Previous_mode, other.pid AS previous_pid, --等待该pid完成(kill) other.GRANTED AS previous_granted --如果持有锁,为真,如果等待锁,为假 FROM pg_catalog.pg_locks AS waiting JOIN pg_catalog.pg_stat_activity AS waiting_stm ON ( waiting_stm.pid = waiting.pid ) JOIN pg_catalog.pg_locks AS other ON ( ( waiting."database" = other."database" AND waiting.relation = other.relation ) OR waiting.transactionid = other.transactionid ) JOIN pg_catalog.pg_stat_activity AS other_stm ON ( other_stm.pid = other.pid ) WHERE NOT waiting.GRANTED AND waiting.pid <> other.pid; select * from viewlocks;
如果查询到了结果,表示该表被锁 则需要释放锁定
select pg_cancel_backend(pid) select pg_terminate_backend(pid)
这篇关于解决postgresql数据库锁表问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-05快速清空 PostgreSQL 数据库中的所有表格,让你的数据库重新焕然一新!
- 2024-01-04在PostgreSQL中创建角色:判断角色是否存在并创建
- 2023-05-16PostgreSQL一站式插件推荐 -- pg_enterprise_views
- 2022-11-22PostgreSQL 实时位置跟踪
- 2022-11-22如何将PostgreSQL插件移植到openGauss
- 2022-11-11PostgreSQL:修改数据库用户的密码
- 2022-11-06Windows 环境搭建 PostgreSQL 物理复制高可用架构数据库服务
- 2022-10-27Windows 环境搭建 PostgreSQL 逻辑复制高可用架构数据库服务
- 2022-10-11PostgreSql安装(Windows10版本)
- 2022-09-13PostgreSQL-Network Address类型操作和函数