Files
article/postgresql_and_edb/postgresql锁表查询.md
2022-11-01 23:53:13 +08:00

46 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```postgresql
SELECT locker.pid,
pc.relname,
locker.mode,
locker_act.application_name,
least(query_start,xact_start) start_time,
locker_act.state,
CASE
WHEN granted='f' THEN
'wait_lock'
WHEN granted='t' THEN
'get_lock'
END lock_satus,current_timestamp - least(query_start,xact_start) AS runtime,
locker_act.query
FROM pg_locks locker,pg_stat_activity locker_act, pg_class pc
WHERE locker.pid=locker_act.pid
AND NOT locker.pid=pg_backend_pid()
AND application_name<>'pg_statsinfod'
AND locker.relation = pc.oid
AND pc.reltype<>0 --and pc.relname='t'
ORDER BY runtime desc;
SELECT pg_terminate_backend(14448)
```
```postgresql
-- 查看表的总大小,包括索引大小
select pg_size_pretty(pg_total_relation_size('test'));
-- 以KBMBGB的方式来查看表大小
select pg_size_pretty(pg_relation_size('test'));
-- 查看最大连接数
show max_connections;
-- 查看当前连接数
SELECT COUNT(*) from pg_stat_activity;
```