ITPub博客

首页 > 数据库 > Oracle > Postgres Query tuning

Postgres Query tuning

原创 Oracle 作者:fiona8953 时间:2016-09-21 15:55:19 0 删除 编辑

Index
PK --> unique, not null
Unique contrast --> unique, nullable

Facing a problem with a QUERY:
WHERE/JOIN clause

ANALYZE : DB/table/column
Auto vacuum 
select name,setting from pg_settings;
autovacuum_analyze_scale_factor: Modification (insert/update/delete rows) reach 
autovacuum_analyze_threshold
NOTE:
\d+ [table_name]
\d+ [table_name]\h alter
ALTER TABLE [table_name] SET (autovacuum_analyze_scale_factor = 0.0); ALTER TABLE novell.disk_data SET (autovacuum_analyze_threshold = 1000);
autovacuum_vacuum_scale_factor
autovacuum_vacuum_threshold
Note:
For worker table, set vacuum_scale_factor large.
Check the last vacuum:
\d pg_stat_all_tables
n_live_tup : 
n_dead_tup : delete row in table
select relname,last_vacuum,last_autovacuum,last_analyze,last_autoanalyze from pg_stat_all_tables;
last_vacuum: manule 
last_autovacuum: 
EXPLAIN [QUERY]
Inline image 1
rows: table's total row number
EXPLAIN ANALYZE [QUERY]
explain analyze select * from personne p inner join adresse a on p.id=a.personne_id;
Inline image 2
Note: 
Explain : cost=143.25..2047108.50 rows=6101020 width=5714
Actual: actual time=0.015..116954.297 rows=6106693 loops=1
When actual is differ with explain, we need to do a statics collect.
Inline image 3
Trigger take time may be larger than the query execute time much, need to disable trigger then let business cs to insert separate.
EXPLAIN ANALYZE query, if it needs many memory (insert / hash join / order by) --> increase work_mem to 24M
vim /u01/app/postgres/data/crm03/postgresql.conf
#TBY-20160318::work_mem = 1MB               # min 64kB
work_mem = 8MB              # min 64kB

pgtune.leopard.in.ua
Inline image 4
Huge Page Setup
kernel.shmmax=12884901888 kernel.shmall=3145728

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26477398/viewspace-2125278/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: HTTP 教程
请登录后发表评论 登录
全部评论

注册时间:2014-06-13

  • 博文量
    284
  • 访问量
    222494