我建议您熟悉安德烈·萨尔尼科夫(Andrey Salnikov)对2016年初报告的解读,“应用程序中的典型错误导致postgresql膨胀”
在此报告中,我将分析在设计和编写应用程序代码阶段出现的应用程序中的主要错误。而且我将只考虑那些导致Postgresql膨胀的错误。通常,这是整个系统性能结束的开始,尽管最初并没有可见的先决条件。
![](https://habrastorage.org/webt/j4/gz/vk/j4gzvk96v4s9_slh-p4gnciohqw.png)
很高兴欢迎大家!这份报告的技术性不如我同事的上一份。该报告主要针对后端系统的开发人员,因为我们有大量的客户。他们都犯了同样的错误。我会告诉你有关它们的信息。我将解释这些错误导致的致命和不良后果。
![](https://habrastorage.org/webt/9o/25/7s/9o257sxpafvagscbtymhpyqqakg.png)
为什么会犯错误?执行它们的原因有两个:偶然,也许是由于对基础和应用程序之间以及基础本身中发生的某种机制的无知。
, . , . , , . .
![](https://habrastorage.org/webt/ch/r5/vr/chr5vre616zbkrcrk_fcbaz60ak.png)
, . , . - .
![](https://habrastorage.org/webt/jx/m_/ng/jxm_nggqmszbi0aa-x0sl8lan-q.png)
: , 2 MB. . – 2 000 .
![](https://habrastorage.org/webt/fx/hv/ed/fxhvedvfa8g_cbgyxmfeadzgiyq.png)
, , . 2 . – , .
, . 2 MB. .
, . .
– . , . , – -. .
![](https://habrastorage.org/webt/7k/kd/_3/7kkd_32jzk8cmll4xgh4hgsgg78.png)
. . , , . , ( ) .
, , . – 2 000 , .
![](https://habrastorage.org/webt/ln/oi/kk/lnoikk3gactr_rj8v3f0af_suro.png)
. - . :
- – , . . . . , , - . – , .
- , - exception. exception . .
- – . . . , , .
?
, . bloat. , , . . 10 , 10 , 20 . .
, . , . , , 300 . , . . .
![](https://habrastorage.org/webt/72/q9/ca/72q9caetfeh_s85jaz2ekfjhsvw.png)
. . . . Postgres , - .
![](https://habrastorage.org/webt/dx/21/3d/dx213dhxb1rxroqoht-fjkl-flq.png)
? . . , , . . , . . – , .
![](https://habrastorage.org/webt/7k/lc/rq/7klcrqmf767vibtfeyvfcnytqoi.png)
. , . . . .
, , , . , . - . , .
![](https://habrastorage.org/webt/_j/he/_i/_jhe_ix0hqxffvpmj0_j_dfdugc.png)
: « ?». . , . . . . . - , .
![](https://habrastorage.org/webt/6u/zb/uu/6uzbuuhl9l1dzipogae1xmq087u.png)
, : . .
, . . , - . . . . .
, , . , .
![](https://habrastorage.org/webt/xa/vx/5u/xavx5up_mbqc52btb-_7nwssgaa.png)
, , , . . ?
. - . . , , . . , , , . , . - Postgres.
? - , : « , , id , ». id. . , - , , , . .
, - . , , . , . . - , , . PostgreSQL.
![](https://habrastorage.org/webt/ff/5v/ir/ff5virwfhf3vlipk3m-d_paqfvg.png)
? ?
- , - , - . . , , id. id, , . , . , . .
. - , , . ? , . .
. , .
, : , , . «bloat», . , 2 MB, 300 MB? .
![](https://habrastorage.org/webt/y5/sj/mu/y5sjmulskvpso8avoizedjlmspg.png)
?
- 150 . , .
- . , . , , - . , , .
- . , .
- , 10 , 10 , 10 , . . . 20 , 10 . , . - , , , , .
- : « ?», , .
![](https://habrastorage.org/webt/mu/8n/es/mu8ness1qpe1lcxbssbsvzahea4.png)
, .
, . , - , - . pgstattuple. , , , .
, , . . . – VACUUM FULL. , , . Pg_repack pgcompacttable – . .
, . . , . .
, , , , , :
- . -. idle in transaction. , , - , .
- , , . . . «» , .
![](https://habrastorage.org/webt/c5/ml/bb/c5mlbbr-awkevvdayxmrv_mo-o8.png)
, , VACUUM FULL’ . production.
. .
![](https://habrastorage.org/webt/mf/v7/lp/mfv7lpm5hb875bsiz9d3bhbfltw.png)
, , , . , , . , , , , . . , , .
![](https://habrastorage.org/webt/x-/-v/zt/x--vztacibsriajurryybhx7x90.png)
. . , , . .
,
![](https://habrastorage.org/webt/er/je/qy/erjeqyfmzmqt6mamwovpkdce-_i.png)
- . , : , . , - ETL. . .
- , . , , . , , .
- .
- . .
![](https://habrastorage.org/webt/dt/20/wf/dt20wfy6x4wrt9r3pp8wiufxcvi.png)
? . -.
. . , . , , 2 . , . .
![](https://habrastorage.org/webt/jm/kx/bh/jmkxbhmxuqvkqdb6klcwnkbhkgq.png)
. , . .
![](https://habrastorage.org/webt/sp/qf/5i/spqf5iac8b7dka6dbsdgltikv40.png)
, . .
, . .
– . , 3 . – 3 . , , .
, . . – hot_standby_feedback. . Hot_standby_feedback . . .
![](https://habrastorage.org/webt/8b/mb/dj/8bmbdjqpu-xvnqvvi-oo29dgttk.png)
-? - . , . , - -. , , . . . - .
![](https://habrastorage.org/webt/4e/ib/ne/4eibnen11hx3m6prbe55bwsua9c.png)
, . . . , .
![](https://habrastorage.org/webt/ob/hd/mz/obhdmztz6o_ks2_s5v47m3om9ki.png)
, , ?
- . , , . . . , Load Average .
- , . , . , .
- . raid. . . , , .
- : , . .
- - .
![](https://habrastorage.org/webt/1i/jz/8b/1ijz8bgp8qwrihslh52nmopyflk.png)
. . . , . , , , .
. - - . - . , -, , . . , .
![](https://habrastorage.org/webt/eo/bh/bg/eobhbgp0qi84jmah2rgt4qi4k_y.png)
, , . . , , . . , .
![](https://habrastorage.org/webt/vl/bl/97/vlbl97m63q5xbodozflngxns2va.png)
- , .
. . . , .
- hot_standby_feedback? , . - . - , .
- max_standby_streaming_delay? , – . , - , . , . , , - . , , – , .
- , , , hot_standby_feedback . . , . . , . . . , .
- , . streaming_delay. . , 6 , . .
:
. .
![](https://habrastorage.org/webt/pp/rt/v7/pprtv72jjqpv1h92ytkly6l2q8o.png)
, .
![](https://habrastorage.org/webt/50/ac/ws/50acwsegb4pnh0mnqhrhnkxpmfe.png)
- . . . , , , .
- . , , . , , , . : .
- . , Liquibase. . . . . , . . , . .
- , .
![](https://habrastorage.org/webt/3i/0p/zd/3i0pzdxv5jsip1tylx0ya4j3efq.png)
. , 15 GB. , , .
![](https://habrastorage.org/webt/af/8h/55/af8h55v9-pmhl4cxxeal6knig3m.png)
, , . , . . . 5 , , 7,5.
![](https://habrastorage.org/webt/eg/vq/wp/egvqwpk4ywpu3p7vvavc9cf8j3i.png)
.
, :
bloat, .
![](https://habrastorage.org/webt/yc/5g/0y/yc5g0y3mlnw53wtdmy4hcokdyfu.png)
, , , . .
![](https://habrastorage.org/webt/zx/uq/pd/zxuqpdxaazk54i9bbjo2gyxavq4.png)
, , . 7,5, . 2 , 1,5 , . . . – . .
![](https://habrastorage.org/webt/ry/6a/6g/ry6a6g7_shhfpn9hrukkqgu1wza.png)
, . . .
- . .
- . DBA , DBA. . , , , .
- , , , , . . , :
- , .
- . ? -, . , - -.
- , , , .
- , ( ) , . – .
- , , . - , .
- .
bloat .
.
![](https://habrastorage.org/webt/g4/3-/be/g43-beor7ucrudazmduy_nhiaig.png)
https://github.com/dataegret/pg-utils/blob/master/sql/table_bloat.sql
https://github.com/dataegret/pg-utils/blob/master/sql/table_bloat_approx.sql
, .
, bloat, pgstattuple.
, . . .
- , bloat .
- , – bloat bloat . , bloat Postgres . MVCC.
- 20 % bloat – . . . .
, , , , .
, bloat:
- , . . VACUUM FULL. , . VACUUM FULL? . . , . . , : , , . VACUUM FULL , .
- pg_repack. VACUUM FULL, . , , , . VACUUM FULL. , , . , -.
- – pgcompacttable. , . pgcompacttable , . , , , . , . . . .
.
![](https://habrastorage.org/webt/nf/-z/pi/nf-zpinx8zbhv1j-jh-59ve35pi.png)
bloat , :
, , . . !
! , . ? . . , , - . - joins. - , , - . . . , . ? , ? ?
– , DBA.
.
PostgreSQL , pg_stat_activity, . , .
5 ?
cron . , . . . , . , . .
, ?
. . .
! pg_repack . , …
.
… . ?
, , . . pg_repack , . , - . .
. . - ?
, .
, VACUUM FULL?
VACUUM FULL, , . , . pg_repack . , , .
! . , . . . – . - ?
. Postgres . . , . id , , . , . - . , . .
. . . , . . - , .
, . Postgres . . , , tos-. : , json. . bloat, . . . .
! statement timeout?
. . . . , , . . . . cron, . , . , 10 . . pg_stat_activity.
! . , . - exception, rollback . . . , . , PostgreSQL , ?
, , , ORM, . . auto commit on, , .
. . ?
. . auto commit on. . , - . «start transaction» «end transaction», .
! ! , , - . - , ?
- .
, DBA , . .
, - , .
?
reserved space, . . , , . , . – , . - , .
?
. , , , . , , . .
! . -, , , , . , . ?
.
?
. , pg_rapack, pgcompacttable. , . VACUUM FULL , , . . .
. , . , – , – .
? , . . , ? - . , , , , . , , , , . PostgreSQL , . , , .
安德烈,有一个问题。您在演示过程中显示的这些精美图形是工作的结果,是某种实用程序的结果吗?是什么建立了图表?
这是Okometer服务。
这是商业产品吗?
是。这是一种商业产品。