This commit is contained in:
George 2026-08-28 17:25:55 +05:30
parent ba69e7c774
commit a92d68fa35
2 changed files with 76 additions and 1 deletions

View File

@ -235,4 +235,13 @@ SET node_local_interface = (
FROM spock.node_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
View 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)