--执行时间超过 10s 的语句
select * from pg_stat_activity where state<>'idle' and Now()-query_start > interval '10 s'
--锁表
SELECT * FROM pg_stat_activity where datname='bms' and wait_event_type='Lock'--limit 10
--将进程杀掉
select pg_cancel_backend("死锁那条数据的pid值")
--运行完后,再次刷新这个表,sql就可顺利执行。
select pg_cancel_backend(27280);
--数据库 整理 查询(查询死元组情况)
SELECT
c.relname 表名,
(current_setting('autovacuum_analyze_threshold')::NUMERIC(12,4))+(current_setting('autovacuum_analyze_scale_factor')::NUMERIC(12,4))*reltuples AS 自动分析阈值,
(current_setting('autovacuum_vacuum_threshold')::NUMERIC(12,4))+(current_setting('autovacuum_vacuum_scale_factor')::NUMERIC(12,4))*reltuples AS 自动清理阈值,
reltuples::DECIMAL(19,0) 活元组数,
n_dead_tup::DECIMAL(19,0) 死元组数
FROM
pg_class c
LEFT JOIN pg_stat_all_tables d
ON C.relname = d.relname
WHERE
c.relname LIKE'tb%' AND reltuples > 0
AND n_dead_tup > (current_setting('autovacuum_analyze_threshold')::NUMERIC(12,4))+(current_setting('autovacuum_analyze_scale_factor')::NUMERIC(12,4))*reltuples;
--修改密码--重建索引
alter user bms_select with password 'QD6eXed6'
alter user bms_report with password 'Ucj1UW3BriA2KlW'
REINDEX INDEX idx_business_time
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。