PostgreSQL DBA(1) - 数据库参数设置#1

本节简单介绍了可用于诊断PostgreSQL数据库参数设置的工具:postgresqltuner,包括该工具的安装和基本使用。

一、安装

在REHL系列下安装:

#该工具基于Perl语言开发,首先安装Perl相关的开发包
#yum -y install perl-DBD-Pg
#获取工具包
#cd /tmp
#wget -O postgresqltuner.pl https://postgresqltuner.pl
#chmod +x postgresqltuner.pl

二、基本使用

在数据库主机上执行:

[xdb@localhost bin]$ /tmp/postgresqltuner.pl --host=localhost --user xdb --database testdb
postgresqltuner.pl version 1.0.0
Connecting to localhost:5432 database testdb with user xdb...
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[OK]      User used for report have super rights
=====  OS information  =====
[INFO]    OS: linux Version: 3.10.0-514.16.1.el7.x86_64 Arch: x86_64-linux-thread-multi
[INFO]    OS total memory: 732.52 MB
[BAD]     Memory overcommitment is allowed on the system. This can lead to OOM Killer killing some PostgreSQL process, which will cause a PostgreSQL server restart (crash recovery)
[INFO]    sysctl vm.overcommit_ratio=50
[BAD]     vm.overcommit_ratio is too small, you will not be able to use more than 50*RAM+SWAP for applications
[INFO]    Currently used I/O scheduler(s) : deadline
=====  General instance informations  =====
-----  Version  -----
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[OK]      You are using last 11beta2
-----  Uptime  -----
[INFO]    Service uptime :  09m 53s
[WARN]    Uptime is less than 1 day. postgresqltuner.pl result may not be accurate
-----  Databases  -----
[INFO]    Database count (except templates): 2
[INFO]    Database list (except templates): postgres testdb
-----  Extensions  -----
[INFO]    Number of activated extensions : 1
[INFO]    Activated extensions : plpgsql
[WARN]    Extensions pg_stat_statements is disabled
-----  Users  -----
[OK]      No user account will expire in less than 7 days
[OK]      No user with password=username
[OK]      Password encryption is enabled
-----  Connection information  -----
[INFO]    max_connections: 100
[INFO]    current used connections: 6 (6.00%)
[INFO]    3 are reserved for super user (3.00%)
[INFO]    Average connection age :  08m 14s
[WARN]    Average connection age is less than 10 minutes. Use a connection pooler to limit new connection/seconds
-----  Memory usage  -----
[INFO]    configured work_mem: 4.00 MB
[INFO]    Using an average ratio of work_mem buffers by connection of 150% (use --wmp to change it)
[INFO]    total work_mem (per connection): 6.00 MB
[INFO]    shared_buffers: 128.00 MB
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[INFO]    Track activity reserved size : 0.00 B
[WARN]    maintenance_work_mem is less or equal default value. Increase it to reduce maintenance tasks time
[INFO]    Max memory usage :
      shared_buffers (128.00 MB)
    + max_connections * work_mem * average_work_mem_buffers_per_connection (100 * 4.00 MB * 150 / 100 = 600.00 MB)
    + autovacuum_max_workers * maintenance_work_mem (3 * 64.00 MB = 192.00 MB)
    + track activity size (0.00 B)
    = 920.00 MB
[INFO]    effective_cache_size: 4.00 GB
[INFO]    Size of all databases : 33.19 MB
[WARN]    shared_buffer is too big for the total databases size, memory is lost
[INFO]    PostgreSQL maximum memory usage: 125.59% of system RAM
[BAD]     Max possible memory usage for PostgreSQL is more than system total RAM. Add more RAM or reduce PostgreSQL memory
[INFO]    max memory+effective_cache_size is 684.76% of total RAM
[WARN]    the sum of max_memory and effective_cache_size is too high, the planer can find bad plans if system cache is smaller than expected
-----  Logs  -----
[OK]      log_hostname is off : no reverse DNS lookup latency
[WARN]    log of long queries is desactivated. It will be more difficult to optimize query performances
[OK]      log_statement=none
-----  Two phase commit  -----
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[OK]      Currently no two phase commit transactions
-----  Autovacuum  -----
[OK]      autovacuum is activated.
[INFO]    autovacuum_max_workers: 3
-----  Checkpoint  -----
[WARN]    checkpoint_completion_target(0.5) is low
-----  Disk access  -----
[OK]      fsync is on
[OK]      synchronize_seqscans is on
-----  WAL  -----
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
-----  Planner  -----
[OK]      costs settings are defaults
[BAD]     some plan features are disabled : enable_partitionwise_aggregate,enable_partitionwise_join
=====  Database information for database testdb  =====
-----  Database size  -----
[INFO]    Database testdb total size : 11.44 MB
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[INFO]    Database testdb tables size : 8.38 MB (73.22%)
[INFO]    Database testdb indexes size : 3.06 MB (26.78%)
-----  Tablespace location  -----
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[OK]      No tablespace in PGDATA
-----  Shared buffer hit rate  -----
[INFO]    shared_buffer_heap_hit_rate: 99.03%
[INFO]    shared_buffer_toast_hit_rate: 0.00%
[INFO]    shared_buffer_tidx_hit_rate: 28.57%
[INFO]    shared_buffer_idx_hit_rate: 98.43%
[OK]      Shared buffer idx hit rate is very good
-----  Indexes  -----
[OK]      No invalid indexes
Argument "11beta2" isn't numeric in numeric gt (>) at /tmp/postgresqltuner.pl line 818.
[OK]      No unused indexes
-----  Procedures  -----
[OK]      No procedures with default costs

=====  Configuration advices  =====
-----  checkpoint  -----
[MEDIUM] Your checkpoint completion target is too low. Put something nearest from 0.8/0.9 to balance your writes better during the checkpoint interval
-----  extension  -----
[LOW] Enable pg_stat_statements to collect statistics on all queries (not only queries longer than log_min_duration_statement in logs)
-----  sysctl  -----
[URGENT] set vm.overcommit_memory=2 in /etc/sysctl.conf and run sysctl -p to reload it. This will disable memory overcommitment and avoid postgresql killed by OOM killer.

执行完毕,该工具会输出一系列的参数调整建议.这些参数的含义和为何如此调整,下节讨论.

三、小结

本节简单介绍了postgresqltuner.pl工具的安装和基本使用,有兴趣的可以查看该工具postgresqltuner的源码并进行改进.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,463评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,868评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,213评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,666评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,759评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,725评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,716评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,484评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,928评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,233评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,393评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,073评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,718评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,308评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,538评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,338评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,260评论 2 352

推荐阅读更多精彩内容