وأنا أقترح على قراءة نص التقرير أليكسي Lesovsky من البلشون الأبيض البيانات "أساسيات الرصد كيو"
في هذا التقرير ، سوف يتحدث أليكسي ليسوفسكي عن النقاط الرئيسية لإحصاءات ما بعد الإجمالي ، وما الذي تعنيه ولماذا يجب أن يكونوا حاضرين في المراقبة ؛ حول الرسوم البيانية التي يجب مراقبتها ، وكيفية إضافتها وكيفية تفسيرها. سيكون التقرير مفيدًا لمسؤولي قواعد البيانات ومسؤولي النظام والمطورين المهتمين باستكشاف أخطاء Postgres وإصلاحها.
![](https://habrastorage.org/webt/xl/1u/xv/xl1uxvtdp44jf9gizjidcg93kmw.png)
اسمي أليكسي ليسوفسكي ، أمثل Data Egret.
بضع كلمات عن نفسك. لقد بدأت ذات مرة كمسؤول نظام.
Linux, , Linux, . . , , . . - , PostgreSQL. . - PostgreSQL . PostgreSQL DBA.
, , . , Zabbix. zabbix-extensions. . , Linux, .
PostgreSQL. , PostgreSQL-. pgCenter ( — ).
![](https://habrastorage.org/webt/1d/un/kw/1dunkwxe4pkli0hoah4nqhi7yrw.png)
. , ? - , . , : «, , - , ». , – PostgreSQL, MySQL - . : « , - . ». . , - , PostgreSQL - . - GitHub, , , - . .
![](https://habrastorage.org/webt/6l/2y/w0/6l2yw0c4nzmeqfcohrqca2mdjc4.png)
, PostgreSQL, . , , - , , - , .
, , , noSQL. PostgreSQL, , PostgreSQL. , , PostgreSQL . , , , .
![](https://habrastorage.org/webt/pb/ck/_s/pbck_sy2jm4nui5jwovhwtqynx8.png)
, . - . .
, - . , . .
![](https://habrastorage.org/webt/c4/0e/r3/c40er3shpzf7pypz851w-ogqfz4.png)
, . – , . . - , . , , , , - .
, , - , . .
– , , – . , . – . . .
PostgreSQL, , . . PostgreSQL , , Stats Collector, , .
(view). . . . psql , select , - PostgreSQL.
, , .
, . -- , .
![](https://habrastorage.org/webt/jl/te/-o/jlte-o2cwfcpnybgpcpkmowyikw.png)
, ? , – , , .
![](https://habrastorage.org/webt/ft/tf/rw/fttfrwfjwddtof7072_5z5we9em.png)
, , , , . .
![](https://habrastorage.org/webt/cs/a8/nz/csa8nz-nwi3zwzgsfidygezo-b0.png)
, , , , : , . . . (workload), .
![](https://habrastorage.org/webt/li/x3/ac/lix3ac_adcpu7liugrziyfr63v4.png)
, , . , , , , , , - , .
![](https://habrastorage.org/webt/iu/5b/zl/iu5bzledrcomvnkgllq6ly3ab70.png)
, – . , . , . , .
![](https://habrastorage.org/webt/rf/g_/_d/rfg__dxiymo_ci50a399tzjkgsi.png)
. , , . , , .
![](https://habrastorage.org/webt/cd/nh/8s/cdnh8s7ws4q5eanxopxgp16v3iu.png)
- , , - - . , .
![](https://habrastorage.org/webt/py/bs/kb/pybskbd78ziwnglfsbpzbnmmx90.png)
– . ? – , . . , , , . . .
![](https://habrastorage.org/webt/tw/gw/bl/twgwblgpnrcmzxvedqsx4jw_7e4.png)
, . , . – .
, , . - , , - , , drilldown-, .
![](https://habrastorage.org/webt/9o/2m/jw/9o2mjwutdfyl-1gcbdvip8nekyg.png)
. . , , . « ». , , , . - , , , . , . . , , . .
![](https://habrastorage.org/webt/id/6v/gm/id6vgmzd77nqf8tcwe0i42bunmg.png)
? . PostgreSQL pg_stat_statements. , , . , .
, , . . – , . , PostgreSQL . - , , . . 'select 1' , , .
, . pg_stat_database. xact_rollback. rollback, , . , . , , , .
![](https://habrastorage.org/webt/sk/au/j1/skauj1gvgadyam6vr82r-cutnaa.png)
, . . , , , , , - backend . , , - , , , .
, pg_stat_database. commit rollback .
, ? TPS QPS .
pg_stat_statements . , , , , .
![](https://habrastorage.org/webt/hb/ry/5s/hbry5s7tcdkjdqosl3berg8lofy.png)
, – - downtime.
– uptime. uptime PostgreSQL – . , . PostgreSQL , uptime. - , , - , OOM-killer PostgreSQL, PostgreSQL , shared . , , . . , downtime. uptime , postmaster . .
. , autovacuum PostgreSQL? PostgreSQL. , . , , . . . , , , .
? . .
pg_stat_activity, . . , . , , PostgreSQL - .
PostgreSQL , PostgreSQL . , , . , , stat idle-in-transaction. , . – , . , , , . , , . - , , 10-20-30 OLTP-, , , . 10-20-30 – , .
![](https://habrastorage.org/webt/vq/_7/xi/vq_7xixmgif8pmdk6x4gp_3qhik.png)
. , , .
, , PostgreSQL, . , .
. . , , . .
, , , . idle.
. , , , - , , , , . . . . - (Exception), . PostgreSQL. PostgreSQL . . , .
. - . , : , - , - , . , , , - . , . , . , . . .
![](https://habrastorage.org/webt/d9/wd/h1/d9wdh1zrvcztf-oyizmjy4un_gg.png)
. . . DB connection – 8 . . , , idle, . , . . , . .
![](https://habrastorage.org/webt/fd/ci/jh/fdcijh_xlquqrarmuhpabbzj4m4.png)
, , pg_stat_activity. PostgreSQL, , , PostgreSQL, . . . , : , , , , , . , , stat. , stats-, , stat- . .
. , , . xact_start query_start. , , . now(), timestamp . , .
, . OLTP- – 1-2-3 . OLAP- , , , - .
![](https://habrastorage.org/webt/dl/1k/m2/dl1km2ykdkvix6jc1r5basiqr60.png)
, . , , . , .
, , «». , , «» - SSD . , - , - «» , SATA , .
. , - . , . , . , update delete. .
«» . ? PostgreSQL . . ? , PostgreSQL , . : , NULL , .
, .
, «». , - , . . , , . , - , .. 100 ( limit 100), . .
. , explain, , . . .
![](https://habrastorage.org/webt/cl/uw/ek/cluwekccoze7_9-to2czfkbbezo.png)
. , , . Prometheus? Prometheus? , PostgreSQL – postgres_exporter Prometheus. .
![](https://habrastorage.org/webt/wa/86/e7/wa86e7wnc4q2n_f5tx9jywxl9gy.png)
. unity , . . 5 . Insert data, Update data, Delete data, Fetch data Return data. unit . , PostgreSQL tuple (). , , – , , tuple – , tuple – , . . . tuples – . , , , .
![](https://habrastorage.org/webt/7n/vd/va/7nvdvam1xg6_yspv3b68olsdzqm.png)
? PostgreSQL . – pg_stat_user_tables. User_tables – , , . , PostgreSQL. Alltables, , . , .
insert, update delete. , , . . , tuples, , .
, , TopN-. , Top-5, Top-10. , . , 5 «» . TopN- , .
, , , , , . .
![](https://habrastorage.org/webt/bx/mf/s6/bxmfs6rqednkdmwn7k73qguqdjm.png)
. , ? ?
![](https://habrastorage.org/webt/aa/qu/g_/aaqug_3cst7nts2apmvlrqbuhi4.png)
. ? . . , . , host , , . Top, PostgreSQL, - . Top , .
![](https://habrastorage.org/webt/er/2u/7h/er2u7hh2jw85vcygscethiomsf8.png)
, , , , , , PostgreSQL , . – 80-85-90 %. . , , , , , . - , .
![](https://habrastorage.org/webt/hr/cl/hq/hrclhqe4jpnega7-sherpwkdqta.png)
, . . . , , , . , . , , , . .
![](https://habrastorage.org/webt/a1/kz/ly/a1kzlyymrmazn9tiz29tlcvvv_g.png)
pg_stat_statements. . , , . . , . , , - .
, . . , . , -. total_time, mean_time, blk_write_time blk_read_time.
, , , , , - .
. , . , - , . .
, .
![](https://habrastorage.org/webt/qi/ar/n5/qiarn5pmssbpvc3cadbtfuk2any.png)
. – , autovacuum .
![](https://habrastorage.org/webt/g8/99/rq/g899rqri4mcpvzzihmurqu0moli.png)
. Maintenance, , - . , . , , .
![](https://habrastorage.org/webt/3e/l2/cv/3el2cvgxtmy8nlqvrcevhbklcwi.png)
, , «» shared , . , PostgreSQL .
, «» , . , , – . - , . . .
, pg_stat_bgwriter . - ( 10-15-20 , ) , , 3-4-5, . , , . , - . , . , .
![](https://habrastorage.org/webt/w6/7e/en/w67een_jmwnxmp-x_3yyhltlrvq.png)
autovacuum, , , , , autovacuum.
autovacuum . , , , autovacuum , , autovacuum .
. , DBA - , . - . , . PostgreSQL – . , , .
, , . , , , , , . , (3-4 ), . , . – . , , . , , .
![](https://habrastorage.org/webt/p0/r2/fg/p0r2fgfuhfhkkscs1unjolabev4.png)
PostgreSQL, . – .
PostgreSQL . . , . .
, pg_stat_replication. . 10 . -, . . 10- , . . 10 . 10- , . . , – . .
, , . pg_stat_replication. , pg_xlog_location_diff() . . .
10- pg_wal_lsn_diff(). , , , , «xlog», «wal». , . .
10- , . write lag, flush lag, replay lag. . . . , , , , .
![](https://habrastorage.org/webt/cr/p8/zq/crp8zqv7oyiw36whgcmwebgeypq.png)
. , . , , swap, . .
, . , . iops . latency . , , . latency, , - . , , . , .
, /proc, . , . .
. , , latency , .
![](https://habrastorage.org/webt/xb/g5/cx/xbg5cxtflzyhdqbw1dyq1q1qcts.png)
. , - . , , , - .
, , .
:
- , , , .
- , , .
- , . .
- , , . , , , . .
- , , .
- , , .
![](https://habrastorage.org/webt/nv/nq/dl/nvnqdlznfjswg6ze4x1cr5iuo1u.png)
, .
http://bit.do/stats_collector — . . , . , .
:
http://bit.do/dataegret_sql
http://bit.do/lesovsky_sql
. . select* from - . , , , , . . , . , , , , .
: , , - – ?
: -. , . , . Zabbi. TopN-. Okmeter, . PostgreSQL . pet-project, Prometheus Grafana. Prometheus Grafana.
: - AWR- … ? - ?
: , , AWR, . , . baselines PostgreSQL . , . sql.ru PostgreSQL. . , , . pgCenter , .
P.S.1 c postgres_exporter, ? . . m ?
P.S.2 pganalyze, is a proprietary SaaS offering which focuses on performance monitoring and automated tuning suggestions.