好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁(yè) > 知識(shí)庫(kù) > Postgresql - 查看鎖表信息的實(shí)現(xiàn)

Postgresql - 查看鎖表信息的實(shí)現(xiàn)

熱門標(biāo)簽:海豐有多少商家沒(méi)有地圖標(biāo)注 地圖標(biāo)注和圖片名稱的區(qū)別 辦公外呼電話系統(tǒng) 漯河外呼電話系統(tǒng) 合肥公司外呼系統(tǒng)運(yùn)營(yíng)商 打電話智能電銷機(jī)器人授權(quán) 重慶自動(dòng)外呼系統(tǒng)定制 美容工作室地圖標(biāo)注 外呼調(diào)研系統(tǒng)

查看表鎖信息,是DBA常用的腳本之一。

實(shí)驗(yàn)環(huán)境:

CentOS 7

PG 10.4

先通過(guò)A窗口執(zhí)行

mytest=# begin;
BEGIN
mytest=# update t1 set col1 = 'a' where id =1 ;
UPDATE 1
mytest=#

打開(kāi)B窗口執(zhí)行

mytest=# begin;
BEGIN
mytest=# update t1 set col1 = 'b' where id =2;
UPDATE 1
mytest=# update t1 set col1 = 'b' where id =1;

等待了

說(shuō)明只鎖住了行,對(duì)于更新其他行沒(méi)有影響。

再打開(kāi)一個(gè)窗口查看信息

SELECT
a.datname,
locktype,
virtualtransaction,
transactionid,
nspname,
relname,
mode,
granted,
cast(date_trunc('second',query_start) AS timestamp) AS query_start
FROM
pg_locks
LEFT OUTER JOIN pg_class ON (pg_locks.relation = pg_class.oid)
LEFT OUTER JOIN pg_namespace ON (pg_namespace.oid = pg_class.relnamespace),
pg_stat_activity a
WHERE NOT pg_locks.pid = pg_backend_pid()
AND pg_locks.pid=a.pid;
datname | locktype | virtualtransaction | transactionid | nspname | relname | mode | granted | query_start
---------+---------------+--------------------+---------------+---------+---------+------------------+---------+---------------------
mytest | relation | 7/332 | | public | t1 | RowExclusiveLock | t | 2018-06-28 06:29:58
mytest | virtualxid | 7/332 | | | | ExclusiveLock | t | 2018-06-28 06:29:58
mytest | relation | 6/42 | | public | t1 | RowExclusiveLock | t | 2018-06-28 06:29:35
mytest | virtualxid | 6/42 | | | | ExclusiveLock | t | 2018-06-28 06:29:35
mytest | transactionid | 7/332 | 712 | | | ExclusiveLock | t | 2018-06-28 06:29:58
mytest | transactionid | 6/42 | 711 | | | ExclusiveLock | t | 2018-06-28 06:29:35
mytest | transactionid | 7/332 | 711 | | | ShareLock | f | 2018-06-28 06:29:58
mytest | tuple | 7/332 | | public | t1 | ExclusiveLock | t | 2018-06-28 06:29:58
(8 rows)

補(bǔ)充:如何查看PostgreSQL正在執(zhí)行的SQL以及鎖信息

查看當(dāng)前正在運(yùn)行的SQL

SELECT 
procpid, 
start, 
now() - start AS lap, 
current_query 
FROM 
(SELECT 
backendid, 
pg_stat_get_backend_pid(S.backendid) AS procpid, 
pg_stat_get_backend_activity_start(S.backendid) AS start, 
pg_stat_get_backend_activity(S.backendid) AS current_query 
FROM 
(SELECT pg_stat_get_backend_idset() AS backendid) AS S 
) AS S 
WHERE 
current_query > 'IDLE>' 
ORDER BY 
lap DESC; 
procpid:進(jìn)程id 
start:進(jìn)程開(kāi)始時(shí)間 
lap:經(jīng)過(guò)時(shí)間 
current_query:執(zhí)行中的sql 
怎樣停止正在執(zhí)行的sql 
SELECT pg_cancel_backend(進(jìn)程id); 
或者用系統(tǒng)函數(shù) 
kill -9 進(jìn)程id;

查看數(shù)據(jù)庫(kù)目前是否有鎖

-- 查看當(dāng)前事務(wù)鎖等待、持鎖信息的SQL
with  
t_wait as  
(  
 select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,  
 a.objid,a.objsubid,a.pid,a.virtualtransaction,a.virtualxid,a.transactionid,a.fastpath,  
 b.state,b.query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name  
  from pg_locks a,pg_stat_activity b where a.pid=b.pid and not a.granted  
),  
t_run as  
(  
 select a.mode,a.locktype,a.database,a.relation,a.page,a.tuple,a.classid,a.granted,  
 a.objid,a.objsubid,a.pid,a.virtualtransaction,a.virtualxid,a.transactionid,a.fastpath,  
 b.state,b.query,b.xact_start,b.query_start,b.usename,b.datname,b.client_addr,b.client_port,b.application_name  
  from pg_locks a,pg_stat_activity b where a.pid=b.pid and a.granted  
),  
t_overlap as  
(  
 select r.* from t_wait w join t_run r on  
 (  
  r.locktype is not distinct from w.locktype and  
  r.database is not distinct from w.database and  
  r.relation is not distinct from w.relation and  
  r.page is not distinct from w.page and  
  r.tuple is not distinct from w.tuple and  
  r.virtualxid is not distinct from w.virtualxid and  
  r.transactionid is not distinct from w.transactionid and  
  r.classid is not distinct from w.classid and  
  r.objid is not distinct from w.objid and  
  r.objsubid is not distinct from w.objsubid and  
  r.pid > w.pid  
 )  
),  
t_unionall as  
(  
 select r.* from t_overlap r  
 union all  
 select w.* from t_wait w  
)  
select locktype,datname,relation::regclass,page,tuple,virtualxid,transactionid::text,classid::regclass,objid,objsubid,  
string_agg(  
'Pid: '||case when pid is null then 'NULL' else pid::text end||chr(10)||  
'Lock_Granted: '||case when granted is null then 'NULL' else granted::text end||' , Mode: '||case when mode is null then 'NULL' else mode::text end||' , FastPath: '||case when fastpath is null then 'NULL' else fastpath::text end||' , VirtualTransaction: '||case when virtualtransaction is null then 'NULL' else virtualtransaction::text end||' , Session_State: '||case when state is null then 'NULL' else state::text end||chr(10)||  
'Username: '||case when usename is null then 'NULL' else usename::text end||' , Database: '||case when datname is null then 'NULL' else datname::text end||' , Client_Addr: '||case when client_addr is null then 'NULL' else client_addr::text end||' , Client_Port: '||case when client_port is null then 'NULL' else client_port::text end||' , Application_Name: '||case when application_name is null then 'NULL' else application_name::text end||chr(10)||  
'Xact_Start: '||case when xact_start is null then 'NULL' else xact_start::text end||' , Query_Start: '||case when query_start is null then 'NULL' else query_start::text end||' , Xact_Elapse: '||case when (now()-xact_start) is null then 'NULL' else (now()-xact_start)::text end||' , Query_Elapse: '||case when (now()-query_start) is null then 'NULL' else (now()-query_start)::text end||chr(10)||  
'SQL (Current SQL in Transaction): '||chr(10)|| 
case when query is null then 'NULL' else query::text end,  
chr(10)||'--------'||chr(10)  
order by  
 ( case mode  
  when 'INVALID' then 0  
  when 'AccessShareLock' then 1  
  when 'RowShareLock' then 2  
  when 'RowExclusiveLock' then 3  
  when 'ShareUpdateExclusiveLock' then 4  
  when 'ShareLock' then 5  
  when 'ShareRowExclusiveLock' then 6  
  when 'ExclusiveLock' then 7  
  when 'AccessExclusiveLock' then 8  
  else 0  
 end ) desc,  
 (case when granted then 0 else 1 end) 
) as lock_conflict 
from t_unionall  
group by  
locktype,datname,relation,page,tuple,virtualxid,transactionid::text,classid,objid,objsubid ; 

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • PostgreSQL 實(shí)現(xiàn)登錄及修改密碼操作
  • postgresql表死鎖問(wèn)題的排查方式
  • 基于postgresql數(shù)據(jù)庫(kù)鎖表問(wèn)題的解決
  • 基于postgresql行級(jí)鎖for update測(cè)試
  • Postgresql鎖機(jī)制詳解(表鎖和行鎖)
  • postgresql查詢鎖表以及解除鎖表操作
  • PostgreSQL中關(guān)閉死鎖進(jìn)程的方法
  • PostgreSQL用戶登錄失敗自動(dòng)鎖定的處理方案

標(biāo)簽:珠海 晉城 錦州 烏海 蚌埠 衡陽(yáng) 株洲 來(lái)賓

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Postgresql - 查看鎖表信息的實(shí)現(xiàn)》,本文關(guān)鍵詞  Postgresql,查看,鎖表,信息,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Postgresql - 查看鎖表信息的實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Postgresql - 查看鎖表信息的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 中文字幕精品久久久久人妻红杏1 中文字幕精品无码亚洲字幕乐视 亚洲色综合色少妇久久草草 | 色欲98久久综合国产精品三区| 日韩毛片一区二区三区| 国精产品自偷自偷综合下载| 国产91热爆TS人妖月奴足球直播| 八戒无码一区二区三区| 大洼县| 精品久久久中文字幕旡码| 99久久国产| 汉中市| 日韩啪啪网站| 国产a级片| 欧美成人大色情大片A级| 亚洲综合日本| 操批网站| 成人黄app福利网站大全| 97韩剧网韩剧在线观看| 我故意没有穿内裤让同桌c| 扒开她的小说让我?吮| 国产片婬乱一级毛片视频接吻| 国产精品视频人人做人人| 久久理论片迅播影院一级| 亚洲精品人成在线观看| gl浴室春药play张开腿百合| 啊灬啊灬啊快日出水了A片真人| yy6080私人伦理一级二级| 国产一级之生活片| 佸伦短篇小说| 中文字幕一区二区免费| 亚洲精品无码一级毛片乌克兰| 欧美情趣内衣丝袜A片| 国产又粗又猛又爽又黄的学生| 黄色小视频在线| 小婬妇水好多真紧奶头好硬| 性视频在线看| 完整欧美一级淫片免费看| 真人裸体做爰免费图片| 秘?韩H漫画网站漫画| 小男孩操大人| 丰满高耸的双乳| ijzzijzz精的女人美女|