Search

9-2-2. pg_locks

-- [SQL-9-2-2-a] A 세션 -- A 세션 -- 1. A 세션 pid 확인(3248) SELECT pg_backend_pid(); -- 2. A 세션 명시적 트랜잭션 시작 BEGIN; -- 3. ACC1 잔액 변경 UPDATE startdbpg.ms_acc t1 SET bal_amt = bal_amt - 500 WHERE t1.acc_no = 'ACC1'; -- 5. 변경된 데이터 반영 COMMIT; -- B 세션(모니터링) -- 4. 락 조회(1에서 조회한 A 세션의 pid를 사용) SELECT t1.pid ,t1.locktype ,t1.relation ,t2.relname ,t1.mode ,t1.granted ,t1.transactionid ,t1.virtualxid FROM pg_locks t1 LEFT OUTER JOIN pg_class t2 ON (t2.oid = t1.relation) WHERE t1.pid = 3248 -- 1에서 조회한 A 세션 pid ORDER BY t1.pid ,t1.locktype ,t1.relation;
SQL
복사
-- [SQL-9-2-2-a] B 세션 -- B 세션(모니터링) -- 4. 락 조회(1에서 조회한 A 세션의 pid를 사용) SELECT t1.pid ,t1.locktype ,t1.relation ,t2.relname ,t1.mode ,t1.granted ,t1.transactionid ,t1.virtualxid FROM pg_locks t1 LEFT OUTER JOIN pg_class t2 ON (t2.oid = t1.relation) WHERE t1.pid = 3248 -- 1에서 조회한 A 세션 pid ORDER BY t1.pid ,t1.locktype ,t1.relation;
SQL
복사