1、让锁表时间变小,对于每个SQL语句统计结果,存放到临时表,然后将临时表的数据插入目标表中。
例子:CREATE TEMPORARY TABLE test as select * from pg_stat_activity order by usename;
2、vaccum 优化
CREATE TABLE new_table (LIKE old_table)
AS SELECT * FROM old_table ORDER BY myixcolumn;
DROP old_table;
ALTER TABLE new_table RENAME TO old_table;
CREATE INDEX myixcolumn_ix ON old_table;
VACUUM ANALYZE old_table;//不管VACCUM怎么使用,这个命令最好每天晚上调用一次
实验:VACUUM ANALYZE 对表作用后的结果。时间结果如下图所示: