PostgreSQL ãµãŒãã®å©çšçµ±èšæ
å ±ãå®æçã«åéã»èç©ããããšã§ãDBèšèšãPostgreSQLã®éçš(æ¥ã
ã®åŠçåŸåã®ææ¡ã
æ§èœå£åãªã©ã®å
åãåé¡çºçæã®åå ã®ææ¡ç)ã«åœ¹ç«ã€ããŒã«ã§ãã
èµ·åãçµäºããã©ã¡ãŒã¿ã®èšå®ã¯ PostgreSQL ãšå¯ã«é£æºããŠãããæéããããã«å°å
¥å¯èœã§ãã
pg_statsinfo 14 ã®å€æŽç¹ã¯ãã¡ããã芧ãã ããã
pg_statsinfo 14 以é㯠GitHub ã«ãŠå ¬éããŠããŸããpg_statsinfo 13 以åã®æ å ±ã«ã€ããŠã¯ãSourceForgeãã芧ãã ããã
pg_statsinfo ã¯ãPostgreSQL ãµãŒãã®çµ±èšæ å ±ã掻åç¶æ³ãäžå®ã®æéééæ¯ã«å®æçã«åéãèç©ããæ©èœãšã PostgreSQL ã®åºåãããµãŒããã°ã解æããããšã§SQLã®æ§èœæ å ±ãååŸããæ©èœããã°åºåãå å·¥ããæ©èœããããŸãã ãŸããèç©ããæ å ±ãå ã«ããã¹ã圢åŒã®ã¬ããŒããåºåããã³ãã³ããæäŸããŸãã
ãŸããpg_statsinfo ã§åéããæ å ±ã¯ pg_stats_reporter ãçšããããšã§ã°ã©ãã£ã«ã«ãªåœ¢ã§è§£æã»åºåããããšãããŸãã
pg_statsinfo ã®ã·ã¹ãã æ§æäŸãšåäœæŠèŠã®ã€ã¡ãŒãžå³ã以äžã«ç€ºããŸãã
çµ±èšæ å ±ã¯äžå®ã®æéééã§ååŸããããªããžããªã»ããŒã¿ããŒã¹ (ä»¥äž ãªããžããªDB) ã«ä¿åãããŸãã çµ±èšæ å ±ã¯åã€ã³ã¹ã¿ã³ã¹ã®ããŒã¿ããŒã¹ã¯ã©ã¹ã¿åäœã§ååŸã§ããŸãã ãªããžããªDBã¯ãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãšåäžã€ã³ã¹ã¿ã³ã¹ã®ããŒã¿ããŒã¹ã§ããå¥ã€ã³ã¹ã¿ã³ã¹ã§ãèšå®å¯èœã§ãã ãŸãã1ã€ã®ãªããžããªDBã«å¯ŸããŠè€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®çµ±èšæ å ±ãæ ŒçŽããããšãã§ããŸãã ãªã 以éã§ã¯ pg_statsinfo ã§ååŸããçµ±èšæ å ±ããã¹ãããã·ã§ãããšå®çŸ©ããŸãã
ã¹ãããã·ã§ããã®ååŸæ¹æ³ã¯ä»¥äžã®ãšããã§ãã
- ãŠãŒã¶ãæå®ããæéééã§å®æçã«ã¹ãããã·ã§ãããååŸããããšãã§ããŸããããã©ã«ãèšå®ã§ã¯10åééã§ååŸããŸãã
- ä»»æã®ã¿ã€ãã³ã°ã§æåã§ã¹ãããã·ã§ãããååŸããããšãã§ããŸãã
ã¹ãããã·ã§ãããšããŠä»¥äžã®çµ±èšæ å ±ãåéããŸãã
- çµ±èšæ å ±ã³ã¬ã¯ã¿ãåéããå šãŠã®æ å ±ãæ¿å ¥ / æŽæ° / åé€è¡æ°ããããã¡ã¢ã¯ã»ã¹åæ°ã
- ããŒãã«ã¹ããŒã¹ãWALé åãã¢ãŒã«ã€ããã°é åã®ãã£ã¹ã¯äœ¿çšéã
- ãã³ã°ãã©ã³ã¶ã¯ã·ã§ã³åããŠããã¯ãšãªã
- ããã¯ãšã³ãããã»ã¹ã®ç¶æ³ãåŠçäžãããã¯åŸ ã¡ããã©ã³ã¶ã¯ã·ã§ã³äžã®åŸ æ©ãã¢ã€ãã«ã®ããããã§éèšããŸãã
- ãã©ã³ã¶ã¯ã·ã§ã³ãã°(WAL)ã®åºåéãæžã蟌ã¿ã«ããã£ãæéã
- ãã§ãã¯ãã€ã³ããèªåããã¥ãŒã ã®çµéæéããããã¡ã¢ã¯ã»ã¹åæ°ã
- ã¯ãšãªã®çµ±èšæ å ±(å®è¡åæ°ã环ç©å®è¡æéã环ç©å®è¡èšç»çææéã®å€ãSQLãšé¢æ°ãOS ãªãœãŒã¹æ å ±ãåŸ æ©ã€ãã³ã(äžäœ10)ãããã³å®è¡èšç»)ã
- PostgreSQLã®èšå®ãã©ã¡ãŒã¿ã
- OS ãªãœãŒã¹æ å ± (CPU䜿çšéãã¡ã¢ãªäœ¿çšéããã£ã¹ã¯I/OãããŒãã¢ãã¬ãŒãž)ã
- ããã¯ç«¶åæ å ±
- ãªã«ããªãšã®ç«¶åã«ããã¯ãšãªã®ãã£ã³ã»ã«æ°
- ã¹ããªãŒãã³ã°ã¬ããªã±ãŒã·ã§ã³æ å ± (walsenderã®æŽ»åç¶æ³)
- ããžã«ã«ã¬ããªã±ãŒã·ã§ã³æ å ± (walsenderã®æŽ»åç¶æ³)
- ã¢ã©ãŒãæ©èœã§æ€åºããã¢ã©ãŒãã®å 容
- SystemTap ã䜿çšãããããã¡ã€ãªã³ã°æ å ± (å®éšçæ±ãã®æ©èœ)ã
- ã€ã³ã¹ã¿ã³ã¹åäœã®åŸ æ©ã€ãã³ã
ã¹ãããã·ã§ããã®ãµã€ãºã¯ãDBå ã®ãªããžã§ã¯ãæ°ã«äŸåããŸãããæŠã1åã®ã¹ãããã·ã§ããã§1DBããã 800 - 1000KBãæ¶è²»ããŸãã ããã©ã«ãã®ååŸéé(10åéé)ã®å Žåãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹äžã€ããã1æ¥ã§120 - 150MBãæ¶è²»ããŸãã
ãªããžããªDBã®ããŒãã«æ§æã«é¢ããŠã¯ããpg_statsinfo v14 ãªããžããªDBæ§æããåç §ããŠãã ããã
PostgreSQL ãåºåãããµãŒããã°ãCSVãã°ãããã¹ããã°ãsyslog ã«åé ããŠåºåããŸãã
- ã¡ãã»ãŒãžã¬ãã« (ãšã©ãŒçš®å¥) ã«å¿ãããµãŒããã°ã®åé ãCSVãã°ãããã¹ããã°ãsyslog ã«åå¥ã§åºåéŸå€ãèšå®ã§ããŸãã
- ããã¹ããã°ã®ãã¡ã€ã«åãåºå®ãåžžã«åãåå (ããã©ã«ã pg_statsinfo.log) ã§ææ°ã®ãµãŒããã°ãé²èŠ§ã§ãããã°ç£èŠãœãããŠã§ã¢ãšã®é£æºã容æã«ãªããŸãã
- ããã¹ããã°ãã¡ã€ã«ã®ã¢ã¯ã»ã¹æš©ã®èšå®ãããã¹ããã°ã®ãã¡ã€ã«æš©éã 600 以å€ã«ãèšå®ã§ãããããéçšãæè»ã«ãªããŸãã
- ããã¹ããã°ãsyslog ã«åºåããããµãŒããã°ã®ã¡ãã»ãŒãžã¬ãã«ãä»»æã®ã¬ãã«ã«å€æŽå¯èœãäŸãã°ããªãã¬ãŒã·ã§ã³ãã¹ãªã©ã§çºçãã ERROR ã¬ãã«ã®ãã°ã INFO ã¬ãã«ã«å€æŽããŠåºåã§ããŸãã
- ããã¹ããã°ã®ãã£ã«ã¿ãªã³ã°èšå®ãç¹å®ã®ãŠãŒã¶ã®ãµãŒããã°ãããã¹ããã°ã«åºåããªãããã«ããããšãã§ããŸãã
PostgreSQL ãåºåãããµãŒããã°ãåéãããªããžããªDBã«èç©ããŸãã
- ãªããžããªDBã«èç©ãããµãŒããã°ãä»»æã®ã¡ãã»ãŒãžã¬ãã« (ãšã©ãŒçš®å¥) 以äžã«å¶éããããšãã§ããŸãã
- ç¹å®ãŠãŒã¶ã®ãµãŒããã°ããªããžããªDBãžèç©ããªãããã«ããããšãã§ããŸãã
- ãµãŒããã°ã®ã¡ãã»ãŒãžã¬ãã«ãä»»æã®ã¬ãã«ã«å€æŽããŠãªããžããªDBã«èç©ããããšãã§ããŸãã
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ç¶æ ãå®æç (ã¹ãããã·ã§ããååŸæ) ã«ãã§ãã¯ããåé¡ãæ€ç¥ããå Žåã«ã¢ã©ãŒãã¡ãã»ãŒãžãããã¹ããã°ã«åºåããŸãã ã¢ã©ãŒãã¡ãã»ãŒãžã¯ãã¡ãã»ãŒãžã¬ãã« "ALERT" ã§åºåãããŸãããªããã¢ã©ãŒãæ©èœã§æ€åºããã¢ã©ãŒãã®å 容ã¯ããªããžããªDBã«ãèç©ãããŸãã
ã¢ã©ãŒãæ©èœã§å€å®ããé
ç®ã¯ä»¥äžã®ãšããã§ãã
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹æ¯ã«ãã¢ã©ãŒãæ©èœã®æå¹ïŒç¡å¹ãšã¢ã©ãŒãæ¡ä»¶(éŸå€)ãèšå®ããããšãã§ããŸãã
- ç§éã®ããŒã«ããã¯æ°
- ç§éã®ã³ãããæ°
- ç£èŠã€ã³ã¹ã¿ã³ã¹äžã®äžèŠé åã®ãµã€ãº (MB)
- ç£èŠã€ã³ã¹ã¿ã³ã¹äžã®äžèŠé åã®å²å (%)
- åããŒãã«ã«å ããäžèŠé åã®å²å (%)
- ã¯ãšãªã®å¹³åã¬ã¹ãã³ã¹æé (ç§)
- ã¯ãšãªã®æé·ã¬ã¹ãã³ã¹æé (ç§)
- åããŒãã«ã®çžé¢ä¿æ°(correlation)(*1) (%)
- ããã¯ãšã³ãã®æ倧æ°
- ããŒãã«ã¹ããŒã¹ã®ãã£ã¹ã¯ç©ºã容é (%)
- ããŒãã¢ãã¬ãŒãž
- ã¹ã¯ãã䜿çšé (KB)
- ã¬ããªã±ãŒã·ã§ã³ã®é 延é (MB)
(*1) ããŒãã«ã®çžé¢ä¿æ°ã¯ãã¯ã©ã¹ã¿åããŒãã«(ã¯ã©ã¹ã¿ã€ã³ããã¯ã¹ãååšããããŒãã«)ã察象ã«å€å®ãè¡ãããŸãã
åã¢ã©ãŒãé ç®ã®ã¢ã©ãŒãã¡ãã»ãŒãžã®å 容ã«ã€ããŠã¯ãpg_statsinfo v14 ã¬ããŒãé ç®äžèŠ§ããã芧ãã ããã
ã¢ã©ãŒãæ©èœã®èšå®æ¹æ³ã¯ãã¡ããã芧ãã ããã
ã³ãã³ãã©ã€ã³æ©èœã¯ã¬ããŒãçæããã³éçšç®¡çãè¡ãããã®ã³ãã³ããæäŸããŸãã
â»ã³ãã³ãã©ã€ã³æ©èœã®äœ¿çšæ¹æ³ã¯ãã¡ããã芧ãã ããã
ãªããžããªDBã«ä¿åãããã¹ãããã·ã§ããããä»»æã®æéã®ã¬ããŒããããã¹ã圢åŒã§åºåããã³ãã³ããæäŸããŸãã
ãŸããã¬ããŒãã®åºå以å€ã«ä»¥äžã®æäœãè¡ãããšãã§ããŸãã
- ã¹ãããã·ã§ããã®äžèŠ§ã®è¡šç€º
- ã¹ãããã·ã§ããã®åèšãµã€ãºã®è¡šç€º
ç°¡æã¬ããŒãæ©èœãåºåããã¬ããŒãã®é
ç®ã«ã€ããŠã¯ãpg_statsinfo v14
ã¬ããŒãé
ç®äžèŠ§ããã芧ãã ããã
ãªããç°¡æã¬ããŒãæ©èœãåºåããã¬ããŒãã®é
ç®ã¯
pg_stats_reporter
ãšåçã§ãã
ã°ã©ããçšããã°ã©ãã£ã«ã«ãªã¬ããŒããåºåãããå Žåã¯
pg_stats_reporter
ã䜿çšããŠãã ããã
pg_statsinfo ã®éçšç®¡çåãã®æäœãè¡ãã³ãã³ããæäŸããŸãã
éçšç®¡çæ©èœã§è¡ãããšãã§ããæäœã¯ä»¥äžã®ãšããã§ãã
- ã¹ãããã·ã§ããã®ååŸ
- ã¹ãããã·ã§ããã®åé€
- ãšãŒãžã§ã³ãã®åæ¢
- ãšãŒãžã§ã³ãã®èµ·å
1æ¥1åãä»»æã®æå»ã«äžèšã®ã¡ã³ããã³ã¹æäœãè¡ãããšãã§ããŸãã
- ä¿ææéãçµéããå€ãã¹ãããã·ã§ããã®åé€
- ä¿ææéãçµéããèç©ãã°ã®åé€
- ãµãŒããã°ã®ãã°ãã¡ã€ã«ã®æŽç
æ¬æ©èœã¯ããã©ã«ã㯠ON ã§ãããäžèšã®æäœãèªåã¡ã³ããã³ã¹å®è¡æå»ã«å®è¡ããŸãã
(泚1)
ã¹ãããã·ã§ããã®èªååé€ãåæ¢ããŠããå Žåãå€ãã¹ãããã·ã§ããã¯èªåçã«åé€ãããŸãããå¿
èŠã«å¿ããŠãŠãŒã¶æäœã§å®æçã«åé€ããŠãã ããã
(泚2) èç©ãã°ã®èªååé€ãåæ¢ããŠããå Žåãå€ããã°ã¯èªåçã«åé€ãããŸãããå¿
èŠã«å¿ããŠãŠãŒã¶æäœã§å®æçã«åé€ããŠãã ããã
(泚3)
ãã°ãã¡ã€ã«ã®èªåæŽçãåæ¢ããŠããå Žåãå€ããã°ãã¡ã€ã«ã¯èªåçã«ã¯åé€ãããŸãããå¿
èŠã«å¿ããŠãŠãŒã¶æäœã§å®æçã«åé€ããŠãã ããã
èªåã¡ã³ããã³ã¹æ©èœã®äœ¿çšæ¹æ³ã¯ãã¡ããã芧ãã ããã
pg_statsinfo ã®ã€ã³ã¹ããŒã«æ¹æ³ã«ã€ããŠèª¬æããŸããåã€ã³ã¹ããŒã«ããã±ãŒãžã¯ãã¡ãããããŠã³ããŒãããŠäžããã
- PostgreSQL
ããŒãžã§ã³ 14 - åäœæ€èšŒæžã¿OS
RHEL 7.x (x86_64), CentOS 7.x (x86_64) RHEL 8.x (x86_64), CentOS 8.x (x86_64)
以äžã¯PostgreSQL14ã®RHEL7ã®x86\64çšã®rpmãã€ã³ã¹ããŒã«ããäŸã§ãã
$ su
# yum install pg_statsinfo-14.0-1.pg14.rhel7.x86_64.rpm
以äžã¯PostgreSQL14ã®RHEL8ã®x86_64çšã®rpmãã€ã³ã¹ããŒã«ããäŸã§ãã
$ su
# dnf install pg_statsinfo-14.0-1.pg14.rhel8.x86_64.rpm
ãœãŒã¹ã³ãŒããããã«ãããã«ã¯ãpgxs ã䜿çšããŸãã ãªããpg_statsinfo ã®ç»é²ã¹ã¯ãªãã (sql) ãæåã§ã€ã³ã¹ããŒã«ããå¿ èŠã¯ãããŸããã ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ããªããžããªDBå ±ã«ãååèµ·åæã«å¿ èŠã«å¿ã㊠ãšãŒãžã§ã³ããã¹ããŒããèªåçã«ã€ã³ã¹ããŒã«ããŸãã
$ tar xzvf pg_statsinfo-14.0.tar.gz
$ cd pg_statsinfo-14.0
$ make USE_PGXS=1
$ su
# make USE_PGXS=1 install
pgxsã䜿çšããªãå Žåãcontribé äžã«pg_statsinfoã®ãã©ã«ããé 眮ããmake, make installãå®æœããŠãã ããã
contrib/pg_statsinfo.sqlãcontrib/pg_statsrepo.sqlã¯èªåçã«ã€ã³ã¹ããŒã«ããããããæåã§ã®å®è¡ã¯äžèŠã§ãã
ç£èŠå¯Ÿè±¡ã® PostgreSQL ã€ã³ã¹ã¿ã³ã¹ãåæ¢ããç¶æ ã§ãpostgresql.conf ã«ä»¥äžã®èšå®ãè¡ããŸãã ãã®èšå®ã§ã¯ãã¹ãããã·ã§ããã®ä¿åå ã¯åäžã€ã³ã¹ã¿ã³ã¹ã® postgres ããŒã¿ããŒã¹ã«ãªããŸãã ããã以å€ã®èšå®ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãåç §ããŠäžããã
#æå°èšå®
shared_preload_libraries = 'pg_statsinfo' # äºåããŒããè¡ã
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # ãã°ãã¡ã€ã«åãæå®ãã
#æšå¥šèšå®
shared_preload_libraries = 'pg_statsinfo' # äºåããŒããè¡ã
pg_statsinfo.snapshot_interval = 30min # ã¹ãããã·ã§ããã®ååŸéé
pg_statsinfo.enable_maintenance = 'on' # èªåã¡ã³ããã³ã¹èšå®
pg_statsinfo.maintenance_time = '00:02:00' # èªåã¡ã³ããã³ã¹å®è¡æå»èšå®
pg_statsinfo.repolog_min_messages = disable # ãã°èç©æ©èœã®èšå®
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # ãã°ãã¡ã€ã«åãæå®ãã
log_min_messages = 'log' # ãã°ãžåºåããã¡ãã»ãŒãžã¬ãã«ã
pg_statsinfo.syslog_min_messages = 'error' # syslogã«åºåãããã°ã¬ãã«ãæå®ããã
pg_statsinfo.textlog_line_prefix = '%t %p %c-%l %x %q(%u, %d, %r, %a) '
# pg_statsinfoãããã¹ããã°ã«åºåããéãåè¡ã®å
é ã«è¿œå ãããæžåŒãæå®ãããlog_line_prefixãšåã圢åŒã§æå®ããã
pg_statsinfo.syslog_line_prefix = '%t %p %c-%l %x %q(%u, %d, %r, %a) '
# pg_statsinfoãsyslogçµç±ã§ãã°ãåºåããéãåè¡ã®å
é ã«è¿œå ãããæžåŒãæå®ããã
track_functions = 'all' # ã¹ãã¢ãããã·ãŒãžã£ã®åŒã³åºãã«é¢ããçµ±èšæ
å ±ãåéãã
log_checkpoints = on # ãã§ãã¯ãã€ã³ããèšé²
log_autovacuum_min_duration = 0 # èªåããã¥ãŒã ãèšé²
#pg_statsinfo.long_lock_threshold = 30s # ããã¯ç«¶åæ
å ±ã«èšé²ãã察象ã®æ¡ä»¶(éŸå€)ãæå®ãã
pg_statsinfo ã¯ä»¥äžã®èšå®ã匷å¶çã«äžæžãããããšã«æ³šæããŠãã ããã
- log_destination
'csvlog'ãè¿œå ããã'stderr'ã¯é€å»ãããŸãã - logging_collector
'on' ã«èšå®ãããŸãã
PostgreSQL èµ·åãŠãŒã¶ã§ã® localhost ããã®ã¢ã¯ã»ã¹ã§ã¯ãã¹ã¯ãŒãã®å ¥åãäžèŠã«ãªãããèšå®ããŸãã ãã®éã®èªèšŒã«ã¯ ident æ¹åŒãæšå¥šããŸãã äžè¬çã«ããå©çšããããOSãŠãŒã¶å = DB管çè å = postgresãã®å Žåã«ã¯ãpg_hba.conf ã«ä»¥äžãè¿œå ããŸãã ä»ã®èªèšŒæ¹åŒãããåªå ããããããã¡ã€ã«ã®æåã®ã»ãã«æžãå¿ èŠãããããšã«æ³šæããŠãã ããã UNIX ç°å¢ã§ã¯ TYPE=local ã® ident èªèšŒã䜿ãã®ãæ軜ã§ãã
# TYPE DATABASE USER CIDR-ADDRESS METHOD [for UNIX]
local all postgres ident
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã® postgres ããŒã¿ããŒã¹ã«
pg_stat_statements
ãã€ã³ã¹ããŒã«ããããšã§ãã¯ãšãªã®çµ±èšæ
å ±ãã¹ãããã·ã§ãããšããŠåéã§ããããã«ãªããŸãã
å©çšããå Žåã«ã¯ãpostgresql.conf ã® shared_preload_libraries ã«
pg_stat_statements ãè¿œå ããååèµ·åæã«ä»¥äžã®æé ã§ç»é²ããŠãã ããã
$ psql -d postgres -c "CREATE EXTENSION pg_stat_statements"
ãŸããå¿ èŠã«å¿ããŠèšå®ãã¡ã€ã«ã«äžèšã®ãã©ã¡ãŒã¿ãèšå®ããŠãã ããã
- pg_statsinfo.stat_statements_max
- pg_statsinfo.stat_statements_exclude_users
- pg_stat_statements.track_planning
äžèšã®ãã©ã¡ãŒã¿ã®èª¬æã¯èšå®ãã¡ã€ã«ãã芧ãã ããã
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã® postgres ããŒã¿ããŒã¹ã« pg_store_plans
ãã€ã³ã¹ããŒã«ããããšã§ãã¯ãšãªã®å®è¡èšç»ãã¹ãããã·ã§ãããšããŠåéã§ããããã«ãªããŸãã
å©çšããå Žåã«ã¯ãpostgresql.conf ã® shared_preload_libraries ã« pg_store_plans
ãè¿œå ããååèµ·åæã«ä»¥äžã®æé ã§ç»é²ããŠãã ããã
$ psql -d postgres -c "CREATE EXTENSION pg_store_plans"
ãŸããå¿ èŠã«å¿ããŠèšå®ãã¡ã€ã«ã«äžèšã®ãã©ã¡ãŒã¿ãèšå®ããŠãã ããã
- pg_statsinfo.stat_statements_max
- pg_statsinfo.stat_statements_exclude_users
äžèšã®ãã©ã¡ãŒã¿ã®èª¬æã¯èšå®ãã¡ã€ã«ãã芧ãã ããã
(泚1) pg_stats_reporter ãå©çšããå Žåã¯ããªããžããªDBã«ã pg_store_plans
ãã€ã³ã¹ããŒã«ããå¿
èŠããããŸãã
ãªãããªããžããªDBãžã®ã€ã³ã¹ããŒã«ã®éã¯äžèšã® shared_preload_libraries ã®èšå®ã¯äžèŠã§ãã
以äžã§ã€ã³ã¹ããŒã«ã¯çµäºã§ãã
pg_statsinfo ã®æäœæ¹æ³ãšåçš®èšå®ã«ã€ããŠèª¬æããŸãã
èµ·åã¯ãéåžžã©ããPostgreSQLãèµ·åããã ãã§ãã PostgreSQL ã®èµ·åãšé£åã㊠ãšãŒãžã§ã³ããèªåçã«èµ·åããŸãã ãšãŒãžã§ã³ãåäœã§èµ·åããããšã¯ã§ããŸããã
$ pg_ctl start [OPTIONS]
çµäºãåæ§ã«ãPostgresSQL ãµãŒãã®çµäºã«é£åããŸãã smart 以å€ã®çµäºã¢ãŒã (fast, immediate) ã§ã¯ãµãŒããã°ã«ãšã©ãŒãåºåãããå ŽåããããŸãããæ£åžžãªåäœã§ãã
$ pg_ctl stop -m smart [OPTIONS]
ãŸããPostgreSQL ãµãŒããçµäºããã« ãšãŒãžã§ã³ãã®ã¿ãåæ¢ããã«ã¯ä»¥äžã®ã³ãã³ããå®è¡ããŸãã
$ pg_statsinfo --stop [OPTIONS]
åæ¢äžã®ãšãŒãžã§ã³ããèµ·åããã«ã¯ä»¥äžã®ã³ãã³ããå®è¡ããŸãã
$ pg_statsinfo --start [OPTIONS]
(泚1) PostgreSQLã®èšå®ãã©ã¡ãŒã¿ã«ãshared_preload_libraries = 'pg_statsinfo'ããèšå®ãããŠããªãå Žåã¯ããšãŒãžã§ã³ãã®åæ¢ïŒèµ·åãå®è¡ã§ããŸããã
ã¹ãããã·ã§ãããäžå®ã®æéééã§å®æçã«ååŸããŸããpostgresql.confã«ä»¥äžã®èšå®ãèšè¿°ããããšã§èªåååŸãå®è¡ã§ããŸãã
äŸ: ã¹ãããã·ã§ããã®ååŸééã30åã«èšå®ããã
pg_statsinfo.snapshot_interval = 30min
ä»»æã®ã¿ã€ãã³ã°ã§ã¹ãããã·ã§ãããååŸããå Žåã¯ãç£èŠå¯Ÿè±¡ã®ã€ã³ã¹ã¿ã³ã¹ãååšããDBã¯ã©ã¹ã¿ã®postgresããŒã¿ããŒã¹ã«å¯Ÿããé¢æ°
statsinfo.snapshot(text DEFAULT NULL) ãå®è¡ããŠäžããã
åŒæ°ã§ã¹ãããã·ã§ããååŸçç±ãã³ã¡ã³ããšããŠèšé²ã§ããŸãã
äŸ: æåã§ã¹ãããã·ã§ãããååŸããŸããã³ã¡ã³ããšããŠæåå 'comment' ãä»äžããŸãã
$ psql -d postgres -c "SELECT statsinfo.snapshot('comment')"
ãªããæåååŸã¯éåæã§è¡ãããŸããäžèšã®ã³ãã³ãå®äºæã«ã¹ãããã·ã§ããååŸãå®äºããŠããªãå ŽåããããŸãã
èªåã¡ã³ããã³ã¹æ©èœã䜿çšããããšã§ä¿ææéãçµéããã¹ãããã·ã§ããåé€ãèªåçã«åé€ããããšãã§ããŸãã
èªåã¡ã³ããã³ã¹ã®ã¹ãããã·ã§ããåé€ã¯ããã©ã«ãã ON ãšãªã£ãŠããŸãã
èªåã¡ã³ããã³ã¹æ©èœã®äœ¿ãæ¹ã¯ãã¡ããã芧ãã ããã
ã¹ãããã·ã§ããã®æååé€ã¯ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«å¯ŸããŠãé¢æ° statsinfo.maintenance(timestamptz) ãå®è¡ããŠäžããã åŒæ°ã§æå®ããæå»ããå€ãã¹ãããã·ã§ãããåé€ãããŸãã
äŸ: ååŸæ¥æã 2011-02-01 07:00:00 ããå€ãã¹ãããã·ã§ãããåé€ããŸãã
$ psql -d postgres -c "SELECT statsinfo.maintenance('2010-02-01 07:00:00'::timestamptz);"
ãªããæååé€ã¯éåæã§è¡ãããŸããäžèšã®ã³ãã³ãå®äºæã«ã¹ãããã·ã§ããåé€ãå®äºããŠããªãå ŽåããããŸãã
pg_statsinfo ã«ã¯ PostgreSQL ã®ãµãŒããã°ããã£ã«ã¿ãªã³ã°ã«ããå å·¥ããæ©èœããããŸãã
以äžã§ã¯ãåºåããããã°ãã¡ã€ã«ã®çš®é¡ãšãã£ã«ã¿ãªã³ã°ã®çš®é¡ã説æããŸãã
- CSVãã° (*.csv) (äŸ: postgresql-2013-10-01_000000.csv)
CSVãã°ãšã¯ãPostgreSQL ãåºåããçã®ãã°ãšãªããŸãã(CSVãã°ã®è©³çŽ°ã¯ãã¡ããã芧ãã ãã) pg_statsinfo ã¯æ¬ãã°ã®æ å ±ãå ã«å å·¥ãããã°ã®åºåãè¡ããŸãããæ¬ãã°ã«é¢ããŠã¯å šãå å·¥ãè¡ããŸããã - ããã¹ããã° (pg_statsinfo.log)
ããã¹ããã°ãšã¯ãPostgreSQL ãåºåãããã°(CSVãã°)ã®æ å ±ãå ã« pg_statsinfo ãå å·¥ãè¡ã£ããã°ã§ãã ããã¹ããã°ã«ã¯ä»¥äžã®ç¹åŸŽããããŸãã- ããã¹ããã°ã®æžåŒãä»»æã®åœ¢åŒã«èšå®ããããšãã§ããŸãã
- ããã¹ããã°ã®ãã¡ã€ã«ã¢ã¯ã»ã¹æš©éãèšå®ããããšãã§ããŸãã
- ããã¹ããã°ã®ãã¡ã€ã«åãèšå®ããããšãã§ããŸãã
- ç¹å®ã®ãŠãŒã¶ã®ãã°ãé€å€ããå 容ã§åºåããããšãã§ããŸãã
- ç¹å®ã®SQLSTATEãæã€ãã°ã®ã¡ãã»ãŒãžã¬ãã«ãå€æŽããå 容ã§åºåããããšãã§ããŸãã ããã¹ããã°ã®æžåŒããã¡ã€ã«åããã³ãã¡ã€ã«ã¢ã¯ã»ã¹æš©éã¯ãèšå®ãã¡ã€ã«ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã(詳现ã¯ãã¡ããã芧ãã ãã)
- pg_statsinfo.textlog_line_prefix
- pg_statsinfo.textlog_permission
- pg_statsinfo.textlog_filename
- ä¿åçšããã¹ããã° (äŸ: postgresql-2013-10-01_000000.log)
äžèšã®ããã¹ããã°ãlog_filenameã§å®çŸ©ãããååã«ãªããŒã ãããã¡ã€ã«ã§ãããã°ããŒããŒãçã®éã«çæãããŸãã
(泚1) ãã°ããŒããŒãåã«å°æ¥ãªããŒã äºå®ã®ãã¹ã«æ¢ã«ãã¡ã€ã«ãååšããå ŽåããããŸãããããã¯æ£åžžãªç¶æ
ã§ãã
(泚2)
æ¡åŒµåãã.copyããã.err.nãã®ãã¡ã€ã«ãäœæãããå ŽåããããŸããåœè©²ãã¡ã€ã«ã®è©³çŽ°ã¯ãã¡ããåç
§ããŠãã ããã
ãã°ãã¡ã€ã«ã®åºåäŸã以äžã«ç€ºããŸãã
$ ls -l $PGDATA/log
-rw------- 1 postgres postgres 433644 Oct 1 23:59 postgresql-2013-10-01_000000.csv
-rw------- 1 postgres postgres 322167 Oct 1 23:59 postgresql-2013-10-01_000000.log
-rw------- 1 postgres postgres 425449 Oct 2 23:59 postgresql-2013-10-02_000000.csv
-rw------- 1 postgres postgres 321695 Oct 2 23:59 postgresql-2013-10-02_000000.log
-rw------- 1 postgres postgres 255424 Oct 3 13:40 postgresql-2013-10-03_000000.csv
-rw------- 1 postgres postgres 0 Oct 3 00:00 postgresql-2013-10-03_000000.log
-rw------- 1 postgres postgres 190786 Oct 3 13:40 pg_statsinfo.log
postgresql-2013-10-01_000000.csv ... ãã°ããŒããŒãæžã¿ã®CSVãã°
postgresql-2013-10-01_000000.log ... ãã°ããŒããŒãæžã¿ã®ããã¹ããã° (äžèšã®CSVãã°ã®æ
å ±ãå
ã«å å·¥ãããã°)
postgresql-2013-10-02_000000.csv ... ãã°ããŒããŒãæžã¿ã®CSVãã°
postgresql-2013-10-02_000000.log ... ãã°ããŒããŒãæžã¿ã®ããã¹ããã° (äžèšã®CSVãã°ã®æ
å ±ãå
ã«å å·¥ãããã°)
postgresql-2013-10-03_000000.csv ... ææ°ã®CSVãã°
postgresql-2013-10-03_000000.log ... ã³ã³ãœãŒã«ãã°
pg_statsinfo.log ................... ããã¹ããã° (ææ°ã®CSVãã°ã®æ
å ±ãå
ã«å å·¥ãããã°)
- ã¡ãã»ãŒãžã¬ãã«ã«ããåºåå¶åŸ¡
ç¹å®ã®ã¡ãã»ãŒãžã¬ãã«ããäœãã¬ãã«ã®ãã°ãããã¹ããã°ã«åºåããªãããã«ãã£ã«ã¿ãªã³ã°ããŸãã ç¹å®ã®ã¡ãã»ãŒãžã¬ãã«ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã- pg_statsinfo.textlog_min_messages èšå®äŸ: warning 以äžã®ã¡ãã»ãŒãžã¬ãã«ã®ãã°ãããã¹ããã°ã«åºåãã pg_statsinfo.textlog_min_messages = warning
- ç¹å®ãŠãŒã¶ã®ã»ãã·ã§ã³ã®ãã°ã®åºåå¶åŸ¡
ç¹å®ãŠãŒã¶ã®ã»ãã·ã§ã³ã®ãã°ãããã¹ããã°ã«åºåããªãããã«ãã£ã«ã¿ãªã³ã°ããŸãã ç¹å®ãŠãŒã¶ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã- pg_statsinfo.textlog_nologging_users èšå®äŸ: postgres ãŠãŒã¶ã®ã»ãã·ã§ã³ã®ãã°ãããã¹ããã°ã«åºåããªã pg_statsinfo.textlog_nologging_users = 'postgres'
- ã¡ãã»ãŒãžã¬ãã«ã®å€æŽ
ç¹å®ã®SQLSTATEãæã€ãã°ã®ã¡ãã»ãŒãžã¬ãã«ãä»»æã®ã¡ãã»ãŒãžã¬ãã«ã«å€æŽããŸãã ã¡ãã»ãŒãžã¬ãã«ã®å€æŽå¯Ÿè±¡ã®SQLSTATEããã³å€æŽåŸã®ã¡ãã»ãŒãžã¬ãã«ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã- pg_statsinfo.adjust_log_level
- pg_statsinfo.adjust_log_info
- pg_statsinfo.adjust_log_notice
- pg_statsinfo.adjust_log_warning
- pg_statsinfo.adjust_log_error
- pg_statsinfo.adjust_log_log
- pg_statsinfo.adjust_log_fatal èšå®äŸ: SQLSTATEã '42P01' ã®ãã°ã®ã¡ãã»ãŒãžã¬ãã«ã 'INFO' ã«å€æŽãã pg_statsinfo.adjust_log_level = on pg_statsinfo.adjust_log_info = '42P01'
(泚1) ã¡ãã»ãŒãžã¬ãã«ã®å€æŽã¯ããµãŒããã°åé
ãšãµãŒããã°èç©ã§å
±éã§ãã
(泚2) ã¡ãã»ãŒãžã¬ãã«ã®å€æŽããµãŒããã°åé
ãšãµãŒããã°èç©ã§åå¥ã«èšå®ããããšã¯ã§ããŸããã
èªåã¡ã³ããã³ã¹æ©èœã䜿çšããããšã§ãã°ãã¡ã€ã«ã®æŽçãè¡ãããšãã§ããŸãã
èªåã¡ã³ããã³ã¹ã®ãã°ãã¡ã€ã«æŽçã¯ããã©ã«ãã ON ãšãªã£ãŠããŸãã
èªåã¡ã³ããã³ã¹æ©èœã®äœ¿ãæ¹ã¯ãã¡ããã芧ãã ããã
ãµãŒããã°èç©æ©èœã䜿çšããããšã§ PostgreSQL ã®ãµãŒããã°ããªããžããªDBã«èç©ããããšãã§ããŸãã
ãŸãããªããžããªDBã«èç©ãããµãŒããã°ããã£ã«ã¿ãªã³ã°ããããšãå¯èœã§ãã
- ã¡ãã»ãŒãžã¬ãã«ã«ããèç©å¶é
ç¹å®ã®ã¡ãã»ãŒãžã¬ãã«ããäœãã¬ãã«ã®ãã°ãèç©ããªãããã«å¶éããŸãã å¶éããã¡ãã»ãŒãžã¬ãã«ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã- pg_statsinfo.repolog_min_messages èšå®äŸ: warning 以äžã®ã¡ãã»ãŒãžã¬ãã«ã®ãã°ãèç©ãã pg_statsinfo.repolog_min_messages = warning ãªããåœè©²ãã©ã¡ãŒã¿ã« "disable" ãæå®ããããšã§ãµãŒããã°ã®èç©ãç¡å¹åããããšãã§ããŸãã èšå®äŸ: ãµãŒããã°ã®èç©ãç¡å¹åãã pg_statsinfo.repolog_min_messages = disable
- ç¹å®ãŠãŒã¶ã®ãã°ã®èç©å¶é
ç¹å®ãŠãŒã¶ã®ã»ãã·ã§ã³ã®ãã°ãèç©ããªãããã«å¶éããŸãã ç¹å®ãŠãŒã¶ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã®äžèšã®ãã©ã¡ãŒã¿ã§æå®ããŸãã èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã- pg_statsinfo.repolog_nologging_users èšå®äŸ: postgres ãŠãŒã¶ã®ã»ãã·ã§ã³ã®ãã°ãèç©ããªã pg_statsinfo.repolog_nologging_users = 'postgres'
- ã¡ãã»ãŒãžã¬ãã«ã®å€æŽ
ç¹å®ã®SQLSTATEãæã€ãã°ã®ã¡ãã»ãŒãžã¬ãã«ãä»»æã®ã¡ãã»ãŒãžã¬ãã«ã«å€æŽããŸãã ã¡ãã»ãŒãžã¬ãã«ã®å€æŽã¯ããµãŒããã°åé ãšãµãŒããã°èç©ã§å ±éã§ãã ã¡ãã»ãŒãžã¬ãã«ã®å€æŽããµãŒããã°åé ãšãµãŒããã°èç©ã§åå¥ã«èšå®ããããšã¯ã§ããŸããã ã¡ãã»ãŒãžã¬ãã«ã®å€æŽã®èšå®æé 㯠ãã¡ã ãã芧ãã ããã
èªåã¡ã³ããã³ã¹æ©èœã䜿çšããããšã§ãªããžããªDBã«èç©ããããã°ãå®æçã«åé€ããããšãã§ããŸãã
èªåã¡ã³ããã³ã¹ã®èç©ãã°ã®åé€ã¯ããã©ã«ãã ON ãšãªã£ãŠããŸãã
èªåã¡ã³ããã³ã¹æ©èœã®äœ¿ãæ¹ã¯ãã¡ããã芧ãã ããã
以äžã®æ¡ä»¶ããã¹ãŠæºããå Žåã¯ããµãŒããã°èç©ãååž°çã«ç¹°ãè¿ãããŠããŸããŸãã
ãããé²ãããã«ãµãŒããã°èç©ã匷å¶çã«ç¡å¹åããŸãã
- ç£èŠå¯Ÿè±¡DBãšãªããžããªDBãåäžã€ã³ã¹ã¿ã³ã¹ã®æ§æã§ãã
- ãªããžããªDBãžã®æ¥ç¶ã«äœ¿çšãããŠãŒã¶ãã¹ãŒããŠãŒã¶ã§ã¯ãªã
- ãªããžããªDBæ¥ç¶ã®èšå®ãã©ã¡ãŒã¿ãlog_statementsãã "all" ãŸã㯠"mod" ã«èšå®ãããŠãã
â»log_statements ã¯èšå®ãã¡ã€ã«(postgresql.conf)ã®ã»ãã«ãããŒã«åºæã®èšå®ãããããšã«æ³šæããŠãã ãã
ã¢ã©ãŒãæ¡ä»¶(éŸå€)ã¯ãã¢ã©ãŒãèšå®ããŒãã«(ãªããžããªDBã®ãstatsrepo.alertãããŒãã«)ã§ç®¡çããŸãã
åèšå®ã«ã©ã ã®å€ã -1
ã«èšå®ããããšã§é
ç®åäœã§ã¢ã©ãŒããç¡å¹ã«ã§ããŸãã
ã¢ã©ãŒãèšå®ããŒãã«ã®ã¹ããŒãæ§æã以äžã«ç€ºããŸãã
ã«ã©ã å | ããŒã¿å | ããã©ã«ãå€ | 説æ |
---|---|---|---|
instid | bigint | ïŒ | ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ID |
rollback_tps | bigint | 100 | ç§éã®ããŒã«ããã¯æ° |
commit_tps | bigint | 1000 | ç§éã®ã³ãããæ° |
garbage_size | bigint | -1 | ç£èŠã€ã³ã¹ã¿ã³ã¹äžã®äžèŠé åã®ãµã€ãº(MB) |
garbage_percent | integer | 30 | ç£èŠã€ã³ã¹ã¿ã³ã¹ã«å ããäžèŠé åã®å²å(%) |
garbage_percent_table | integer | 30 | åããŒãã«ã«å ããäžèŠé åã®å²å(%) |
response_avg | bigint | 10 | ã¯ãšãªã®å¹³åã¬ã¹ãã³ã¹æé(ç§) |
response_worst | bigint | 60 | ã¯ãšãªã®æé·ã¬ã¹ãã³ã¹æé(ç§) |
correlation_percent | integer | 70 | åããŒãã«ã®çžé¢ä¿æ°(correlation)(%) |
backend_max | integer | 100 | ããã¯ãšã³ãã®æå€§æ° |
disk_remain_percent | integer | 20 | ããŒãã«ã¹ããŒã¹ã®ãã£ã¹ã¯ç©ºã容éã®å²å(%) |
loadavg_1min | real | 7.0 | éå»1åéã®ããŒãã¢ãã¬ãŒãž |
loadavg_5min | real | 6.0 | éå»5åéã®ããŒãã¢ãã¬ãŒãž |
loadavg_15min | real | 5.0 | éå»15åéã®ããŒãã¢ãã¬ãŒãž |
swap_size | integer | 1000000 | ã¹ã¯ãã䜿çšé(KB) |
rep_flush_delay | integer | 100 | ãã¹ã¿ãšã¹ã¿ã³ãã€éã®WALæžã蟌ã¿é 延é(MB) |
rep_replay_delay | integer | 200 | ã¹ã¿ã³ãã€ã®ãªã«ããªé 延é(MB) |
enable_alert | boolean | true | false ã«èšå®ãããšãã®ã€ã³ã¹ã¿ã³ã¹ã«ã€ããŠã®ã¢ã©ãŒããç¡å¹ã«ãªããŸãã |
èšå®å€æŽã®äŸ: ç§éããŒã«ããã¯æ°ã®éŸå€ãã3000ãã«å€æŽããå Žå
# UPDATE statsrepo.alert SET rollback_tps = 3000 WHERE instid = <å€æŽå¯Ÿè±¡ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ID>
ãã®ããŒãã«ã®è¡ãåé€ãããšã該åœããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¢ã©ãŒãæ©èœãç¡å¹ã«ãªããŸãããã®ã¢ã©ãŒããæå¹ã«ããããã«ã¯æ°ããªè¡ãæ¿å ¥ããå¿ èŠããããŸãã
GUC èšå®ãã¡ã€ã«ã® pg_statsinfo.enable_alert ã true ã«ããããšã§ã¢ã©ãŒãæ©èœå šäœãæå¹ã«ã§ããŸããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹åäœã§ã®æå¹åã»ç¡å¹åã¯ã¢ã©ãŒãèšå®ããŒãã«ã® enable_alert ã«ã©ã ã§è¡ããŸããããã©ã«ãå€ã¯pg_statsinfo.enable_alertã¯falseãã¢ã©ãŒãèšå®ããŒãã«ã®enable_alert ã«ã©ã ã¯trueã§ãããã®ããããã©ã«ãã§ã¯ã¢ã©ãŒãã¯ç¡å¹ã«ãªã£ãŠããŸãã
$ pg_statsinfo -r REPORTID [-i INSTANCEID] [-b SNAPID] [-e SNAPID] [-B DATE] [-E DATE] [-o FILENAME] [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠãããªããžããªDBã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres ãŠãŒã¶ã§æ¥ç¶ãã以äžã®æ¡ä»¶ã®ã¬ããŒããåºåããŸãã
- ã¬ããŒãçš®å¥IDã All ã®ã¬ããŒã
- ã¬ããŒãç¯å²ã¯æåã®ã¹ãããã·ã§ããããæåŸã®ã¹ãããã·ã§ãã
- ã¬ããŒã察象ã¯å šãŠã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹
- ã¬ããŒãã®åºåå ã¯æšæºåºå
$ pg_statsinfo -r All -h localhost -d postgres -p 5432 -U postgres
- -r, --report=REPORTID
ã¬ããŒãçš®å¥IDãæå®ããŸãã ã¬ããŒãçš®å¥IDã«æå®ã§ããå€ã¯ä»¥äžã®ãšããã§ãã ã¬ããŒãçš®å¥IDãšã¬ããŒãã®å 容ã«ã€ããŠã®å¯Ÿå¿ã¯ãpg_statsinfo v14 ã¬ããŒãé ç®äžèŠ§ããã芧ãã ããã- Summary
- Alert
- DatabaseStatistics
- InstanceActivity
- OSResourceUsage
- DiskUsage
- LongTransactions
- NotableTables
- CheckpointActivity
- AutovacuumActivity
- QueryActivity
- LockConflicts
- ReplicationActivity
- SettingParameters
- SchemaInformation
- Profiles
- All ã¬ããŒãçš®å¥IDã¯ãé æåããã®æçäžèŽã§ã®æå®ã蚱容ãã倧æåãšå°æåãåºå¥ããŸããã
- -i, --instid=INSTANCEID
ã¬ããŒã察象ãšããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®èå¥åãæå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯å šãŠã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãã¬ããŒã察象ã§ãã - -b, --beginid=SNAPID
ã¬ããŒãç¯å²ã®éå§ç¹ãšããã¹ãããã·ã§ãããã¹ãããã·ã§ããIDã§æå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯æåã®ã¹ãããã·ã§ãããéå§ç¹ãšããŸãã æ¬ãªãã·ã§ã³ãšã--B, --begindateããŸãã¯ã-E, --enddateããåæã«æå®ããããšã¯ã§ããŸããã - -e, --endid=SNAPID
ã¬ããŒãç¯å²ã®çµäºç¹ãšããã¹ãããã·ã§ãããã¹ãããã·ã§ããIDã§æå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯æåŸã®ã¹ãããã·ã§ãããçµäºç¹ãšããŸãã æ¬ãªãã·ã§ã³ãšã--B, --begindateããŸãã¯ã-E, --enddateããåæã«æå®ããããšã¯ã§ããŸããã - -B, --begindate=DATE
ã¬ããŒãç¯å²ã®éå§ç¹ãšããã¹ãããã·ã§ãããæ¥æ (YYYY-MM-DD HH:MI:SS圢åŒ) ã§æå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯æåã®ã¹ãããã·ã§ãããéå§ç¹ãšããŸãã æ¬ãªãã·ã§ã³ãšã--b, --beginidããŸãã¯ã-e, --endidããåæã«æå®ããããšã¯ã§ããŸããã - -E, --enddate=DATE
ã¬ããŒãç¯å²ã®çµäºç¹ãšããã¹ãããã·ã§ãããæ¥æ (YYYY-MM-DD HH:MI:SS圢åŒ) ã§æå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯æåŸã®ã¹ãããã·ã§ãããçµäºç¹ãšããŸãã æ¬ãªãã·ã§ã³ãšã--b, --beginidããŸãã¯ã-e, --endidããåæã«æå®ããããšã¯ã§ããŸããã - -o, --output=FILENAME
ã¬ããŒãã®åºåå ãã¡ã€ã«åãæå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯ã¬ããŒããæšæºåºåã«åºåããŸãã æå®ãããã¡ã€ã«ãæ¢ã«ååšããå Žåã¯äžæžãããŸãã
$ pg_statsinfo -l [-i INSTANCEID] [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠãããªããžããªDBã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres
ãŠãŒã¶ã§æ¥ç¶ããåœè©²ãªããžããªDBã«èç©ãããŠããã¹ãããã·ã§ããã®äžèŠ§ã衚瀺ããŸãã
$ pg_statsinfo -l -h localhost -d postgres -p 5432 -U postgres
- -l, --list
æ¬ãªãã·ã§ã³ãæå®ãããå Žåã¯ã¹ãããã·ã§ããäžèŠ§ã®è¡šç€ºãè¡ããŸãã - -i, --instid=INSTANCEID
ã¹ãããã·ã§ããäžèŠ§ã衚瀺ããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®èå¥åãæå®ããŸãã æ¬ãªãã·ã§ã³ã¯çç¥å¯èœã§ããçç¥æã¯å šãŠã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ããäžèŠ§ã衚瀺ããŸãã
$ pg_statsinfo -s [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠãããªããžããªDBã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres
ãŠãŒã¶ã§æ¥ç¶ããåœè©²ãªããžããªDBã«èç©ãããŠããã¹ãããã·ã§ããã®ãµã€ãºã衚瀺ããŸãã
$ pg_statsinfo -s -h localhost -d postgres -p 5432 -U postgres
- -s, --size
æ¬ãªãã·ã§ã³ãæå®ãããå Žåã¯ã¹ãããã·ã§ãããµã€ãºã®è¡šç€ºãè¡ããŸãã
$ pg_statsinfo -S COMMENT [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres
ãŠãŒã¶ã§æ¥ç¶ãã'COMMENT'ãã³ã¡ã³ããšããŠä»äžããã¹ãããã·ã§ãããååŸããŸãã
$ pg_statsinfo -S 'COMMENT' -h localhost -d postgres -p 5432 -U postgres
- -S, --snapshot=COMMENT
æ¬ãªãã·ã§ã³ãæå®ãããå Žåã¯ã¹ãããã·ã§ããã®ååŸãè¡ããŸãã ãªãã·ã§ã³åŒæ°ã«ã¯ã¹ãããã·ã§ããã«ä»äžããã³ã¡ã³ããæå®ããŸãã
$ pg_statsinfo -D SNAPID [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠãããªããžããªDBã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres ãŠãŒã¶ã§æ¥ç¶ããåœè©²ãªããžããªDBã«èç©ãããŠããã¹ãããã·ã§ããIDã
123 ã®ã¹ãããã·ã§ãããåé€ããŸãã
$ pg_statsinfo -D 123 -h localhost -d postgres -p 5432 -U postgres
- -D, --delete=SNAPID
æ¬ãªãã·ã§ã³ãæå®ãããå Žåã¯ã¹ãããã·ã§ããã®åé€ãè¡ããŸãã ãªãã·ã§ã³åŒæ°ã«ã¯åé€å¯Ÿè±¡ã®ã¹ãããã·ã§ããã®ã¹ãããã·ã§ããIDãæå®ããŸãã
$ pg_statsinfo --stop [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres ãŠãŒã¶ã§æ¥ç¶ãããšãŒãžã§ã³ããåæ¢ããŸãã
$ pg_statsinfo --stop -h localhost -d postgres -p 5432 -U postgres
- --stop
æ¬ãªãã·ã§ã³ãæå®ãããå Žå㯠ãšãŒãžã§ã³ããåæ¢ããŸãã
$ pg_statsinfo --start [connection-options]
以äžã«ã³ãã³ãäŸã瀺ããŸãã
以äžã®ã³ãã³ãäŸã§ã¯ããã¹ãå localhost äžã®ããŒã 5432 ã§çšŒåããŠããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«å¯ŸããŠãpostgres
ããŒã¿ããŒã¹ã«ãpostgres ãŠãŒã¶ã§æ¥ç¶ãããšãŒãžã§ã³ããèµ·åããŸãã
$ pg_statsinfo --start -h localhost -d postgres -p 5432 -U postgres
- --start
æ¬ãªãã·ã§ã³ãæå®ãããå Žå㯠ãšãŒãžã§ã³ããèµ·åããŸãã
ããŒã¿ããŒã¹æ¥ç¶ã«é¢ãããªãã·ã§ã³ã§ãã
ã¹ãããã·ã§ããååŸãå®è¡ããå Žåã¯ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ããã以å€ã¯ãªããžããªDBãžã®æ¥ç¶æ
å ±ãæå®ããŸãã
- -d, --dbname=DBNAME
æ¥ç¶ããããŒã¿ããŒã¹åãæå®ããŸãã æ¬ãªãã·ã§ã³ãæå®ãããŠããªãå Žåã¯ç°å¢å€æ°ãPGDATABASEãã®å€ã䜿çšãããŸãã ç°å¢å€æ°ãèšå®ãããŠããªãå Žåã¯ãæ¥ç¶æã«æå®ãããŠãŒã¶åã䜿çšãããŸãã - -h, --host=HOSTNAME
ãµãŒãã皌åããŠãããã·ã³ã®ãã¹ãåãæå®ããŸãã ãã¹ãåãã¹ã©ãã·ã¥ããå§ãŸãå ŽåãUnixãã¡ã€ã³ãœã±ããçšã®ãã£ã¬ã¯ããªãšããŠäœ¿çšãããŸãã - -p, --port=PORT
ãµãŒããæ¥ç¶ãç£èŠããTCPããŒããããã¯Unixãã¡ã€ã³ãœã±ãããã¡ã€ã«ã®æ¡åŒµåãæå®ããŸãã - -U, --username=USERNAME
æ¥ç¶ãããŠãŒã¶åãæå®ããŸãã - -w,
--no-password
ãã¹ã¯ãŒãã®å ¥åãä¿ããŸããããµãŒãããã¹ã¯ãŒãèªèšŒãå¿ èŠãšãããã€ã.pgpassãã¡ã€ã«ãªã©ã®ä»ã®æ¹æ³ãå©çšã§ããªãå Žåãæ¥ç¶è©Šè¡ã¯å€±æããŸãã - -W, --password
ããŒã¿ããŒã¹ã«æ¥ç¶ããåã«ã匷å¶çã«ãã¹ã¯ãŒãå ¥åãä¿ããŸãã
èªåã¡ã³ããã³ã¹æ©èœã䜿çšããããšã§ä»¥äžã®æäœã1æ¥1åä»»æã®æå»ã«è¡ãããšãã§ããŸãã
- ä¿ææéãçµéããå€ãã¹ãããã·ã§ããã®åé€
- ä¿ææéãçµéããèç©ãã°ã®åé€
- ãµãŒããã°ã®ãã°ãã¡ã€ã«ã®æŽç
èªåã¡ã³ããã³ã¹æ©èœã䜿çšããã«ã¯ãèšå®ãã¡ã€ã«(postgresql.conf)ã«ä»¥äžã®ãã©ã¡ãŒã¿ãæå®ããŸãã
èšå®ã®è©³çŽ°ã«ã€ããŠã¯ãèšå®ãã¡ã€ã«ãã芧ãã ããã
- pg_statsinfo.enable_maintenance
- pg_statsinfo.maintenance_time
- pg_statsinfo.repository_keepday
- pg_statsinfo.repolog_keepday
- pg_statsinfo.log_maintenance_command
èšå®äŸ1: æ¯æ¥0æ2åã«7æ¥éã®ä¿ææéãéããã¹ãããã·ã§ãããèªååé€ãã
pg_statsinfo.enable_maintenance = 'snapshot' # èªåã¡ã³ããã³ã¹èšå®
pg_statsinfo.maintenance_time = '00:02:00' # èªåã¡ã³ããã³ã¹å®è¡æå»èšå®
pg_statsinfo.repository_keepday = 7 # ã¹ãããã·ã§ããã®ä¿ææéèšå®
èšå®äŸ2: æ¯æ¥0æ2åã«7æ¥éã®ä¿ææéãéããèç©ãã°ãèªååé€ãã
pg_statsinfo.enable_maintenance = 'repolog' # èªåã¡ã³ããã³ã¹èšå®
pg_statsinfo.maintenance_time = '00:02:00' # èªåã¡ã³ããã³ã¹å®è¡æå»èšå®
pg_statsinfo.repolog_keepday = 7 # èç©ãã°ã®ä¿ææéèšå®
èšå®äŸ3: æ¯æ¥0æ2åã«åæ¥ä»¥åã®CSVãã°ãã¡ã€ã«ãå§çž®ã¢ãŒã«ã€ããã
pg_statsinfo.enable_maintenance = 'log' # èªåã¡ã³ããã³ã¹èšå®
pg_statsinfo.maintenance_time = '00:02:00' # èªåã¡ã³ããã³ã¹å®è¡æå»èšå®
pg_statsinfo.log_maintenance_command = '<PGHOME>/bin/archive_pglog.sh %l' # ãã°ãã¡ã€ã«æŽçã³ãã³ãèšå® (*1)
â»<PGHOME>: PostgreSQL ã€ã³ã¹ããŒã«ãã£ã¬ã¯ããª
(*1) archive_pglog.sh
archive_pglog.sh ã¯å梱ãããã·ã§ã«ã¹ã¯ãªããã§ãã
åæ¥ä»¥åã®CSVãã°ãã¡ã€ã«ãå§çž®ã¢ãŒã«ã€ããããã°ãã¡ã€ã«æ ŒçŽãã£ã¬ã¯ããªé
äžã«ã¢ãŒã«ã€ããã¡ã€ã«(TGZ)ãäœæããŸãã
ãŸããã¢ãŒã«ã€ãããCSVãã°ãã¡ã€ã«ããã°ãã¡ã€ã«æ ŒçŽãã£ã¬ã¯ããªããåé€ããŸãã
èšå®äŸ4: æ¯æ¥0æ2åã«7æ¥éã®ä¿ææéãéããã¹ãããã·ã§ãããšèç©ãã°ãèªååé€ããã€åæ¥ä»¥åã®CSVãã°ãã¡ã€ã«ãå§çž®ã¢ãŒã«ã€ããã
pg_statsinfo.enable_maintenance = 'on' # èªåã¡ã³ããã³ã¹èšå®
pg_statsinfo.maintenance_time = '00:02:00' # èªåã¡ã³ããã³ã¹å®è¡æå»èšå®
pg_statsinfo.repository_keepday = 7 # ã¹ãããã·ã§ããã®ä¿ææéèšå®
pg_statsinfo.repolog_keepday = 7 # èç©ãã°ã®ä¿ææéèšå®
pg_statsinfo.log_maintenance_command = '<PGHOME>/bin/archive_pglog.sh %l' # ãã°ãã¡ã€ã«æŽçã³ãã³ãèšå®
(泚1) èªåã¡ã³ããã³ã¹èšå®ã®ããã©ã«ãã¯ãå šãŠã®æäœãå®è¡ããèšå®('on')ã§ãã
(泚2) èªåã¡ã³ããã³ã¹ã§ã¹ãããã·ã§ããåé€ãèç©ãã°åé€ãè¡ããªãå Žåãæåã§åé€ããªãéããªããžããªDBã«æ®ãç¶ããŸãã äžèŠãšãªã£ãå€ãã¹ãããã·ã§ããããã³èç©ãã°ã¯å®æçã«åé€ããŠäžããã
(泚3) ãã°ãã¡ã€ã«æŽçã³ãã³ãã®èšå®ãçç¥ããå Žåãäžèšã®äŸãšåãã³ãã³ããé©çšãããŸãã
(泚4) è€æ°ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ïŒåäžãªããžããªDBã®æ§æã§ãåç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ããã®ä¿ææéã äºãã«ç°ãªãæéã«èšå®ããå Žåãèªåã¡ã³ããã³ã¹å®è¡æã«ã¯æãçãèšå®ããæéã®ã¹ãããã·ã§ãããä¿æãããŸãã äŸãã°ãåç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®èšå®ãã¡ã€ã«(postgresql.conf)ã以äžã®ããã«èšå®ããå Žåã¯ã éå»3æ¥éã®ã¹ãããã·ã§ãããä¿æãããããšã«ãªããŸãã(èç©ãã°ã«é¢ããŠãåæ§)
<ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹1>
pg_statsinfo.enable_maintenance = 'on'
pg_statsinfo.repository_keepday = 7
<ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹2>
pg_statsinfo.enable_maintenance = 'on'
pg_statsinfo.repository_keepday = 5
<ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹3>
pg_statsinfo.enable_maintenance = 'on'
pg_statsinfo.repository_keepday = 3
éåžžã«å€ãã®ããŒãã«ãã€ã³ããã¯ã¹ãæã€ç°å¢ã§ã¯ãã¹ãããã·ã§ãããµã€ãºã®è¥å€§åããååŸæéã®é 延ãåé¡ãšãªãå ŽåããããŸããæ å ±åé察象ãå¶éããããšã§ãã¹ãããã·ã§ãããµã€ãºããã³ååŸæéã®åæžãå¯èœã§ãã
pg_statsinfoã§ã¯ãç¹ã«ããŒãã«ã®åæ å ±ãšã€ã³ããã¯ã¹æ å ±ãã¹ãããã·ã§ãããµã€ãºã®å€ããå ããããšãå€ããããåæ å ±ãšã€ã³ããã¯ã¹æ å ±ã®ååŸãç¡å¹åãããã©ã¡ãŒã¿ãæã£ãŠããŸããåæ å ±ååŸã®æå¹/ç¡å¹ã¯pg_statsinfo.collect_columnãã€ã³ããã¯ã¹æ å ±ååŸã®æå¹/ç¡å¹ã¯pg_statsinfo.collect_indexã§ããããèšå®ããŸããã©ã¡ããon/offããããã¯true/falseã§ã®æå®ãšãªããããã©ã«ãã¯åæ¹ãšãonã§ãã
ãã ããäžéšã¬ããŒãé ç®ãåºåãããªããªããŸãããããã®æ å ±ãäžèŠã§ãããšå€æã§ããå Žåã®ã¿ãå©çšããããã«ããŠãã ããã詳现ã¯èšå®ãã¡ã€ã«ã®æ³šèšãã芧ãã ããã
1åã®ã¹ãããã·ã§ããã§ãæ å ±åé察象ãšãªãã€ã³ããã¯ã¹1ã€ãããçŽ350Byteãå1ã€ãããçŽ150Byteãå¿ èŠãšãªããããåéããªãå Žåã¯ãããããã®ãŸãŸåæžã§ããŸãããã ããã€ã³ããã¯ã¹åãååãéåžžã«é·ãå Žåããã€ã³ããã¯ã¹ã«å¯ŸããŠreloptionsãå€æ°èšå®ããŠããå Žåã1ã€ãããã®ãµã€ãºã¯ãããã倧ãããªãã±ãŒã¹ããããŸãã
åæ°ã¯ããŒãã«æ°ãã€ã³ããã¯ã¹æ°ãããå€ããªãããšãã»ãšãã©ã§ãããããã¹ãããã·ã§ãããµã€ãºã«ãããŠãæ¯é çãªèŠçŽ ãšãªããããã§ãã以äžã®äŸã§ã¯ãã¹ãããã·ã§ãããµã€ãºã®ãã¡50%以äžãåæ å ±ãšãªã£ãŠããŸãã
ã¹ããŒãæ¡ä»¶ | ã¹ãããã·ã§ãããµã€ãº | ã¹ãããã·ã§ãããµã€ãº(ã€ã³ããã¯ã¹éšå) | ã¹ãããã·ã§ãããµã€ãº(åéšå) |
---|---|---|---|
ããŒãã«æ° 1000ãã€ã³ããã¯ã¹æ° 1000ãã«ã©ã æ° 10000(1ããŒãã«ããã10ã«ã©ã ) | 2.8MB | 0.34MB | 1.5MB |
ããŒãã«æ° 10000ãã€ã³ããã¯ã¹æ° 10000ãã«ã©ã æ° 100000(1ããŒãã«ããã10ã«ã©ã ) | 26MB | 3.3MB | 14.2MB |
pg_statsinfo ã¯èšå®ãã¡ã€ã«ãšããŠç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã® postgresql.conf ã䜿çšããŸãã èšå®ãã¡ã€ã«ã«èšèŒããå 容ã¯ãã€ã³ã¹ã¿ã³ã¹èµ·åæãšãªããŒãæ (pg_ctl reload) ã«èªã¿èŸŒãŸããåäœã«åæ ãããŸãã
pg_statsinfo ãå©çšããããã«å¿ é ã®ãã©ã¡ãŒã¿ã¯ä»¥äžã§ãã ãã©ã¡ãŒã¿ãåŸããå€æŽããããã«ã¯ PostgreSQL ã€ã³ã¹ã¿ã³ã¹ã®åèµ·åãå¿ èŠãªèšå®ããããŸãã
èšå®é ç® | èšå®å€ | 説æ |
---|---|---|
shared_preload_libraries | 'pg_statsinfo' | äºåèªèŸŒã¿çšã®ã©ã€ãã©ãªã®æå®ã pg_stat_statementsãpg_store_plans ã䜵çšããå Žå㯠'pg_stat_statements, pg_store_plans, pg_statsinfo, ' ã®ããã«ã«ã³ãåºåãã§æå®ããŸãã |
log_filename | 'postgresql-%Y-%m-%d_%H%M%S.log' | CSVãã°ããã³ããã¹ããã°ã®ãã¡ã€ã«åãããã©ã«ãããå€æŽããå Žåã§ãã%Y, %m, %d, %H, %M, %S ããã®é ã«å šãŠè¡šãã圢åŒã§ãªããã°ãªããŸããã |
track_counts | on | ããŒã¿ããŒã¹ã®æŽ»åã«é¢ããçµ±èšæ å ±ã®åéèšå®ã |
track_activities | on | ã»ãã·ã§ã³ã§å®è¡äžã®ã³ãã³ãã«é¢ããæ å ±ã®åéèšå®ã |
log_min_messages | debug5 ~ log | ãã°ãžåºåããã¡ãã»ãŒãžã¬ãã«ã 'log', pg_statsinfo.syslog_min_messages, pg_statsinfo.textlog_min_messages, pg_statsinfo.repolog_min_messages ã®ãããã®èšå®ããããããå€ããåºåããã¬ãã«ãèšå®ããå¿ èŠããããŸãã |
log_destination | 'csvlog' å¿ é / 'syslog', 'eventlog' ãè¿œå å¯èœ | ä»ã®å€ã§ãã£ãŠãããšãŒãžã§ã³ãèµ·åæã«åŒ·å¶çã« 'csvlog' ãè¿œå ããã'stderr' ã¯é€å»ãããŸãã |
logging_collector | on | ä»ã®å€ã§ãã£ãŠãããšãŒãžã§ã³ãèµ·åæã«åŒ·å¶çã«ãã®å€ã«èšå®ãããŸãã |
pg_statsinfo ãå©çšããããã«ç¢ºèªãæšå¥šããããã©ã¡ãŒã¿ã¯ä»¥äžã§ãã ãã©ã¡ãŒã¿ãåŸããå€æŽããããã«ã¯ãèšå®å€ã®ãªããŒã (pg_ctl reload) ããããã¯ã€ã³ã¹ã¿ã³ã¹ã®åèµ·å(pg_ctl restart)ãå¿ èŠã§ããåèµ·åãå¿ èŠãªãã®ã¯ä»¥äžã®èª¬æã®é ã«èšèŒããŠããŸãã
èšå®é ç® | ããã©ã«ãå€ | 説æ |
---|---|---|
track_functions | none | é¢æ°ã®åŒã³åºãã«é¢ããçµ±èšæ å ±ã®åéèšå®ã çµ±èšæ å ±ãåéããããã«ã¯ pl ãŸã㯠all ãèšå®ããŸãã |
track_io_timing | off | ãããã¯ã®èªã¿èŸŒã¿ãšæžã蟌ã¿æéã«é¢ããçµ±èšæ
å ±ã®åéèšå®ã ãããã¯ã®èªã¿æžãã«é¢ããçµ±èšæ
å ±ãåéããå Žå㯠on ãèšå®ããŸãã æ¬ãã©ã¡ãŒã¿ã on ã«èšå®ããå ŽåãçŸæç¹ã®æå»ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ç¹°ãè¿ãåãåãããã®ã§ããã©ãããã©ãŒã ã«ãã£ãŠã¯æ·±å»ãªè² è·ã®åå ã«ãªãå¯èœæ§ãããç¹ãçæããŠãã ããã |
log_checkpoints | off | ãã§ãã¯ãã€ã³ãç¶æ³ã®ãµãŒããã°åºåãon ãæšå¥šããŸãã |
log_autovacuum_min_duration | -1 | èªåããã¥ãŒã ç¶æ³ã®ãµãŒããã°åºåã0 ~ 1min ãæšå¥šããŸãã |
log_directory | 'log' | CSVãã°ããã³ããã¹ããã°ã®åºåå ãã£ã¬ã¯ããªã |
log_rotation_age | 1d | ãã°ããŒããŒãèšå® (æéã«ãããã°ãã¡ã€ã«åæ¿)ã |
log_rotation_size | 10MB | ãã°ããŒããŒãèšå® (容éã«ãããã°ãã¡ã€ã«åæ¿)ã |
syslog_facility | 'LOCAL0' | syslog ã® facility æå®ã |
syslog_ident | 'postgres' | syslog ã® indentæååæå®ã |
pg_stat_statements.track_planning | off | ã¯ãšãªã®çµ±èšæ å ±ã§"å®è¡èšç»çææé"ãååŸããå Žå㯠on ãèšå®ããŸãã |
pg_statsinfo.textlog_min_messages | warning | ããã¹ããã°ãžåºåããæå°ã¡ãã»ãŒãžã¬ãã« (*1) |
pg_statsinfo.syslog_min_messages | disable | syslog ãžåºåããæå°ã¡ãã»ãŒãžã¬ãã« (*1) |
pg_statsinfo.textlog_filename | 'pg_statsinfo.log' | ããã¹ããã°ãã¡ã€ã«åã空æåã¯ãšã©ãŒã |
pg_statsinfo.textlog_line_prefix | '%t %p ' | ããã¹ããã°ã®åè¡ã®å é ã«è¿œå ãããæžåŒ (*2) |
pg_statsinfo.syslog_line_prefix | '%t %p ' | syslog ã®åè¡ã®å é ã«è¿œå ãããæžåŒ (*2). syslog ãããã©ã«ãã§ä»äžããæå»ãšããã»ã¹IDã¯ããšãŒãžã§ã³ãã®ãã®ã«çœ®ãæãã£ãŠããŸããããå ã®å€ãèšé²ããããã« %t ã %p ãå¿ èŠãªããšã«æ³šæããŠãã ããã |
pg_statsinfo.textlog_permission | 600 | ããã¹ããã°ãã¡ã€ã«ã®ããŒããã·ã§ã³æå®ã |
pg_statsinfo.textlog_nologging_users | - | ããã¹ããã°ã®ãã£ã«ã¿ãªã³ã°èšå®ãããã¹ããã°ãžã®åºåãé€å€ãããŠãŒã¶ãèšå®ããŸããè€æ°ã®ãŠãŒã¶ãèšå®ããå Žåã¯ã«ã³ãåºåãã§æå®ããŸãã |
pg_statsinfo.repolog_min_messages | warning | ãªããžããªDBã«èç©ãããµãŒããã°ã®æå°ã¡ãã»ãŒãžã¬ãã«ã(*1) ç£èŠå¯Ÿè±¡DBãšãªããžããªDBãåäžã€ã³ã¹ã¿ã³ã¹ã®å Žåã«ã¯ disable (ç¡å¹)ã«ããããšãæšå¥šããŸã |
pg_statsinfo.repolog_nologging_users | - | ãµãŒããã°èç©ã®ãã£ã«ã¿ãªã³ã°èšå®ããªããžããªDBãžã®èç©ãé€å€ãããŠãŒã¶ãèšå®ããŸããè€æ°ã®ãŠãŒã¶ãèšå®ããå Žåã¯ã«ã³ãåºåãã§æå®ããŸãã |
pg_statsinfo.repolog_buffer | 10000 | ãµãŒããã°èç©æ©èœã®ãã¥ãŒãã³ã°èšå®ããããã¡ãªã³ã°ãããã°ã¬ã³ãŒãæ°ãæå®ããŸãã |
pg_statsinfo.repolog_interval | 10s | ãµãŒããã°èç©æ©èœã®ãã¥ãŒãã³ã°èšå®ããããã¡å ã®ãã°ããªããžããªDBãžæ ŒçŽããééãæå®ããŸãã(*3) |
pg_statsinfo.sampling_interval | 5s | ãµã³ããªã³ã°ã®å®è¡éé (*3) |
pg_statsinfo.snapshot_interval | 10min | ã¹ãããã·ã§ããã®ååŸéé (*3) |
pg_statsinfo.excluded_dbnames | 'template0, template1' | ç£èŠå¯Ÿè±¡ããé€å€ããããŒã¿ããŒã¹åã |
pg_statsinfo.excluded_schemas | 'pg_catalog, pg_toast, information_schema' | ç£èŠå¯Ÿè±¡ããé€å€ããã¹ããŒãåã |
pg_statsinfo.repository_server | 'dbname=postgres' | ãªããžããªDBãžã®æ¥ç¶æåå (*4)ããã¹ã¯ãŒãã®å ¥ååŸ ã¡ã¯é¿ãããäžè¬ãŠãŒã¶ã䜿çšããŠæ¥ç¶ããå Žåã¯ã ãã¡ã ã®æ³šæç¹ãã芧ãã ããã |
pg_statsinfo.adjust_log_level | off | ãµãŒããã°ã®ã¡ãã»ãŒãžã¬ãã«å€æŽèšå®ã |
pg_statsinfo.adjust_log_info | - | ã¡ãã»ãŒãžã¬ãã«ã INFO ã«å€æŽããã SQLSTATE ãã«ã³ãåºåãã§æå® (*5) |
pg_statsinfo.adjust_log_notice | - | adjust_log_info ãšåæ§ã§ã¡ãã»ãŒãžã¬ãã«ã NOTICE ã«å€æŽ |
pg_statsinfo.adjust_log_warning | - | adjust_log_info ãšåæ§ã§ã¡ãã»ãŒãžã¬ãã«ã WARNING ã«å€æŽ |
pg_statsinfo.adjust_log_error | - | adjust_log_info ãšåæ§ã§ã¡ãã»ãŒãžã¬ãã«ã ERROR ã«å€æŽ |
pg_statsinfo.adjust_log_log | - | adjust_log_info ãšåæ§ã§ã¡ãã»ãŒãžã¬ãã«ã LOG ã«å€æŽ |
pg_statsinfo.adjust_log_fatal | - | adjust_log_info ãšåæ§ã§ã¡ãã»ãŒãžã¬ãã«ã FATAL ã«å€æŽ |
pg_statsinfo.enable_maintenance | 'on' | èªåã¡ã³ããã³ã¹èšå®ãèªåã¡ã³ããã³ã¹ã§å®è¡ããæäœã以äžããéžæããŸããè€æ°ã®æäœãè¡ãå Žå㯠'snapshot, repolog' ã®ããã«ã«ã³ãåºåãã§æå®ããŸãã ã» 'snapshot': ã¹ãããã·ã§ããåé€ãå®è¡ããŸã ã» 'repolog': èç©ãã°åé€ãå®è¡ããŸã ã» 'log': ãã°ãã¡ã€ã«æŽçã³ãã³ããå®è¡ããŸã ã» 'on': ã¹ãããã·ã§ããåé€ãšèç©ãã°åé€ããã³ãã°ãã¡ã€ã«æŽçã³ãã³ããå®è¡ããŸã ã» 'off': äœãããªã |
pg_statsinfo.maintenance_time | '00:02:00' | èªåã¡ã³ããã³ã¹å®è¡æå»èšå®ã |
pg_statsinfo.repository_keepday | 7 | ã¹ãããã·ã§ããã®ä¿ææéèšå®ã |
pg_statsinfo.repolog_keepday | 7 | èç©ãã°ã®ä¿ææéèšå®ã |
pg_statsinfo.log_maintenance_command | <PGHOME>/bin/archive_pglog.sh %l | ãµãŒããã°ã®ãã°ãã¡ã€ã«ã®æŽçãå®è¡ããã·ã§ã«ã³ãã³ããæå®ããŸããæååå ã«'%l'ãèšè¿°ããå Žåã¯'%l'ããã°ãã¡ã€ã«æ ŒçŽãã£ã¬ã¯ããªã®çµ¶å¯Ÿãã¹ã«çœ®ãæãããŸããã·ã§ã«ã³ãã³ãã¯æ£åžžã«ã³ãã³ããçµäºããå Žåã«ã®ã¿æ£åžžçµäºå€(0)ãè¿ããŠãã ããã |
pg_statsinfo.long_lock_threshold | 30s | ããã¯ç«¶åæ å ±ã®åé察象ãšããæ¡ä»¶(éŸå€)ãã¹ãããã·ã§ããã®æç¹ã§çºçããŠããããã¯ç«¶åã®å ãããã¯åŸ ã¡ã®çµéæé(ç§)ãéŸå€ãè¶ããŠãããã®ãåé察象ãšãªããŸãã |
pg_statsinfo.stat_statements_max | 30 | pg_stat_statementsãpg_store_plansã§åéããæ å ±æ°ã®äžéã |
pg_statsinfo.stat_statements_exclude_users | - | pg_stat_statementsãpg_store_plansã§åéããæ å ±ã®ãã£ã«ã¿ãªã³ã°èšå®ãåé察象ããé€å€ãããŠãŒã¶ãèšå®ããŸããè€æ°ã®ãŠãŒã¶ãèšå®ããå Žåã¯ã«ã³ãåºåãã§æå®ããŸãã |
pg_statsinfo.long_transaction_max | 10 | ãã³ã°ãã©ã³ã¶ã¯ã·ã§ã³æ å ±ã®æ倧åé件æ°ã ãã®ãã©ã¡ãŒã¿å€æŽã«ã¯PostgreSQLã®åèµ·åãå¿ èŠãšãªããŸãã |
pg_statsinfo.controlfile_fsync_interval | 1min | pg_statsinfoã®å¶åŸ¡ãã¡ã€ã«ã®æŽæ°ãã¹ãã¬ãŒãžããã€ã¹ã«åææžãåºã(fsync)ããééãèšå®ããŸãã |
pg_statsinfo.enable_alert | off | ã¢ã©ãŒãæ©èœã®æå¹ïŒç¡å¹ãèšå®ããŸãã |
pg_statsinfo.target_server | - | ç£èŠå¯Ÿè±¡DBãžã®æ¥ç¶æåå (*4)ãpg_statsinfoã¯çµ±èšæ å ±åéãªã©ã®ããã«ç£èŠå¯Ÿè±¡DBãžæ¥ç¶ããŸãã ããã©ã«ãã§ã¯ãã®æ¥ç¶ã«DBã¯ã©ã¹ã¿äœææã®åæãŠãŒã¶ããã³åæããŒã¿ããŒã¹(postgres)ã䜿çšãããŸãã ãã®æ¥ç¶èšå®ãå€æŽããå¿ èŠãããå Žåã«ã¯åœè©²ãã©ã¡ãŒã¿ãèšå®ããŸãããªãããŠãŒã¶ãæå®ããå Žåã¯ã¹ãŒããŠãŒã¶ãæå®ããå¿ èŠãããããšã«æ³šæããŠãã ããã |
pg_statsinfo.rusage_max | 5000 | ã¯ãšãªåäœã§ã®ãªãœãŒã¹æ¶è²»éãååŸããããã®æ å ±æ°ã®äžéãpg_stat_statements.maxãšåå€ãèšå®ããããšãæšå¥šããŸãããã®ãã©ã¡ãŒã¿å€æŽã«ã¯PostgreSQLã®åèµ·åãå¿ èŠãšãªããŸãã |
pg_statsinfo.rusage_track | on | ã¯ãšãªåäœã®ãªãœãŒã¹æ¶è²»ååŸã®æå¹/ç¡å¹ãèšå®ããŸãã |
pg_statsinfo.rusage_track_utility | off | rusage_trackãæå¹ãªå Žåã«ãCOPYåŠçãªã©ã®ãŠãŒãã£ãªãã£ã³ãã³ãã®ãªãœãŒã¹æ¶è²»ååŸã®æå¹/ç¡å¹ãèšå®ããŸãã(*6) |
pg_statsinfo.rusage_track_planning | off | rusage_trackãæå¹ãªå Žåã«ãã¯ãšãªåŠçã®å®è¡èšç»äœææã®ãªãœãŒã¹æ¶è²»ååŸã®æå¹/ç¡å¹ãèšå®ããŸãã |
pg_statsinfo.rusage_save | on | ã¯ãšãªåäœã®ãªãœãŒã¹æ å ±ãPostgreSQLã®åæ¢ã»èµ·åããŸããã£ãŠèšé²ããŠããããèšå®ããŸãã |
pg_statsinfo.wait_sampling_max | 25000 | åŸ æ©ã€ãã³ãã®æ å ±æ°ã®äžéãpg_stat_statements.max * 10 çšåºŠã®å€ã«èšå®ããããšãæšå¥šããŸãããã®ãã©ã¡ãŒã¿å€æŽã«ã¯PostgreSQLã®åèµ·åãå¿ èŠãšãªããŸãã |
pg_statsinfo.wait_sampling_queries | on | åŸ æ©ã€ãã³ãã®æ å ±ååŸæã®ã¯ãšãªIDæ å ±ä»äžã®æå¹/ç¡å¹ãèšå®ããŸãã |
pg_statsinfo.wait_sampling_save | on | åŸ æ©ã€ãã³ãã®æ å ±ãPostgreSQLã®åæ¢ã»èµ·åããŸããã£ãŠèšé²ããŠããããèšå®ããŸãã |
pg_statsinfo.wait_sampling_interval | 10ms | åŸ æ©ã€ãã³ãæ å ±ã®ãµã³ããªã³ã°éé (*7) |
pg_statsinfo.collect_column | on | ã¹ãããã·ã§ããååŸæã«ããŒãã«ã®åæ å ±ã®ååŸã®æå¹/ç¡å¹ãèšå®ããŸããoffã«ãããšåæ å ±ãåéãããªããªããã¹ãããã·ã§ãããµã€ãºã®åæžãå¯èœã§ãããäžéšã®æ å ±ãã¬ããŒããããªããªããŸãã(*8) |
pg_statsinfo.collect_index | on | ã¹ãããã·ã§ããååŸæã«ã€ã³ããã¯ã¹æ å ±ã®ååŸã®æå¹/ç¡å¹ãèšå®ããŸããoffã«ãããšåæ å ±ãåéãããªããªããã¹ãããã·ã§ãããµã€ãºã®åæžãå¯èœã§ãããäžéšã®æ å ±ãã¬ããŒããããªããªããŸãã(*8) |
- 以äžã®å€ãæå®ã§ãããã®ã¬ãã«ãšãããããäžäœã®ã¬ãã«ã®ã¡ãã»ãŒãžãèšé²ãããŸãã å šãèšé²ããªãå Žåã«ã¯ disable ãæå®ããŸãã ç¬èªã« disable, alert ã¬ãã«ãè¿œå ãããŠããããšãšãdebug ãåºå¥ããªãããšãé€ããlog_min_messages ãšåãåªå é äœã§ãã disable > alert > panic > fatal > log > error > warning > notice > info > debug
- èšå®ãã©ã¡ãŒã¿ log_line_prefix ãšåã圢åŒã§æå®ããŸãã log_line_prefix ã®å€ãã®ãã®ã¯ç¡èŠãããããšã«æ³šæããŠäžããã
- åäœãšã㊠d(æ¥)ãh(æ)ãmin(å)ãs(ç§) ãæå®ã§ããŸããæå®ç¡ãã®å Žåã¯ç§åäœãšã¿ãªããŸãã
- äŸãã° 'host=127.0.0.1 port=5432 dbname=mydb user=postgres' ãšãã£ãlibpq圢åŒã®æ¥ç¶æ å ±æååã§ãã 詳现ã¯ããŒã¿ããŒã¹æ¥ç¶å¶åŸ¡é¢æ°ã®PQconnectdbãåç §ããŠäžããã ãã®ä»ãlibpq ã䜿çšããç°å¢å€æ°ã®åœ±é¿ãåããŸãã®ã§ããç°å¢å€æ°ããåç §ããŠäžããã ãã¹ã¯ãŒãã®å ¥ååŸ ã¡ã«ãªããªãããã«ããå¿ èŠããããŸãã ãã¹ã¯ãŒãèªèšŒãå¿ èŠãªå Žåã«ã¯ãPostgreSQL ã€ã³ã¹ã¿ã³ã¹èµ·åãŠãŒã¶ã« .pgpass ãèšå®ãããã¹ã¯ãŒãã®å ¥åãèªååããŠãã ããã ãã®éã«ã¯ãhost ãæå®ããªãå Žå㯠hostaddr ããã¹ãåãšããŠåç §ãããŸãã詳现ã¯ããã©ã¡ãŒã¿ããŒã¯ãŒãããåç §ããŠãã ããã
- SQLSTATE ã¯SQLæšæºã§èŠå®ããã5æåã®èšå·ã§ã"42P01" ã®ãããªåœ¢åŒã®æååã§ããè€æ°ã®SQLSTATEãæå®ãããå Žåã«ã¯ãã«ã³ãåºåãã§æå®ããŸãã
- pg_stat_statementsãshared_preload_librariesã«èšå®ããŠæå¹ã«ãããã€ãã®ãã©ã¡ãŒã¿ãæå¹ã«ããå Žåãshared_preload_librariesã«ã¯'pg_stat_statements, pg_statsinfo'ã®ããã«å ã«(å·ŠåŽã«)pg_stat_statementsãèšè¿°ããããã«ããŠãã ããããã®ãããªæå®ããããªãå ŽåãWARININGãã°ãåºåãããrusage_track_utilityã¯åŒ·å¶çã«offã«èšå®ãããŸãã
- åäœãšã㊠d(æ¥)ãh(æ)ãmin(å)ãs(ç§)ãms(ããªç§) ãæå®ã§ããŸããæå®ç¡ãã®å Žåã¯ããªç§åäœãšã¿ãªããŸãã
- collect_columnãoffã«ããå ŽåããNotable Tablesã®Correlationãå šãŠããNotable Tablesã®Low Density Tablesãã«ããLogical Pages ããã³ Logical Page Ratio(%)ã®2é ç®ãããã³ãSchema Informationã®Tableãã«ããColumnsã®é ç®ãã¬ããŒãã§ããªããªããŸãã collect_indexãoffã«ããå ŽåããNotable Tablesã®Correlationãå šãŠãããã³ãSchema Informationã®Indexesãå šãŠãã¬ããŒãã§ããªããªããŸãã
PostgreSQLãµãŒããçµäºãããããšãªã postgresql.conf ã®èšå®ãåæ ããããå Žåã¯ãPostgresSQLã®ãªããŒãã³ãã³ããå®è¡ããŸãã
$ pg_ctl reload
ãŠãŒã¶ãè¡ãå¿ èŠã®ããæäœãšéçšäžå¿ èŠãšãªãäœæ¥ã«ã€ããŠèª¬æããŸãã
äžèŠãšãªã£ãå€ããã°ãã¡ã€ã«(CSVãã°ãããã¹ããã°)ã¯å®æçã«åé€ããŠäžããã
äžèŠãšãªã£ããã°ãã¡ã€ã«ã®åé€ã¯æåã§è¡ãããèªåã¡ã³ããã³ã¹ã®ãã°ãã¡ã€ã«æŽçãå©çšããŠäžããã
æªäœ¿çšãšãªã£ãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãåé€ããå Žåã¯ããªããžããªDBãçŽæ¥æäœããŠãã ããã
ãªããã€ã³ã¹ã¿ã³ã¹æ
å ±ãåé€ãããšé¢é£ããã¹ãããã·ã§ãããå
šãŠåé€ãããŸãã
ã€ã³ã¹ã¿ã³ã¹æ å ±ã®åé€æé ã以äžã«ç€ºããŸãã
$ psql -d postgres -c "DELETE FROM statsrepo.instance WHERE instid = "
ä»»æã®ã¿ã€ãã³ã°ã§ãã°ãããŒããŒãããããå Žåã¯ãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«ãŠä»¥äžãå®è¡ããŠäžããã
$ psql -d postgres -c "SELECT pg_rotate_logfile()"
ãšãŒãžã§ã³ãã®ã¿ãç°åžžçµäºããŠããPostgreSQL
ã€ã³ã¹ã¿ã³ã¹ã«ã¯åœ±é¿ã¯ãããŸãããããšãŒãžã§ã³ãã®æ©èœã¯åæ¢ãããŸãŸã«ãªã£ãŠããŸããŸãã
ãšãŒãžã§ã³ããåèµ·åããã«ã¯ PostgreSQL ã€ã³ã¹ã¿ã³ã¹ãåèµ·åããŠãã ããã
ãªãããšãŒãžã§ã³ããç°åžžçµäºããŠããåèµ·åãããŸã§ã®éã«åºåããããµãŒããã°ã¯ãåèµ·åæã«è§£æ(ãµãŒããã°ã®åé
ã®ã¿)ãããŸãã
pg_statsinfo ãã¢ã³ã€ã³ã¹ããŒã«ããã«ã¯ãPostgreSQL ã€ã³ã¹ã¿ã³ã¹ã®åèµ·åãå¿
èŠã§ãã postgresql.conf
ã® shared_preload_libraries
ãã pg_statsinfo ãåãé€ããå
šãŠã®
pg_statsinfo.*
ãã©ã¡ãŒã¿ãåé€ããåŸã«ãPostgreSQL ãåèµ·åããŠäžããã
ãã®åŸãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã«ã€ã³ã¹ããŒã«ããã pg_statsinfo ã䜿çšãããªããžã§ã¯ããåé€ããŸããç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã® postgres ããŒã¿ããŒã¹ã«å¯Ÿã $PGSHARE/contrib/uninstall_pg_statsinfo.sql ãå®è¡ããŠäžããã
$ psql -d postgres -f $PGSHARE/contrib/uninstall_pg_statsinfo.sql
ååŸæžã¿ã®ã¹ãããã·ã§ãããäžèŠãªå Žåã«ã¯ããªããžããªDBã«æ¥ç¶ãã$PGSHARE/contrib/uninstall_pg_statsrepo.sql ãå®è¡ããŠäžããã ãã®æäœã§ã¯ãªããžããªDBã«èç©ããå šãŠã®ã¹ãããã·ã§ãããåé€ããŸãã®ã§ããªããžããªDBãå ±æããŠããå Žåã«ã¯ç¹ã«æ³šæããŠäžããã
$ psql -d <repository> -f $PGSHARE/contrib/uninstall_pg_statsrepo.sql
pg_statsinfo ã䜿çšããéã«ã¯ã以äžã®äœ¿çšäžã®æ³šæãšå¶çŽããããŸãã
-
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã§ã¯ãšã³ã³ãŒãã£ã³ã°ãš lc_messages ã®çµ±äžãå¿ èŠ
pg_statsinfo 㯠PostgreSQL ããµããŒããããšã³ã³ãŒãã£ã³ã°ãã¡ãã»ãŒãžã»ãã±ãŒã«ã«å¯Ÿå¿ããŠããŸãããæ··åšãããããšã¯ã§ããŸããã PostgreSQL ãåºåãããµãŒããã°ã«ãã°ãæ··åšããŠããŸãããã解æã«å€±æããŸãã -
log_filename ã®å¶é
pg_statsinfo ã§ã¯ã以äžãæºããèšå®å€ãæåŸ ããŠããŸãã- ãµãŒããåèµ·åãããã³ã«ãæ°ãããµãŒããã°ã«åãæ¿ããã(ç§ç²ŸåºŠãªã©ãååé«ãæé粟床ã®ãã¡ã€ã«åãå©çšãããŠãã)
- ãµãŒããã°ã®ååã¯æ°æ§ã«å¿ããŠæé ã®ååã«ãªãã
ãã®ãããèšå®å€ãå€æŽããå Žåã«ã¯ãå€æŽåã®å šãŠã®ãã°ãã¡ã€ã«ãåé€ããŠãã ããã ãã°ãã¡ã€ã«ã®æ°æ§ãååã«åºã¥ããŠå€æããŠããããããœãŒãé ãå€åãããããªèšå®å€æŽæã«åäœäžè¯ãèµ·ããå¯èœæ§ããããŸãã
-
pg_statsinfo.textlog_filename ã®å¶é
åºå®ãã¡ã€ã«åã®ããã¹ããã°ã¯å¿ é ã§ãã䜿ããªãèšå®ã«ã¯ã§ããŸããã -
fast åã³ immediate ã·ã£ããããŠã³æã®ãšã©ãŒã¡ãã»ãŒãž
PostgreSQL ãµãŒãã®ã·ã£ããããŠã³ã®éãåæ¢ã¢ãŒãã®æå®ã smart ã¢ãŒã以å€ã®å Žåã¯æ¥ç¶ãšã©ãŒãçºçããå ŽåããããŸãã ãã㯠ãšãŒãžã§ã³ãã®ããŒã¿ããŒã¹åæãåŸ ããã«ãµãŒããã·ã£ããããŠã³ãããããã§ãã çµäºæã«ãšã©ãŒã¡ãã»ãŒãžãåºåãããŠãåé¡ã¯ãããŸããã ãŸããsmart ã·ã£ããããŠã³ã§ããã°ãšã©ãŒã¯çºçããŸããã -
ã·ã£ããããŠã³ã»ãã§ãã¯ãã€ã³ãã¯åéã§ããªã
ã·ã£ããããŠã³æã®ãã§ãã¯ãã€ã³ããã°ã¯ãªããžããªDBã«ä¿åãããŸããã åå± æ§æã®å Žåã«ã¯æ¢ã«ãªããžããªDBãçµäºããŠããŸã£ãŠããããã§ãã -
ã¹ãããã·ã§ããååŸãšããŒãã«åé€ã®åæå®è¡
ã¹ãããã·ã§ããååŸãšããŒãã«åé€ãåæã«èŠæ±ããããšãã¿ã€ãã³ã°ã«ãã£ãŠã¯ã¹ãããã·ã§ããååŸã§ãšã©ãŒãçºçããå¯èœæ§ããããŸãã ãšã©ãŒãçºçããå Žåãã¹ãããã·ã§ããååŸã¯ãªãã©ã€ãããŸãã -
è€æ°ã®ç£èŠã€ã³ã¹ã¿ã³ã¹ã®èšå®ã«ã€ããŠ
åã€ã³ã¹ã¿ã³ã¹æ¯ã«ãããŒã¿ããŒã¹ã·ã¹ãã èå¥å or OSãã¹ãå or Portçªå·ã®ãããããç°ãªã£ãŠããªãå Žåãè€æ°ã€ã³ã¹ã¿ã³ã¹ãšããŠèªèã§ããŸããã -
èªåã¡ã³ããã³ã¹(ã¹ãããã·ã§ããåé€)ã®æ³šæç¹
è€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ãããåäžã®ãªããžããªDBã«èç©ããæ§æã§ã¯ã èªåã¡ã³ããã³ã¹èšå®ã®ã¹ãããã·ã§ããä¿ææéã®èšå®ã«æ³šæããŠãã ããã
è€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã§èªåã¡ã³ããã³ã¹ã®ã¹ãããã·ã§ããåé€ãæå¹ãšããå Žåã ããããã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ããä¿ææéã®èšå®ã§ã¹ãããã·ã§ããåé€ãå®è¡ãããŸãã
ãã®ãããçµæçã«ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®äžã§æãæéã®çãã¹ãããã·ã§ããä¿ææéãæå¹ãšãªããŸãã -
ãã©ã³ã¶ã¯ã·ã§ã³ãã°(WAL)ã®åºåéã®çµ±èšæ å ±åéã«é¢ããå¶é
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãã¬ããªã±ãŒã·ã§ã³æ§æã®ã¹ã¿ã³ãã€ã®å Žåã¯ããã©ã³ã¶ã¯ã·ã§ã³ãã°(WAL)ã®åºåéã®çµ±èšæ å ±ãåéãããŸããã -
ã¬ããŒãå šè¬ã«é¢ãã泚æç¹
ããŒã¿ãµã€ãºãªã©ã瀺ãäžéšã®é ç®ã®å€ã¯ãåäœæç®ã§ã®æ°å€ã®åãæšãŠã«ãã埮å°ãªå€ãååšããã«ãããããããŒããšè¡šç€ºãããå¯èœæ§ãããã -
ãµãŒããã°èç©æ©èœã«é¢ãã泚æç¹
ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã倧éã®ãµãŒããã°ãåºåããå Žåã¯ããªããžããªDBãžã®ãµãŒããã°ã®èç©ãé 延ããå¯èœæ§ããããŸãã é 延ãçºçããŠããå Žåã¯å ¥åå ã®CSVãã°ãã¡ã€ã«ã移åïŒåé€ããªãããã«ããŠãã ããã ãŸãã¯ããµãŒããã°èç©æ©èœã®ãã£ã«ã¿ãªã³ã°èšå®ã䜿çšããŠé 延ãçºçããªãããã«ãã°ã®èç©éã調æŽããŠãã ããã -
ãªããžããªDBãžã®æ¥ç¶ã«äžè¬ãŠãŒã¶ã䜿çšããéã®æ³šæç¹
ãªããžããªDBãžã®æ¥ç¶ã«äžè¬ãŠãŒã¶ã䜿çšããå Žåã¯ãåœè©²ãŠãŒã¶ã«ãªããžããªDBã®ããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹æš©éãå¿ èŠã§ãã ãã®ãããäžè¬ãŠãŒã¶ã§æ¥ç¶ãè¡ãå Žåã¯ããã®æ¥ç¶ãŠãŒã¶ãææè ãšãªãããã«ãªããžããªããŒã¿ããŒã¹ãäœæããããšãæšå¥šããŸãã
æ¥ç¶çšã®äžè¬ãŠãŒã¶ã®äœæããã³ãã®ãŠãŒã¶ãææè ãšãªãããŒã¿ããŒã¹ã®äœæã®ããã«ã¯ã以äžã®ã³ãã³ããå®è¡ããŸãã$ createuser -DRSl -U <DB管çè ãŠãŒã¶å> <æ¥ç¶ãŠãŒã¶å> $ createdb -U <DB管çè ãŠãŒã¶å> -O <æ¥ç¶ãŠãŒã¶å> <ããŒã¿ããŒã¹å>
-
log_timezone ã®èšå®ã«é¢ãã泚æç¹
pg_statsinfo ã®ãã°ã¯ã·ã¹ãã (OS)ã®ã¿ã€ã ãŸãŒã³ã䜿çšããŠã¿ã€ã ã¹ã¿ã³ããçæããŸãã ãã®ãããlog_timezone ã«ã·ã¹ãã (OS)ãšç°ãªãã¿ã€ã ãŸãŒã³ãèšå®ããå Žåãpg_statsinfo ã®ãã°ã®ã¿ã€ã ã¹ã¿ã³ããã ãããã®ã¿ã€ã ãŸãŒã³éã®æå·®åããããæ¥æã§åºåãããŸãã -
log_timezone ã®å€æŽãå€æéã®åãæ¿ãæã®æ³šæç¹
log_timezone ã®å€æŽãå€æéã®åãæ¿ãã®åœ±é¿ã«ãããCSVãã°ãã¡ã€ã«ãææ°ã®ãã¡ã€ã«ããå€ãæ¥æã®ãã¡ã€ã«åã§äœæãããããšããããŸãã ãããã®CSVãã°ãã¡ã€ã«ã¯ pg_statsinfo ã§åŠçãããªãããšã«æ³šæããŠãã ããã -
äžéšã®ã¿ã€ã ãŸãŒã³ã§ã®ãã°ã®ãªããžããªæ ŒçŽã«ããã泚æç¹
ãã°ã®ã¿ã€ã ã¹ã¿ã³ãã«ã¯ã¿ã€ã ãŸãŒã³ã®çç¥åœ¢ãä»ããããŠããŸããããã®çç¥åœ¢ã®äžã«ã¯è€æ°ã®ã¿ã€ã ãŸãŒã³ã«é¢é£ä»ããããŠãããã®ããããŸãããªããžããªDBã«ãããŠãã®é¢é£ä»ããæ³å®ãšç°ãªã£ãŠãããšããã°ã®ã¿ã€ã ã¹ã¿ã³ããééã£ãŠè§£éãããŠãªããžããªã«æ ŒçŽãããŸããäŸãã° CST ã¯3ã€ã®æé垯ã«é¢é£ä»ããããŠããããã©ã«ãã§ã¯US/Central(CST-6) ãšãªã£ãŠããããããã®é¢é£ä»ãã®èšå®ãå€æŽããã«éçšãããšlog_timezone ã äžåœ(PRC=CST+8)ã«èšå®ãããµãŒããŒããã®ãã°ã®æå»ããªããžããªDBã§ã¯14æéé²ãã§è§£éãããããšã«ãªããŸãããªããžããªDBã§ä»¥äžã®ããã«å ¥åãšç°ãªãæå»ã衚瀺ãããå Žåã«ã¯èšå®ãå¿ èŠã§ããèšå®æ¹æ³ã¯ãã¡ããåç §ããŠãã ãããrepository=$ SET TIME ZONE 'PRC'; select '2014/1/1 0:0:0 CST'::timestamptz; timestamptz ------------------------ 2014-01-01 14:00:00+08 (1 row)
-
AUTOVACUUM/AUTOANALYZEã®ãã£ã³ã»ã«åå ã¯ãšãªã®åéã«é¢ããå¶é
AUTOVACUUM/AUTOANALYZEã®ãã£ã³ã»ã«åå ã¯ãšãªã¯log_min_messagesãdebug1~debug5ã«èšå®ããå Žåã®ã¿åéãããŸãã -
shared_preload_librariesã§ã®ã¢ãžã¥ãŒã«æå®é åº pg_statsinfoãšpg_stat_statementsã䜵çšããå Žåãshared_preload_libraries = 'pg_stat_statements, pg_statsinfo'ã®ããã«å ã«(å·ŠåŽã«)pg_stat_statementsãèšè¿°ããããã«ããŠãã ããããã®ãããªæå®ããããªãå Žåã以äžã®æ§ãªWARININGãã°ãåºåãããrusage_track_utilityã¯åŒ·å¶çã«offã«èšå®ãããŸãã
WARNING: pg_statsinfo.rusage_track_utility is set to false. HINT: pg_statsinfo must be loaded after pg_stat_statements when enable rusage_track_utility .
pg_statsinfo ãååŸããæ å ±ã¯ãstatsrepo ã¹ããŒãã«æ ŒçŽãããŠããŸãã ã³ãã³ãã©ã€ã³äžã§ä»¥äžã® SQL ãå®è¡ãã確èªããããšãã§ããŸãã
$psql -d postgres -c "SELECT statsinfo.snapshot('test')"
$psql -d postgres -c "SELECT * FROM statsrepo.snapshot WHERE COMMENT = 'test'"
2åç®ã®ã³ãã³ãã§ããã¹ãå®è¡ãã snapshot ã®æ å ±ã確èªãããã°ãæ£åžžã«åäœããŠããŸãã
pg_statsinfo ã®çµ±èšæ å ±ã®ååŸæ©èœã¯ããã®æç¹ã®çµ±èšæ å ±ãã¹ãããã·ã§ãããšããŠå®æçã«ååŸããæ©èœã®ã¿ã«ãªããŸãã ååŸããçµ±èšæ å ±ãããæçãªæ å ±ãèŠããå Žå㯠簡æã¬ããŒãæ©èœ ãå©çšããããpg_stats_reporter ãã䜿ããã ããã
èªåã¡ã³ããã³ã¹ã®èšå®ãæå¹ã«ãªã£ãŠããªãããšãèããããŸãã 以äžã®äºé ãç¹æ€ããŠãã ããã
- èªåã¡ã³ããã³ã¹ã®èšå®ããpostgresql.conf ã«é©åã«èšè¿°ãããŠããã
postgresql.conf ã®èªåã¡ã³ããã³ã¹èšå®ã 'on' ãŸã㯠'snapshot' ãå«ãŸããŠããã確èªããŠãã ããã- pg_statsinfo.enable_maintenance = 'on'
- pg_statsinfo.enable_maintenance = 'snapshot'
- pg_statsinfo.enable_maintenance = 'snapshot, log'
ã¢ã©ãŒãæ©èœãæå¹ã«èšå®ããã€ç§éã³ãããæ°ã®ã¢ã©ãŒãæ¡ä»¶(éŸå€)ãã0ãã«èšå®ããç¶æ
ã§ã¹ãããã·ã§ãããååŸããŠãã ããã
ã¹ãããã·ã§ããã®ååŸæã«ããµãŒããã°ã«ã¢ã©ãŒãã¡ãã»ãŒãžãåºåãããŠããã°ã¢ã©ãŒãæ©èœãæ£åžžã«åäœããŠããŸãã
ã¢ã©ãŒãæ©èœãæå¹ããã€ç§éã®ã³ãããæ°ã®ã¢ã©ãŒãæ¡ä»¶(éŸå€)ãã0ãã«èšå®ããã«ã¯ä»¥äžã® SQL ããªããžããªDBã«å¯ŸããŠå®è¡ããŸãã
# UPDATE statsrepo.alert SET enable_alert = true, commit_tps = 0;
ã¢ã©ãŒãæ©èœãæ£åžžã«åäœããããšã確èªããåŸã¯ãç§éã®ã³ãããæ°ã®ã¢ã©ãŒãæ¡ä»¶(éŸå€)ãå ã«æ»ããŠãã ããã
Q5. å€ãããŒãžã§ã³(3.1以å)ããã¢ããã°ã¬ãŒãããæ¹æ³ãæããŠãã ããã
å€ãããŒãžã§ã³ãã¢ã³ã€ã³ã¹ããŒã«ããåŸãæ°ããããŒãžã§ã³ãã€ã³ã¹ããŒã«ããŠãã ããã
ãŸããå€ãããŒãžã§ã³ã§ååŸæžã¿ã®ã¹ãããã·ã§ããã¯æ°ããããŒãžã§ã³ã§ã¯å©çšã§ããŸããã
ã¢ã³ã€ã³ã¹ããŒã«
ã®æé ã«åŸãããªããžããªDBã®ã¹ãããã·ã§ãããå
šãŠåé€ããŠãã ããã
äžèšã®æäœãè¡ã£ãåŸãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãåèµ·åããŠãã ããã
Q6. ç°¡æã¬ããŒãæ©èœã§ã¬ããŒãçæãå®è¡ãããšãããã¬ããŒãã衚瀺ãããŸããã
ãªããžããªDBã«æ ŒçŽãããŠããã¹ãããã·ã§ããã®ä»¶æ°ã2件æªæºã§ããå¯èœæ§ããããŸãã
ã¬ããŒãã®äœæã«ã¯2件以äžã®ã¹ãããã·ã§ãããå¿
èŠãšãªããŸãã®ã§ãã¹ãããã·ã§ããã®ååŸã2åå®è¡ãããã®ãåŸ
ã£ãŠããã¬ããŒãçæãå®è¡ããŠãã ããã
Q7. ç°¡æã¬ããŒãæ©èœã§ã¬ããŒãçæãå®è¡ãããšãããäžéšã®ã¬ããŒãé ç®ã衚瀺ãããŸããã
- Query Activity (Functions)
èšå®ãã¡ã€ã«ã®ãtrack_functionsãããnoneãã«èšå®ãããŠããå¯èœæ§ããããŸãã ãã®å Žåãåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«å«ãŸããŸããã åœè©²ã¬ããŒãé ç®ã衚瀺ããã«ã¯ãtrack_functionsãããnoneã以å€ã«èšå®ããŠãã ããã - Query Activity (Statements)
pg_stat_statements ãã€ã³ã¹ããŒã«ãããŠããªãå¯èœæ§ããããŸãã ãã®å Žåãåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«å«ãŸããŸããã åœè©²ã¬ããŒãé ç®ã衚瀺ããã«ã¯ pg_stat_statements ãã€ã³ã¹ããŒã«ããŠãã ããã - Query Activity (Plans)
pg_store_plans ãã€ã³ã¹ããŒã«ãããŠããªãå¯èœæ§ããããŸãã ãã®å Žåãåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«å«ãŸããŸããã åœè©²ã¬ããŒãé ç®ã衚瀺ããã«ã¯ pg_store_plans ãã€ã³ã¹ããŒã«ããŠãã ããã - Autovacuum Activity
èšå®ãã¡ã€ã«ã®ãlog_autovacuum_min_durationããã-1ãã«èšå®ãããŠããå¯èœæ§ããããŸãã ãã®å Žåãåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«å«ãŸããŸããã åœè©²ã¬ããŒãé ç®ã衚瀺ããã«ã¯ãlog_autovacuum_min_durationããã-1ã以å€ã«èšå®ããŠãã ããã - Checkpoint Activity
èšå®ãã¡ã€ã«ã®ãlog_checkpointsãããoffãã«èšå®ãããŠããå¯èœæ§ããããŸãã ãã®å Žåãåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«å«ãŸããŸããã åœè©²ã¬ããŒãé ç®ã衚瀺ããã«ã¯ãlog_checkpointsãããonãã«èšå®ããŠãã ããã - OS Resource Usage (IO Usage)
OS管çå€ã®èšæ¶ããã€ã¹ãŸãã¯åæ£ãã¡ã€ã«ã·ã¹ãã (NFSãªã©)ãå©çšããç°å¢ã§ã¯ãOSãªãœãŒã¹ã®ãã£ã¹ã¯I/Oæ å ±ãåéãããŸããã ãã®ãããåœè©²ã¬ããŒãé ç®ã«å¿ èŠãªæ å ±ãã¹ãããã·ã§ããã«ååšããªãå¯èœæ§ããããŸãã - Long Transactions
ã¬ããŒã察象ãšãªãæ å ±ãã¹ãããã·ã§ããã«ååšããªãå¯èœæ§ããããŸãã - Notable Tables
ã¬ããŒã察象ãšãªãæ å ±ãã¹ãããã·ã§ããã«ååšããªãå¯èœæ§ããããŸãã - Lock Conflicts
ã¬ããŒã察象ãšãªãæ å ±ãã¹ãããã·ã§ããã«ååšããªãå¯èœæ§ããããŸãã - Replication Activity
ã¬ããŒã察象ãšãªãæ å ±ãã¹ãããã·ã§ããã«ååšããªãå¯èœæ§ããããŸãã - Schema Information
äžéšã®ããŒã¿ããŒã¹ã®ã¹ããŒãæ å ±ãå«ãŸããŠãªãå Žåã¯ã該åœã®ããŒã¿ããŒã¹ã«æ¥ç¶ã§ããèšå®ã«ãªã£ãŠããã ã¯ã©ã€ã¢ã³ãèªèšŒ ãªã©ã確èªããŠãã ããããŸãäžéšã®æ å ±(Tablesã®ColumnãIndexes)ãååŸãããŠããªãå Žåãpg_statsinfo.collect_columnãpg_statsinfo.collect_indexãç¡å¹ã«ãããŠããªããã確èªããŠãã ããã
Q8. pg_store_plans ãã€ã³ã¹ããŒã«ããŠããã®ã«ã¬ããŒãã§ãã©ã³ã®çµ±èšæ å ±ãåºãŠããŸããã
pg_store_plans ã public
以å€ã®ã¹ããŒãã«ã€ã³ã¹ããŒã«ãããŠããå¯èœæ§ããããŸãã
ãã®å Žåã¯ãã°ã確èªãããšç¹°ãè¿ã以äžã®æ§ãªãšã©ãŒãèšé²ãããŠããã¯ãã§ãã
ERROR: pg_statsinfo: query failed: ERROR: relation "pg_store_plans" does not exist
ãã®å Žåã¯äžæŠ DROP EXTENSION ããã®ã¡ãæ瀺çã«ã¹ããŒãã public ãšæå®ã㊠CREATE EXTENSION ãå®è¡ããªãããŠãã ããã
CREATE EXTENSION pg_store_plans SCHEMA public;
ååã®ã¹ãããã·ã§ããååŸãæªå®äºã®ç¶æ
ã§æ¬¡ã®ã¹ãããã·ã§ããååŸãè¡ãããå Žåãä»ååã®ã¹ãããã·ã§ããååŸã¯ã¹ããããããŸãã
ãªããã¹ãããã·ã§ããååŸã§ã¯ããŒãã«ããã³ã€ã³ããã¯ã¹ã«å¯ŸããŠAccessShareLockãç²åŸãããããAccessExclusiveLockãç²åŸãããŠãããšã¹ãããã·ã§ããååŸãé
延ããããšããããŸãã
Q10. HAæ§æã«ãããŠãã§ã€ã«ãªãŒããçºçããå Žåã«ããã§ã€ã«ãªãŒãååŸã§ãã¹ã¿ã®ã€ã³ã¹ã¿ã³ã¹IDãå€ãã£ãŠããŸããŸãã
pg_statsinfo ã¯ãã€ã³ã¹ã¿ã³ã¹IDãã§ã€ã³ã¹ã¿ã³ã¹ãèå¥ããŸããã€ã³ã¹ã¿ã³ã¹IDã¯ç£èŠå¯Ÿè±¡ãµãŒãã®ãã¹ãåãããŒãçªå·ãšpg_controldata ã衚瀺ããããŒã¿ããŒã¹ã·ã¹ãã èå¥åããçæãããŸãããã®äžã§ãã¹ã¿ã®ãã¹ãåã¯ãã§ã€ã«ãªãŒããŒã®éã«å€ããããšãæ®éãªãããã®ããã«ãªããŸãã
pg_statsinfo 13 ããã®å€æŽç¹ã¯ä»¥äžã®éãã§ãã
- PostgreSQL 14ã«å¯Ÿå¿ (pg_statsinfo 14㯠PostgreSQL 14ã®ã¿ããµããŒãããŸã)
- ããã©ã«ãã§ã¢ã©ãŒãæ©èœãç¡å¹ã«ããŸãããpg_statsinfo.enable_alertãªãã·ã§ã³ã¯ããã©ã«ãã§offã«ãªããŸãããã¢ã©ãŒãæ©èœã䜿ãå Žåããã®ãªãã·ã§ã³ãæ瀺çã«onãŸãã¯trueãžå€æŽããŠãã ããã
- åŸ æ©ã€ãã³ãæ å ±ååŸçšã®å°çšã³ã¬ã¯ã¿ãŒã¹ã¬ããã皌åããããã«ãªããŸããããã®ã¹ã¬ããã¯ç£èŠå¯Ÿè±¡ã®ã€ã³ã¹ã¿ã³ã¹ã®postgresããŒã¿ããŒã¹ã§åžžæãµã³ããªã³ã°ãå®æœããŠããŸãããŸããã®ã³ã¬ã¯ã¿ãŒã®å¶åŸ¡çšã«æ°èŠãã©ã¡ãŒã¿ãè¿œå ãããŸããã
- ã¯ãšãªåäœã®OSãªãœãŒã¹æ å ±ãååŸã§ããããã«ãªããŸãããpg_stat_statementsãšåæ§ã«Hookæ©èœã䜿ããã¯ãšãªåŠçäžã®CPUæéãå®IOã®æ å ±ãåéããŸãããŸãåé察象ã®å¶åŸ¡çšã«æ°èŠãã©ã¡ãŒã¿ãè¿œå ãããŸããã
- ãã©ã¡ãŒã¿ã§åæ å ±ãã€ã³ããã¯ã¹æ å ±ã®åéãç¡å¹åã§ããããã«ãªããŸããããããã®æ å ±ãããŸãæçšã§ãªãã±ãŒã¹ã§ãã¹ãããã·ã§ãããµã€ãºãåæžãããå Žåã«å©çšã§ããŸãã
- åéããæ§èœæ
å ±ãå¢ããŸããã
- pg_stat_walã®æ å ±ãåéããŸããWALã®èªã¿æžãéãæéãªã©ãã¬ããŒãããŸãã
- ãã©ã³ã¶ã¯ã·ã§ã³IDã®æ¶è²»æ°ãåéããŸããåäœæéãããã®ãã©ã³ã¶ã¯ã·ã§ã³IDæ¶è²»æ°ãã¬ããŒãããŸãã
- autovacuumã®ãã°æ å ±ãããWALã®çæéã«é¢ããæ å ±ãIndexéšåã®VACUUM詳现æ å ±ãåéããŸããVACUUMæã«æžã蟌ãŸããWALã®éãã€ã³ããã¯ã¹ã®VACUUMæã«ã¹ãã£ã³ããããŒãžæ°ãåé€ã»ååããããŒãžæ°ãã¬ããŒãããŸãã
- pg_stat_replication_slotsã®æ å ±ãåéããŸããããžã«ã«ã¬ããªã±ãŒã·ã§ã³ãå©çšããŠããå Žåã«äŒæ¬ãããããŒã¿éãwal_senderãäžæçã«æ¶è²»ãããã£ã¹ã¯IOéãã¬ããŒãããŸãã
- CPUãšã¡ã¢ãªã®æ å ±ãåéããŸããOSããèŠããCPUæ°ãã¯ããã¯æ°ãã¡ã¢ãªãµã€ãºãã¬ããŒãããŸãã
- åŸ æ©ã€ãã³ãæ å ±ãåéããŸããã€ã³ã¹ã¿ã³ã¹æ¯ãDBæ¯ãã¯ãšãªæ¯ã®3ã€ã§æ¯é èŠå ãšãªã£ãŠããåŸ æ©ã€ãã³ããã¬ããŒãããŸãã
- ã¯ãšãªãæ¶è²»ããOSãªãœãŒã¹æ å ±ãåéããŸããDBæ¯ãã¯ãšãªæ¯ã«å®IO(read, write)ãCPUæé(user, sys)ãã¬ããŒãããŸãã
ããé«åºŠãªå©çšæ¹æ³ããå éšæ§æã«ã€ããŠèª¬æããŸãã
è€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãååšããå Žåã®æ§æãšããŠãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹æ¯ã«ãªããžããªDBãçšæããŠååã«ã¹ãããã·ã§ãããèç©ããæ§æãšãåç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã§å
±éã®ãªããžããªDBãçšæããŠã¹ãããã·ã§ãããèç©ããæ§æããããŸãã
ããã§ã¯ãåŸè
ã®åäžãªããžããªã«è€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®ã¹ãããã·ã§ãããèç©ããæ§æã«ã€ããŠèª¬æããŸãã
åç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®èšå®ãã¡ã€ã«ã«ãåäžã®ãªããžããªDBãåç
§ããå
容ã§ãpg_statsinfo.repository_serverããèšå®ããŸãã
以äžã«èšå®äŸã瀺ããŸãã
pg_statsinfo.repository_server = 'host=192.168.0.32 port=5432 user=postgres dbname=postgres'
ãªããžããªDBã¯åç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ããäžèšã§èšå®ããããŒã¿ããŒã¹ã«ãã¹ã¯ãŒãå
¥åãªãã«æ¥ç¶ã§ããå¿
èŠããããŸãã
åç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ãããªããžããªDBã«ãã¹ã¯ãŒãå
¥åãªãã«æ¥ç¶ã§ãããã
ã¯ã©ã€ã¢ã³ãèªèšŒ
ãèšå®ããŠãã ããã
- è€æ°ã®ç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã§èªåã¡ã³ããã³ã¹ã®ã¹ãããã·ã§ããåé€ãèšå®ãããŠããå Žåãç£èŠå¯Ÿè±¡ã€ã³ã¹ã¿ã³ã¹ã®äžã§æãæéã®çãã¹ãããã·ã§ããä¿ææéãæå¹ãšãªããŸãã
ãšãŒãžã§ã³ãèµ·åæããã³èšå®ãªããŒãæã«ãªããžããªDBã®æ£åœæ§ãã§ãã¯ãè¡ããŸãã
æ£åœæ§ãã§ãã¯ãå®æœããçµæãäžåãæ€åºãããå Žåã¯äžéšã®æ©èœãç¡å¹åããç¶æ
ã§åäœããã¢ãŒã(ãã©ãŒã«ããã¯ã¢ãŒã)ã«ç§»è¡ããŸãã
ãªããžããªDBã®æ£åœæ§ãã§ãã¯ã®å 容ããã³ãã©ãŒã«ããã¯ã¢ãŒãã§ç¡å¹åãããæ©èœã以äžã«ç€ºããŸãã
- ãªããžããªDBã«æ¥ç¶ã§ããã
- ãªããžããªDBã«ç»é²ãããŠãã statsrepo ã¹ããŒãã®ããŒãžã§ã³ãæ£ããã
- çµ±èšæ å ±ã®ååŸæ©èœ
- ãµãŒããã°èç©æ©èœ
- ã¢ã©ãŒãæ©èœ
- ã³ãã³ãã©ã€ã³æ©èœã§ã®ã¹ãããã·ã§ããååŸ
- èªåã¡ã³ããã³ã¹æ©èœã§ã®ã¹ãããã·ã§ããåé€
ãã©ãŒã«ããã¯ã¢ãŒããã埩æ§ãããšåçš®æ©èœãåéãããŸãã
ãã®éããã©ãŒã«ããã¯ã¢ãŒãã§åäœããŠããæéã®ã¹ãããã·ã§ããååŸãã¢ã©ãŒããèªåã¡ã³ããã³ã¹ã¯è£å®ãããŸããã
ãŸãããµãŒããã°ã®èç©ã¯ãã©ãŒã«ããã¯ã¢ãŒãã«ç§»è¡ããæç¹ã®ãã°ããè£å®ãè¡ãããŸãã
ãªããžããªDBã«æ¥ç¶ã§ããªãããšãåå ã§ãã©ãŒã«ããã¯ã¢ãŒãã®ç§»è¡ããå Žåã¯ããªããžããªDBã埩æ§ããæç¹ã§èªåçã«éåžžã¢ãŒãã«åŸ©æ§ããŸãã
ä»ã®åå ã«ãããã©ãŒã«ããã¯ã¢ãŒãã«ç§»è¡ããå Žåã¯ããªããžããªDBã埩æ§ããåŸã§èšå®ãªããŒããå®è¡ããŠãã ããã
ãã©ãŒã«ããã¯ã¢ãŒãã«ç§»è¡ããåå ã¯ãã°(ããã¹ããã° or syslog)ã«åºåãããå
容ããå€æã§ããŸãã
ãã©ãŒã«ããã¯ã¢ãŒãã«ç§»è¡ããæã®ãã°ã®åºåäŸã以äžã«ç€ºããŸãã
# ãªããžããªDBã«æ¥ç¶ã§ããªã
ERROR: pg_statsinfo: could not connect to database with "host=192.168.0.1 user=postgres": timeout expired
LOG: pg_statsinfo: pg_statsinfo is starting in fallback mode
# statsrepo ã¹ããŒãã®ããŒãžã§ã³ãåããªã
ERROR: pg_statsinfo: incompatible statsrepo schema: version mismatch
LOG: pg_statsinfo: pg_statsinfo is starting in fallback mode
ãªããžããªDBã®åŸ©æ§ã«é¢ããç¹æ€äºé ãšå¯ŸåŠæ¹æ³ã以äžã«ç€ºããŸãã
- ãªããžããªDBã«æ¥ç¶ã§ããªãå Žå
statsrepo ã¹ããŒãã®ããŒãžã§ã³ãåããªãå Žå
(æ£ããããŒãžã§ã³ã® statsrepo ã¹ããŒãã¯èšå®ãªããŒãæã«èªåçã«ç»é²ãããŸã)
pg_statsinfo ã¯PostgreSQLã®ãµãŒããµã€ãã§åäœãã pg_statsinfo ã©ã€ãã©ãªãšããšãŒãžã§ã³ããšããŠåäœããå®è¡ããã°ã©ã ã®2ã€ã®ã¢ãžã¥ãŒã«ã§æ§æãããŠããŸãã ã©ã€ãã©ãªã¯ããŒãçŽåŸã«åŒã°ããããã¯é¢æ°ãããšãŒãžã§ã³ããèµ·åããããããŠãŒã¶ããšãŒãžã§ã³ããæ瀺çã«èµ·åããããšã¯ãããŸããã
ããã§ã¯ãpg_statsinfoã®ãµãŒããã°åé æ©èœã®ãã°ããŒããŒãæã®åäœã説æããŸããæ¡åŒµåã«ã.copyããä»ããã¡ã€ã«ãåºæ¥ãã±ãŒã¹ãæ¡åŒµåã«ã.err.nããä»ããã¡ã€ã«ãåºæ¥ãã±ãŒã¹ã説æããŸãã
ãã°ããŒããŒãçºçæã®æå (æ¡åŒµåã.copyãã®ãã¡ã€ã«ãäœæãããã±ãŒã¹)
ä¿åçšããã¹ããã°çæã®éã«ãååã®ãã¡ã€ã«ãååšããŠæ¢ã«å 容ãæžãããŠããå Žåããã®ãã¡ã€ã«ã®ååã®æ¡åŒµåã«ã.copyããä»å ããŸãã ããã¯ã³ã³ãœãŒã«ãã°ã®å 容ã®æ¶å€±ãåé¿ããããã®åŠçœ®ã§ãã
ãµãŒãã¯ã©ãã·ã¥ãŸãã¯ãšãŒãžã§ã³ãåæ¢ã³ãã³ãã«ããåæ¢åŸã«ããšãŒãžã§ã³ããåéãããšãã®ãã¡ã€ã«ãçæãããããšããããŸãããšãŒãžã§ã³ãåéæã«ã¯ãæåŸã«åŠçããŠããCSVãã¡ã€ã«ãååšããªããšã察å¿ããã.logããã¡ã€ã«ã®æ¡åŒµåãã.err.nãã«ãªããŒã ããŸãã ãã®å ŽåããšãŒãžã§ã³ãåæ¢ããåŸã®éšåã®CSVãã¡ã€ã«ã®å 容ã¯åŠçãããŸããã
ãŸããããŒã¹ããã¯ã¢ããããã®èµ·åã®éã«ãã.err.nããã¡ã€ã«ãäœæãããå ŽåããããŸãããããé²ãããã«ã¯ããµãŒãèµ·ååã«DBã¯ã©ã¹ã¿ãã£ã¬ã¯ããªã®äžã®pg_statsinfo.controlãã¡ã€ã«ãåé€ããŠãã ããã
pg_ctl, psql, ãµãŒãã®æ§æ, çµ±èšæ å ±ã³ã¬ã¯ã¿, ã·ã¹ãã ã«ã¿ãã°, pg_stat_statements, pg_stats_reporter
Copyright (c) 2009-2022, NIPPON TELEGRAPH AND TELEPHONE CORPORATION