Sugiro que vocĂŞ se familiarize com a decodificação do relatĂłrio de inĂcio de 2019 por Alexey Lesovsky - “Solução de problemas do pgCenter com o Postgres”
De tempos em tempos, surgem problemas ao usar o Postgres, e quanto mais rápidas as fontes do problema são encontradas e resolvidas, mais agradecidos os usuários. O pgCenter é um conjunto de utilitários da CLI que é uma ferramenta poderosa para identificar e corrigir problemas aqui e agora. Neste relatório, mostrarei como usar efetivamente o pgCenter para encontrar e corrigir problemas, em quais direções procurar e como responder a determinados problemas, em particular, como:
- verifique se está tudo bem com o Postgres;
- encontre rapidamente clientes ruins e elimine-os;
- identificar solicitações pesadas;
- e outros truques Ăşteis com o pgCenter.
![](https://habrastorage.org/webt/qn/a4/mf/qna4mfqgy2rzglomcwb7vqfzf6c.png)
, . Data Egret. . , PostgreSQL.
, pgCenter , .
![](https://habrastorage.org/webt/yr/w0/xq/yrw0xql9iojdv71lootxkstpnp4.png)
. . Linux, , . - Postgres'. Postgres . PostgreSQL DBA. , Postgres . .
![](https://habrastorage.org/webt/un/iq/hn/uniqhn3vizz01sw-ehwfqinuou4.png)
. : Slack, Telegram. - . .
![](https://habrastorage.org/webt/by/b_/v5/byb_v5zrziwqg7uynekxbgicm5g.png)
, , Linix. . , Linux . , , .
![](https://habrastorage.org/webt/dw/9v/fx/dw9vfxixzbtylmq8ngyde_m0tac.png)
, Postgres. Postgres. - Postgres'. Postgres. Postgres.
![](https://habrastorage.org/webt/h6/yh/wi/h6yhwi0yvjcmfvtwcsp4lpd1-ew.png)
Postgres . Postgres Postgres. , Postgres (views), .
. . . - .
![](https://habrastorage.org/webt/qs/is/z5/qsisz5kh0nwff3fnhyuuedmi4ac.png)
- , , , , , . - . : « ?», « ?» « ?». , .
![](https://habrastorage.org/webt/hy/1d/js/hy1djsfn24oaxtvtoenwfutnae0.png)
, , , , . - pgCenter.
. , TOP- .
- , C . .. . Golang, , . .
Go pgCenter . . , , , targz, deb- rpm- . .. - , make, GCC Golang. , , .
![](https://habrastorage.org/webt/r_/ml/jv/r_mljvrlw4cy-on_0xjshhku_p8.png)
pgCenter , top- ( ).
![](https://habrastorage.org/webt/ec/zn/ll/ecznll_0zub4khs1n2jmokshn30.png)
. , . wait_events. , -.
![](https://habrastorage.org/webt/ky/ug/ln/kyuglnhkaayl8bu3h1fc08uzz48.png)
PSQL. Postgres, PSQL Postgres. pgCenter , «pgcenter top» postgres - (-, ).
![](https://habrastorage.org/webt/9q/h_/m_/9qh_m_wcabojkl4lpuxcksrp9ae.png)
, - , , , , PSQL, , , .
![](https://habrastorage.org/webt/1t/f9/bw/1tf9bw-l988uxgquo3_vxflodfu.png)
, UNIX-, . . go' , pgCenter , UNIX.
![](https://habrastorage.org/webt/c1/6h/vm/c16hvmt1ulij9-dtagepnodbtxq.png)
, libpq. , , pg_stat_statements pgCenter , . .
![](https://habrastorage.org/webt/7s/vg/kx/7svgkxnps7ythlgby1qopvdffmy.png)
(pgcenter top). , , . , - . , , . . , pgCenter, top-, .
![](https://habrastorage.org/webt/mx/xj/9y/mxxj9ydlc1chuzs0y6rkbtfop2w.png)
– . .
![](https://habrastorage.org/webt/ty/ex/8x/tyex8xl56ktalumc-pddn1sigo4.png)
– , Postgres. - , Postgres .
![](https://habrastorage.org/webt/66/ku/np/66kunpjqe9jcqa3kas1dhrbrghe.png)
– (views). stat-, Postgres, .
![](https://habrastorage.org/webt/a7/sd/ar/a7sdarvtow0y-pcvvedv7ckkqjs.png)
, . -, . . , , , , . .
, . (regexp). . , , - : .
![](https://habrastorage.org/webt/pf/mw/vx/pfmwvxrsdgjc_12luq9vaebret8.png)
, pgCenter. – - .
![](https://habrastorage.org/webt/hj/or/qw/hjorqwuc5pn4khboewm2ou3cim0.png)
, USE . . - , .
![](https://habrastorage.org/webt/as/ez/_h/asez_hivnpftponwarhsbp9dr5g.png)
. . , Top, . : , ..
![](https://habrastorage.org/webt/lz/ic/el/lzicel6s5y1g6kwfam-lc9zkbig.png)
, : , , .
![](https://habrastorage.org/webt/np/4l/vj/np4lvjczw7fxixq-2p1sdjjuuek.png)
, , swap. swap, , swap. – .
![](https://habrastorage.org/webt/6m/qd/g9/6mqdg9yw1ns3ap8_zzg97unyik4.png)
- : « - ?». . , .
![](https://habrastorage.org/webt/2n/1u/uk/2n1uukefmeisgx0ixat60is_hmc.png)
, – - Postgres. uptime. , uptime Postgres – , , . , Postgres .
![](https://habrastorage.org/webt/yg/ie/60/ygie60a26gqjyhbolxqbl-1eip0.png)
. , Postgres, . , , . . . .
![](https://habrastorage.org/webt/vb/7s/7y/vb7s7yoxlu5dbg4e3lizbxjc6qm.png)
, , . , , . , . , . - .
![](https://habrastorage.org/webt/-l/7c/kb/-l7ckbjhj4dsylg-a7x2qcabtok.png)
, Postgres MVCC . MVCC . , . .
![](https://habrastorage.org/webt/gh/j7/le/ghj7le7a-7l1u3ysgpq5wryj9lc.png)
'd'.
, pg_stat_database , «rollbacks». «ROLLBACK», /. (constraints), . . , .
pg_stat_database (conflicts) (deadlocks). , , , - .
![](https://habrastorage.org/webt/6n/wk/h2/6nwkh22oadmefjnbvfwleno31bo.png)
, pgCenter. , . -, :
top
vmstat
iostat
nicstat
pg_stat_activity
pg_stat_statements
, .
![](https://habrastorage.org/webt/wa/m4/ho/wam4hohz7mx6rv62czpzxzmymzm.png)
, , - .
![](https://habrastorage.org/webt/i7/cs/bj/i7csbjggspmjmj6k7igcgk-g5n4.png)
. , , . . . CPU usage – 85 %. , - . , . , Postgres. Postgres , .
![](https://habrastorage.org/webt/4i/q9/si/4iq9si3nflmq2gjob7ux81ns_bi.png)
, , 38 , - . state: waiting idle_xact. Waiting 0, . . . , 20 idle . , (xact_age) – . , . – 15 . , .
![](https://habrastorage.org/webt/bs/jm/zm/bsjmzmekxk9m89iyi-incu4pkli.png)
(: pg_stat_statements. pg_stat_statements "x", . "shift + x" pg_stat_statements_timings. "pg_stat_statements not available on this database", pg_stat_statements postgres postgres: create extension pg_stat_statements;
)
, () . , . pg_stat_statements. contrib. : , . contrib , . , -. Postgres – pg_stat_statements.
, . , . . , CPU pg_stat_statements. – 2 . SELECT COUNT (*) FROM "game_competition_events"
. . . , , , , . , - , , -. , .
. total_time. total_time , , /: . , «t_cpu_t». . .
![](https://habrastorage.org/webt/rb/tx/tb/rbtxtb-h59duuj5rnzav8t_kueg.png)
, . , , «cpu_t», , , . snapshot , , . . SELECT "courses_logs".* FROM course_logs
. , 5 . , , , , .
«calls», , . . . . .
![](https://habrastorage.org/webt/be/vf/8_/bevf8_xi1tr4u8gthw1femyeqts.png)
, . Top pg_stat_activity pg_stat_statements. pgCenter .
![](https://habrastorage.org/webt/lu/8u/wm/lu8uwmka4hdvnqe2ky2a5m46ave.png)
– -. , , , -.
![](https://habrastorage.org/webt/5r/w4/86/5rw486zd8afdszdzbkvmjuvbwt8.png)
. , - – 27 %. , -.
![](https://habrastorage.org/webt/gp/lb/2v/gplb2vl2exzmefukpqvmqgpr0uc.png)
, «background worker». , .
![](https://habrastorage.org/webt/vo/jl/cf/vojlcftweu-mwgx0gyzfvgsrz_w.png)
«wait_event». , -. . . .
![](https://habrastorage.org/webt/yp/sq/qo/ypsqqopecjuawv5sybz6ueti4iq.png)
-. 'B' iostat. . , 99 %. – , NVME. , latency.
![](https://habrastorage.org/webt/f0/ty/vu/f0tyvuxnxpzfx0yjkujqtplvafu.png)
latency, latency 1 . .
, . , SSD NVME- - , , latency. latency, , - .
![](https://habrastorage.org/webt/e1/xe/ka/e1xekaqycwcpc248k_ak-xzcitc.png)
, -. pg_stat_statements , -. «t_read_t», . . , .
. «read_t». , -, .
/ track_io_timing.
, , . pgCenter queryid. . , pg_stat_statements. . . . . pgCenter . queryid. pgCenter .
![](https://habrastorage.org/webt/fp/3x/jj/fp3xjj2ninlijbpv5ftokqbud5s.png)
:
– summary, , pg_stat_statements. , , -.
, , summary. .
, , .
, , .
![](https://habrastorage.org/webt/ix/7o/56/ix7o56r1vbmc7b_ohgunxzowrxs.png)
, , , top, iostat pg_stat_activity, pg_stat_statements. , .
![](https://habrastorage.org/webt/cq/lu/8k/cqlu8k4bvwzoi6-evsgvw1lu-he.png)
– , -. Postgres , .
:
Checkpointer pocess.
WAL writer process.
Autovacuum workers.
Background workers.
pgCenter , , .
![](https://habrastorage.org/webt/jj/x7/ut/jjx7utmlxkdaeb7uh8vtyr4vnm4.png)
, : - , . , , .
![](https://habrastorage.org/webt/bf/dt/ma/bfdtmaslqkiiiilzlluqvg2ocfu.png)
, , . - .
![](https://habrastorage.org/webt/hh/uy/mn/hhuymnjtf6zjdpubpertpzphy5e.png)
.
![](https://habrastorage.org/webt/l4/a4/vv/l4a4vvjtnowhf8fl_w2vhynmoie.png)
. , , 22 21 . , - .
![](https://habrastorage.org/webt/i9/fs/a5/i9fsa52ag9kwg_5clfbyrswrsi8.png)
wait_event , , . . . - - , , .
![](https://habrastorage.org/webt/ae/l3/ye/ael3ye_vydpudqcrho-xmqljguu.png)
, (idle in transaction). , 6 . .
![](https://habrastorage.org/webt/hh/pa/jy/hhpajyn-3_7ld00momu8b7k_gk0.png)
, , 10- , . , , 7 . 10- .
![](https://habrastorage.org/webt/ag/zy/rt/agzyrtdg9-nrmhktrg3ub_fx5eu.png)
wait_etype, wait_event , , , (Client:Client Read). , - , - . , , - , , . , , .
– . : pg_cancel_backend pg_terminate_backend. , backend. pgCenter . backend pid, .
![](https://habrastorage.org/webt/py/ck/gj/pyckgjbcaf1rc5gtq1vjkxbjaiw.png)
:
Pg_stat_activity.
Pg_stat_statements.
Pg_cancel_backend ().
Pg_terminate_backend ().
![](https://habrastorage.org/webt/rt/ij/jm/rtijjm-xng842mjtnyemrf_o-dw.png)
, . , , .
. , . - . , ( , , ). - , , idle transaction . — .
![](https://habrastorage.org/webt/sh/qw/rh/shqwrhk9o1v9zxcfi-vgobnb-fu.png)
– . , (deadlocks) .
![](https://habrastorage.org/webt/ff/tq/f6/fftqf6fvkjgpkhceg33r8p-ti9c.png)
. ALTER TABLE, , , . . , , 11- . Postgres, . ALTER .
![](https://habrastorage.org/webt/vq/lt/xs/vqltxssnw69vhtlzaieaygbd0hy.png)
– CREATE INDEX CONCURRENTLY, - , , . .
![](https://habrastorage.org/webt/-r/uz/hf/-ruzhfbfuydomh9gk_uiqq2rx24.png)
, .. , production Postgres , .
![](https://habrastorage.org/webt/dd/yh/we/ddyhwentwfs65a09cmc195zpuoa.png)
pg_stat_replication. , Postgres, .
pgCenter pg_stat_replication. , , .
5 . .
![](https://habrastorage.org/webt/5h/dh/an/5hdhaneor7w8-wrzj7xs0_sbqgc.png)
, , . 2 walreceiver, . . 2 .
![](https://habrastorage.org/webt/0z/kt/jp/0zktjpvqmouvpu3tivmsgdas6eu.png)
, , , . , , - . , , – - .
, pg_stat_replication , . 1,5 GB. replay_lag – 2 . . . 2- . 2 , . . .
![](https://habrastorage.org/webt/bf/cp/qx/bfcpqxfzhmcka2_przsngz6jhs0.png)
, , 2 pg_basebackup 1 pg_receivewal. Pg_basebackup – . pg_stat_replication. pg_receivewal – , . . . , , . - , .
![](https://habrastorage.org/webt/29/q5/z0/29q5z0bsl59k_q3m7prh_a5m9pi.png)
pg_stat_replication . . , 5 . : pending, write, flush, replay, total_lag. . . .
Pending – , . .
Write – , , . . .
Flush – , .
Replay – . .
Total_lag – .
, , , - , . , ; , ; , , .
![](https://habrastorage.org/webt/gf/8i/ij/gf8iijwr61pkhdylduyhqavz0ws.png)
, . . , , .
![](https://habrastorage.org/webt/qu/dy/ag/qudyageigyjrprl7ob74vczyrio.png)
– , . . – , . Postgres, . , - .
![](https://habrastorage.org/webt/2u/4d/x0/2u4dx0bujjdlddgtnm1e6rvjnyc.png)
:
pg_stat_replication.
pg_wal_lsn_diff().
pg_current_wal_lsn().
pg_last_commited_xact().
![](https://habrastorage.org/webt/lj/l-/lx/ljl-lx1ukvsvfnthbpzh5uyzb_k.png)
, .
![](https://habrastorage.org/webt/dz/uk/4i/dzuk4i7gn_b0evxafqlgowz-q0m.png)
, top . – Seq Scan, update, delete, insert, .
![](https://habrastorage.org/webt/nl/e7/ss/nle7ssgxr15rgjddnfjv0aiscdi.png)
. . .
![](https://habrastorage.org/webt/ac/4b/zu/ac4bzu9golpff9rger53zojeyse.png)
. , , . , .
![](https://habrastorage.org/webt/rq/j-/bu/rqj-buxh0ebqgbwgdchhnny8xly.png)
, , pg_stat_progress_vacuum 9.6. , , , , , . pg_stat_progress_vacuum – . , . , , , . , .
![](https://habrastorage.org/webt/l4/ze/ro/l4zeroomn-ai2mwdkzh-wzgpna4.png)
, . , , . . postgresql.conf, - reload. , , .
. , , . . , .
psql, . . psql , pgCenter. - , pgCenter, psql .
![](https://habrastorage.org/webt/pz/n8/do/pzn8doxswlxet4kbntn3dgwmrau.png)
top- – , pgCenter. top , pgCenter. record report.
, . . report , , Top. — .
![](https://habrastorage.org/webt/-n/en/ms/-nenmsxqwjmvaizdhqqvdpqj6nq.png)
-. - , record. . .
![](https://habrastorage.org/webt/lu/e0/wb/lue0wborpecwc8rtmx_8zjftttm.png)
wait_event’, , .
![](https://habrastorage.org/webt/fd/bk/mj/fdbkmj5xbm8irymj4ccrbi-dohq.png)
: SELECT . , , , 44 % , - , – - , .
![](https://habrastorage.org/webt/nj/fd/iz/njfdizke09pnj36updzdsxlpw6g.png)
: VACUUM FULL. , VACUUM FULL IO , 12 %. , , .
! . . . , , pg_stat_statements, query . - - ?
, . , , , , - , . , , - . . - . . . , , -. , , . , , .
. , rollbacks. rollbacks, rollbacks, .
, , , pg_stat_database . rollbacks .
pg_stat_statements rollbacks, .
, . . `SELECT FROM pg_stat_database JNOIN pg_stat_statements` pg_stat_statements, rollbacks , . . , 10-20 .
, ! Postgres ?
9.0-9.1, C . - , , , , . Go , 9.4. 9.4 , SELECT… where filter. . (9.3) . . , , . , , , , .
, ! , TOP. .
, , . , – . less ( ), – , .
. TOP ?
. , , , . , . , . , , .
! . , . , 85% CPU usage, , . pg_stat_statements. . , .
. CPU . – t_all_t. pg_stat_statements. , . , . t . . . «t». . . . , .
. , pg_stat_statements, ?
pg_stat_statements real time.
, pg_stat_statements , 85 CPU usage – .
, . , pg_stat_statements . , , , 10 , . 10 – , , , atop. atop ?
, . pg_stat_statements, CPU, , , pg_stat_statements.
. , Grafana, . . . pgCenter – , , , , .
. pgCenter atop , Grafana?
pgCenter report pgCenter record, . . . , , . . ., , pgCenter report , , pg_stat_database sar . . atop, .
, ! , Postgres, , , . , . ? ?
10 . «-f», . , , , 10 . , pg_stat_activity , . . , . , , 50 . , , 1-2 %. . . , , - 0,5-2 % .
. , - .
, . , , 0,04 % . , , . - .
.
, .
, ! . wait_event Running – ?
.
CPU.
, . . . , wait_events PID , , backend - , , - . Running, , . . .
CPU?
, CPU, . . - . .
! ! - , , Ubuntu?
C, . , , . PDGD Ubuntu. Launchpad , - . . , . Go -, dev-. . , travis-ci build, build . . . Realeses, . wget, , tar’ , .
Goreleaser, . .
, GO . , . , SOLID. , , Goreleaser , , , . C’ , . , Realeses. !
Updated. Goreleaser , !
, queryid. queryid. , . ?
, . , - . , . - . . . , . . . . , , .
, , queryid – .
Sim, inicialmente a largura da coluna aumentou e foi irritante. Corrigi-o no ramo dev, mas isso ainda não está no ramo mestre. Em meados de fevereiro, desejo lançar o Event Profiler. E apenas uma largura fixa da coluna será.
Ă“timo.
Sim, você pode ajustar a largura através das setas.
Obrigado Alexey!
Muito obrigado!
VĂdeo: