本篇内容介绍了“PostgreSQL中怎么安装和使用postgresqltuner工具”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

一、安装

在REHL系列下安装:

#该工具基于Perl语言开发,首先安装Perl相关的开发包#yum-yinstallperl-DBD-Pg#获取工具包#cd/tmp#wget-Opostgresqltuner.plhttps://postgresqltuner.pl#chmod+xpostgresqltuner.pl二、基本使用

在数据库主机上执行:

[xdb@localhostbin]$/tmp/postgresqltuner.pl--host=localhost--userxdb--databasetestdbpostgresqltuner.plversion1.0.0Connectingtolocalhost:5432databasetestdbwithuserxdb...Argument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[OK]Userusedforreporthavesuperrights=====OSinformation=====[INFO]OS:linuxVersion:3.10.0-514.16.1.el7.x86_64Arch:x86_64-linux-thread-multi[INFO]OStotalmemory:732.52MB[BAD]Memoryovercommitmentisallowedonthesystem.ThiscanleadtoOOMKillerkillingsomePostgreSQLprocess,whichwillcauseaPostgreSQLserverrestart(crashrecovery)[INFO]sysctlvm.overcommit_ratio=50[BAD]vm.overcommit_ratioistoosmall,youwillnotbeabletousemorethan50*RAM+SWAPforapplications[INFO]CurrentlyusedI/Oscheduler(s):deadline=====Generalinstanceinformations=====-----Version-----Argument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[OK]Youareusinglast11beta2-----Uptime-----[INFO]Serviceuptime:09m53s[WARN]Uptimeislessthan1day.postgresqltuner.plresultmaynotbeaccurate-----Databases-----[INFO]Databasecount(excepttemplates):2[INFO]Databaselist(excepttemplates):postgrestestdb-----Extensions-----[INFO]Numberofactivatedextensions:1[INFO]Activatedextensions:plpgsql[WARN]Extensionspg_stat_statementsisdisabled-----Users-----[OK]Nouseraccountwillexpireinlessthan7days[OK]Nouserwithpassword=username[OK]Passwordencryptionisenabled-----Connectioninformation-----[INFO]max_connections:100[INFO]currentusedconnections:6(6.00%)[INFO]3arereservedforsuperuser(3.00%)[INFO]Averageconnectionage:08m14s[WARN]Averageconnectionageislessthan10minutes.Useaconnectionpoolertolimitnewconnection/seconds-----Memoryusage-----[INFO]configuredwork_mem:4.00MB[INFO]Usinganaverageratioofwork_membuffersbyconnectionof150%(use--wmptochangeit)[INFO]totalwork_mem(perconnection):6.00MB[INFO]shared_buffers:128.00MBArgument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[INFO]Trackactivityreservedsize:0.00B[WARN]maintenance_work_memislessorequaldefaultvalue.Increaseittoreducemaintenancetaskstime[INFO]Maxmemoryusage:shared_buffers(128.00MB)+max_connections*work_mem*average_work_mem_buffers_per_connection(100*4.00MB*150/100=600.00MB)+autovacuum_max_workers*maintenance_work_mem(3*64.00MB=192.00MB)+trackactivitysize(0.00B)=920.00MB[INFO]effective_cache_size:4.00GB[INFO]Sizeofalldatabases:33.19MB[WARN]shared_bufferistoobigforthetotaldatabasessize,memoryislost[INFO]PostgreSQLmaximummemoryusage:125.59%ofsystemRAM[BAD]MaxpossiblememoryusageforPostgreSQLismorethansystemtotalRAM.AddmoreRAMorreducePostgreSQLmemory[INFO]maxmemory+effective_cache_sizeis684.76%oftotalRAM[WARN]thesumofmax_memoryandeffective_cache_sizeistoohigh,theplanercanfindbadplansifsystemcacheissmallerthanexpected-----Logs-----[OK]log_hostnameisoff:noreverseDNSlookuplatency[WARN]logoflongqueriesisdesactivated.Itwillbemoredifficulttooptimizequeryperformances[OK]log_statement=none-----Twophasecommit-----Argument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[OK]Currentlynotwophasecommittransactions-----Autovacuum-----[OK]autovacuumisactivated.[INFO]autovacuum_max_workers:3-----Checkpoint-----[WARN]checkpoint_completion_target(0.5)islow-----Diskaccess-----[OK]fsyncison[OK]synchronize_seqscansison-----WAL-----Argument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.-----Planner-----[OK]costssettingsaredefaults[BAD]someplanfeaturesaredisabled:enable_partitionwise_aggregate,enable_partitionwise_join=====Databaseinformationfordatabasetestdb=====-----Databasesize-----[INFO]Databasetestdbtotalsize:11.44MBArgument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[INFO]Databasetestdbtablessize:8.38MB(73.22%)[INFO]Databasetestdbindexessize:3.06MB(26.78%)-----Tablespacelocation-----Argument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[OK]NotablespaceinPGDATA-----Sharedbufferhitrate-----[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]Sharedbufferidxhitrateisverygood-----Indexes-----[OK]NoinvalidindexesArgument"11beta2"isn'tnumericinnumericgt(>)at/tmp/postgresqltuner.plline818.[OK]Nounusedindexes-----Procedures-----[OK]Noprocedureswithdefaultcosts=====Configurationadvices=====-----checkpoint-----[MEDIUM]Yourcheckpointcompletiontargetistoolow.Putsomethingnearestfrom0.8/0.9tobalanceyourwritesbetterduringthecheckpointinterval-----extension-----[LOW]Enablepg_stat_statementstocollectstatisticsonallqueries(notonlyquerieslongerthanlog_min_duration_statementinlogs)-----sysctl-----[URGENT]setvm.overcommit_memory=2in/etc/sysctl.confandrunsysctl-ptoreloadit.ThiswilldisablememoryovercommitmentandavoidpostgresqlkilledbyOOMkiller.

“PostgreSQL中怎么安装和使用postgresqltuner工具”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!