PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图
发表于:2024-12-13 作者:千家信息网编辑
千家信息网最后更新 2024年12月13日,这篇文章主要介绍"PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图",在日常操作中,相信很多人在PostgreSQL中怎么在pg_locks和pg
千家信息网最后更新 2024年12月13日PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图
这篇文章主要介绍"PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图",在日常操作中,相信很多人在PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
显示阻塞信息的视图:
CREATE OR REPLACE VIEW vw_lockinfoASSELECT blocked_locks.pid AS blocked_pid, blocked_activity.usename AS blocked_user, blocking_locks.pid AS blocking_pid, blocking_activity.usename AS blocking_user, blocked_activity.query AS blocked_statement, blocking_activity.query AS current_statement_in_blocking_process FROM pg_catalog.pg_locks blocked_locks JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid JOIN pg_catalog.pg_locks blocking_locks ON blocking_locks.locktype = blocked_locks.locktype AND blocking_locks.DATABASE IS NOT DISTINCT FROM blocked_locks.DATABASE AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid AND blocking_locks.pid != blocked_locks.pid JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid WHERE NOT blocked_locks.GRANTED;[local]:5432 pg12@testdb=# CREATE OR REPLACE VIEW vw_lockinfopg12@testdb-# ASpg12@testdb-# SELECT blocked_locks.pid AS blocked_pid,pg12@testdb-# blocked_activity.usename AS blocked_user,pg12@testdb-# blocking_locks.pid AS blocking_pid,pg12@testdb-# blocking_activity.usename AS blocking_user,pg12@testdb-# blocked_activity.query AS blocked_statement,pg12@testdb-# blocking_activity.query AS current_statement_in_blocking_processpg12@testdb-# FROM pg_catalog.pg_locks blocked_lockspg12@testdb-# JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pidpg12@testdb-# JOIN pg_catalog.pg_locks blocking_locks pg12@testdb-# ON blocking_locks.locktype = blocked_locks.locktypepg12@testdb-# AND blocking_locks.DATABASE IS NOT DISTINCT FROM blocked_locks.DATABASEpg12@testdb-# AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relationpg12@testdb-# AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.pagepg12@testdb-# AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuplepg12@testdb-# AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxidpg12@testdb-# AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionidpg12@testdb-# AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classidpg12@testdb-# AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objidpg12@testdb-# AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubidpg12@testdb-# AND blocking_locks.pid != blocked_locks.pidpg12@testdb-# pg12@testdb-# JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pidpg12@testdb-# WHERE NOT blocked_locks.GRANTED;CREATE VIEWTime: 131.424 ms[local]:5432 pg12@testdb=# select * from vw_lockinfo;-[ RECORD 1 ]-------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------blocked_pid | 2184blocked_user | pg12blocking_pid | 2863blocking_user | pg12blocked_statement | update t_lock set id = 1000 where id = 1;current_statement_in_blocking_process | select pid,locktype,relation::regclass,mode,page,tuple,virtualxid,transactionid,virtualtransaction,granted,fastpath from pg_locks where relation='t_lock'::regclass;Time: 21.032 ms
显示带有时间属性的locks
CREATE OR REPLACE VIEW vw_lockinfo_timeASSELECT a.datname, l.relation::regclass, l.transactionid, l.mode, l.GRANTED, a.usename, a.query, a.query_start, age(now(), a.query_start) AS "age", a.pidFROM pg_stat_activity aJOIN pg_locks l ON l.pid = a.pidORDER BY a.query_start;[local]:5432 pg12@testdb=# CREATE OR REPLACE VIEW vw_lockinfo_timepg12@testdb-# ASpg12@testdb-# SELECT a.datname,pg12@testdb-# l.relation::regclass,pg12@testdb-# l.transactionid,pg12@testdb-# l.mode,pg12@testdb-# l.GRANTED,pg12@testdb-# a.usename,pg12@testdb-# a.query,pg12@testdb-# a.query_start,pg12@testdb-# age(now(), a.query_start) AS "age",pg12@testdb-# a.pidpg12@testdb-# FROM pg_stat_activity apg12@testdb-# JOIN pg_locks l ON l.pid = a.pidpg12@testdb-# ORDER BY a.query_start;CREATE VIEWTime: 17.799 ms[local]:5432 pg12@testdb=# select * from vw_lockinfo_time;-[ RECORD 1 ]-+---------------------------------------------------------------------------------------------------------------------------------------------------------------------datname | testdbrelation | t_locktransactionid | mode | RowExclusiveLockgranted | tusename | pg12query | select pid,locktype,relation::regclass,mode,page,tuple,virtualxid,transactionid,virtualtransaction,granted,fastpath from pg_locks where relation='t_lock'::regclass;query_start | 2019-08-13 15:32:23.139886+08age | 00:11:29.095421pid | 2863...
到此,关于"PostgreSQL中怎么在pg_locks和pg_stat_activity两张基表基础上创建的视图"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
视图
基础
学习
更多
帮助
实用
接下来
信息
属性
文章
方法
时间
理论
知识
篇文章
网站
资料
跟着
问题
好用
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
桂林中程软件开发有限公司
t3修改数据库
十大品评网络技术
云服务器如何切回桌面
百世快软件开发行业税收
解码服务器连接几个显示器
局长讲网络安全宣传周
日活10万网站服务器
武大网络安全学硕复试科目
湖南省计算机网络技术专业专升本
为什么软件开发没有任何监管
磁盘数据恢复软件开发
苏州net软件开发价格表
网络安全法突出亮点是
ps4为什么连接不了2k服务器
北京网络技术有限公司待遇
上海付正网络技术有限公司老板
服务器维护的工作
linux nfs服务器
临沂傲宇网络技术公司招聘
依网打金网络技术
福建闪电出行网络技术有限公司
浅谈计算机网络安全的现状及对策
金融类软件开发公司
商务谈判软件开发案例
科技公司是不是互联网
石家庄软件开发就找驰宇网络
广东游爱网络技术
数据库设计入门经典 下载
企业租用国外服务器