v2
This commit is contained in:
parent
ba69e7c774
commit
a92d68fa35
@ -236,3 +236,12 @@ SET node_local_interface = (
|
||||
WHERE if_name = 'node2_local'
|
||||
AND if_nodeid = 13534
|
||||
);
|
||||
|========================|
|
||||
|WAY TO ENTER PSQL SHELL |
|
||||
|========================|
|
||||
psql "postgresql://postgres_exporter:postgres@172.16.10.178:5444/postgres"
|
||||
|
||||
|=============================|
|
||||
|ENDPONT TO DETECT A DEAD LOCK|
|
||||
|=============================|
|
||||
http://172.16.10.178:9188/metrics | grep -i deadlock
|
||||
66
lockDetectServer.py
Normal file
66
lockDetectServer.py
Normal file
@ -0,0 +1,66 @@
|
||||
import time
|
||||
import psycopg2
|
||||
|
||||
DB_CONFIG = {
|
||||
"host": "172.16.10.178",
|
||||
"port": 5444,
|
||||
"dbname": "postgres",
|
||||
"user": "postgres_exporter",
|
||||
"password": "postgres"
|
||||
}
|
||||
|
||||
while True:
|
||||
try:
|
||||
conn = psycopg2.connect(**DB_CONFIG)
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("""
|
||||
SELECT
|
||||
pid,
|
||||
usename,
|
||||
now() - query_start AS duration,
|
||||
query
|
||||
FROM pg_stat_activity
|
||||
WHERE state = 'active'
|
||||
AND pid <> pg_backend_pid()
|
||||
AND query_start < now() - interval '30 seconds';
|
||||
""")
|
||||
|
||||
long_queries = cur.fetchall()
|
||||
|
||||
if long_queries:
|
||||
print("WARNING: Long-running queries detected")
|
||||
|
||||
for row in long_queries:
|
||||
print(row)
|
||||
else:
|
||||
print("OK: No long-running queries")
|
||||
|
||||
cur.execute("""
|
||||
SELECT
|
||||
pid,
|
||||
usename,
|
||||
query,
|
||||
pg_blocking_pids(pid)
|
||||
FROM pg_stat_activity
|
||||
WHERE cardinality(pg_blocking_pids(pid)) > 0;
|
||||
""")
|
||||
|
||||
blockers = cur.fetchall()
|
||||
|
||||
if blockers:
|
||||
print("WARNING: Blocking sessions detected")
|
||||
for row in blockers:
|
||||
print(row)
|
||||
else:
|
||||
print("OK: No blocking sessions")
|
||||
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
print("ERROR:", e)
|
||||
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user