def get_lock_statistics()

in postgresql_metrics/postgres_queries.py [0:0]


def get_lock_statistics(conn):
    sql = ("SELECT locktype, granted, count(*) FROM pg_locks GROUP BY locktype, granted")
    results = query(conn, sql)
    total = [0, 0]
    lock_stats = {}
    for lock_type, granted, count in results:
        if lock_type not in lock_stats:
            lock_stats[lock_type] = [0, 0]
        lock_stats[lock_type][granted] = count
        total[granted] += count
    return [lock_stats, total]