Trong bài đăng này, tôi đang chia sẻ một tập lệnh để tìm danh sách các truy vấn bị chặn và bế tắc bởi các truy vấn chặn khác của Máy chủ cơ sở dữ liệu Greenplum.
Bạn có thể truy cập bài viết dưới đây để biết thêm về lock, deadlock, block và timeout là gì?
Database Theory: Timeout, Lock, Block và Deadlock trong hệ thống cơ sở dữ liệu là gì?
Nếu hai truy vấn đang cố gắng lấy cùng một tài nguyên, cả hai đều phụ thuộc vào nhau và tạo ra trạng thái khối trước rồi sau đó là deadlock.
Trong tập lệnh bên dưới, bạn có thể tìm thấy danh sách các truy vấn bị chặn và các truy vấn trình chặn có giá trị tuổi thời gian.
Bạn có thể tìm thấy process_id của truy vấn trình chặn mà chúng tôi có thể loại bỏ để tránh tình trạng bế tắc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | SELECT kl.pid as blocking_pid ,ka.usename as blocking_user ,ka.current_query as blocking_query ,bl.pid as blocked_pid ,a.usename as blocked_user ,a.current_query as blocked_query ,to_char(age(now(), a.query_start),'HH24h:MIm:SSs') as age FROM pg_catalog.pg_locks bl JOIN pg_catalog.pg_stat_activity a ON bl.pid = a.procpid JOIN pg_catalog.pg_locks kl ON bl.locktype = kl.locktype and bl.database is not distinct from kl.database and bl.relation is not distinct from kl.relation and bl.page is not distinct from kl.page and bl.tuple is not distinct from kl.tuple and bl.transactionid is not distinct from kl.transactionid and bl.classid is not distinct from kl.classid and bl.objid is not distinct from kl.objid and bl.objsubid is not distinct from kl.objsubid and bl.pid <> kl.pid JOIN pg_catalog.pg_stat_activity ka ON kl.pid = ka.procpid WHERE kl.granted and not bl.granted ORDER BY a.query_start; |