我建议熟悉Andrey Salnikov对2019年初报告的解码,“当一台服务器已经不够时,管理PostgreSQL上的负载”
要点:
1)PostgreSQL标准负载平衡实践。首先,我们讨论数据库负载高的原因。下一步是考虑那些负载平衡方法。
2)将讨论有关如何在PostgreSQL中组织复制,同步和异步副本之间的区别以及如何正确配置副本的问题。
![](https://habrastorage.org/webt/vy/7v/gk/vy7vgkxphftzmdi4tsvtuxzdwrm.png)
![](https://habrastorage.org/webt/34/cy/s9/34cys9vfr-k70f_s3n5uayiv5yg.png)
, . – Data Egret. . . HeadHunter, Lamoda. DBA PostgreSQL. DBA – . . , .
, - , .
Postgres open source’ community, . , Postgres.
, RDBMS . – enterprise: Oracle MSSQL, open source: MySQL Posgres, .
- . . . – Postgres .
– .
, - . , , , . . . Postgres, , , . , , .
![](https://habrastorage.org/webt/cc/po/md/ccpomdtvx7l1nmt0qeulyxbsuue.png)
. ? , . , -, .
![](https://habrastorage.org/webt/rm/uh/6s/rmuh6s-kc2ejk1ay1uplobgs-fk.png)
, .
![](https://habrastorage.org/webt/f5/uq/jy/f5uqjyjsnkdfxzyuwnr9qn6jvi0.png)
, , . . , , , , , , .
. , ? , raid 1 raid 0. . -. , , . , . , .
![](https://habrastorage.org/webt/wg/if/xu/wgifxu16lwnnmgir-lybswio2ag.png)
, , – 20 000-30 000. 40 000, , - . .
, . 50 000 . .
![](https://habrastorage.org/webt/eu/ik/cc/euikccla9vsax4yvvru28skaey4.png)
, , - - . . – , . . , . , . . . , , - , , , . .
![](https://habrastorage.org/webt/6m/p4/nw/6mp4nwfdikdo6_rwqimxkgwkwqi.png)
. . , , . . , . .
, . – «exclusive», «share».
20 000 ( ), , - .
: HH Lamoda. , ? 10-20-50 , .
. , .
![](https://habrastorage.org/webt/vq/mu/vj/vqmuvjdtlmjzrmqtmbx2rdhogo4.png)
, , . , , . - . , , , , , , . .
, , Postgres , . . Postgres Posix, , , . – . , , : «, » sleep. , . , . , .
![](https://habrastorage.org/webt/mh/6_/rn/mh6_rn09u98aujcgwr14ihkqq5q.png)
. .
![](https://habrastorage.org/webt/gy/km/5n/gykm5nsop8tkc-6odj43ffibnd4.png)
timestamps.
, 30 . . . . RDBMS , . , - . , . , . .
![](https://habrastorage.org/webt/rr/ke/u-/rrkeu-kvdfhy1crr9ihenj4fruw.png)
-. , . .
, – idle-. Idle- , - pool connection. , , . , , , , , , , . overhead, , -, .
– . – , .
– , . - , : , . .
– - , . , , , .
? . .
, . ? -, . -, - Postgres ( MVCC), . update/delete, , , , .
idle in transaction , , Postgres . , . . , . , . , . - ( ), 10 , 300 , 400 . . Postgres, .
– waiting. , - . , , . , , .
, . . : - , . , Ruby, Python. , . , , - , . idle in transaction.
instances , . . - . . . , .
![](https://habrastorage.org/webt/lk/ww/wg/lkwwwgzx6mdk0yzmhyyn8n63kiq.png)
-. , pool connection . pools, . Hibernate pools. , pool. , pool .
, . , , idle-. . . , . , , , . , . , . . .
, , .
![](https://habrastorage.org/webt/xx/jd/kx/xxjdkx2jp-z3f4skrdv1a04xoii.png)
, , , . , .
![](https://habrastorage.org/webt/iw/jr/op/iwjrop7pew4tbjl_vajquavr2tm.png)
.
, . . , , – . , - .
, , , . . , .
, 2,5 . 2 – transaction log. . , . , . . . 1,5 . : « . ». 0,5 . 2,5 0,5 . , .
. , . , , . .
. ORM-. . , , , . .
, , 2 , , 490 , . 490 , , . - . .
, , . , , , , , .
. , , , . . , - . , , , - , .
, , . , , . , . . , , . . , , – 3-4 , .
. . , .
? , . , , - . , : , , . , , « , ». , , , . , , , .
. Json, , . . . - Json . . , .
. , , , , . . . . , , , . , Json, . Json, . , .
![](https://habrastorage.org/webt/rx/fq/an/rxfqaneiyipzobi6g4atdwncuik.png)
. , join. . , , , , , .
Java , hibernate . Hibernate, , . . , 2 , . , . 2 – , .
, , Python, 490 , . . 5 . . . , . , - , , .
2 . , , . .
, , , . . , , , , . . , , . . . LEFT JOIN, DISTINCT , , - .
GROUP BY – DISTINCT. . . , . .
– COUNT, MAX, MIN , . . , , . , , . , . . . - . . , MIN, MAX . . .
, . «WHERE id IN (SELECT id FROM)», . «NOT EXISTS». id, , .
, . SELECT ids. id , – .
NOT EXISTS , . , : «, id, ». WHERE, . , WHERE , , , .
– . . , - , , . cron- ( ) , , , . , .
. , -, , . - . , , . PIDs . , , .
, HH , cron …, . . cron . , , – .
![](https://habrastorage.org/webt/mu/b3/cz/mub3czf7ns67jcqyaytzecwany8.png)
. . , : Kafka, RabbitMQ, ZeroMQ, .
, . . Skype SkyTools PGQ. . . . . 20 000-30 000 .
– . , . , , .
. . DBA, , Postgres. .
. , , idles. , .
idle-. . . , 10 , 15, 15 , . . idle 15 . , , .
pgbouncer . . , .
PgBouncer transaction-, . . : start transaction commit rollback. , … – . – . , , , .
Pgpool-II, , .
PgBouncer , . . Odyssey. . , . . . . -, , , - Odyssey Pgbouncer. PgBouncer – .
. , COUNT 200 , 200 . MIN , .
200 , 100 . . .
– , . . . , . , , , . , .
, . ? , 100 , 2 200 . , . , 90 % 10 % . 200 , .
. . Oracle, partition. «» . - – .
. .
![](https://habrastorage.org/webt/gr/el/hw/grelhwc_t8madpm_5ndatmknohy.png)
?
![](https://habrastorage.org/webt/ql/gc/k5/qlgck5fyv4d8lzktqsbhd5_xmvc.png)
. , , .
. , : , , , . , . , , . , , . , , . , .
. , , , , .
– . , , , : HDD SSD. NVMe . – , . , NVMe, .
![](https://habrastorage.org/webt/8x/jm/zm/8xjmzms2ii2duunfi3gg_02e4s0.png)
? WHERE , , , .
, - . . .
![](https://habrastorage.org/webt/ja/zb/fa/jazbfalflti4_0ddrfgujhopoum.png)
– . – , . – , , . . – drop table, .
. - , , . - . , – Coca-Cola, Pepsi, Nike, Adidas . . , . . . .
, , , . . . , . . . . , . , , .
![](https://habrastorage.org/webt/ta/u0/az/tau0azsogwuj8bu8b0ksvoxugno.png)
, , , 4 , 2 , 2 , , : « ?».
, - . , . , RDBMS .
![](https://habrastorage.org/webt/ww/19/1l/ww191lk7ygiyr6cqv8pq0zrt1my.png)
. , , , .
: .
– , . INSERT. INSERT INSERT’ . DELETE DELETE SQL . .
. INSERT . , . . . . , .
, .
9.4 . . 9.6 . 10-11 . , , , , .
Postgres . , – , . .
Postgres, , , , . – . INSERTS DELETES.
, . Slony, Londiste Burcado.
Burcado – . – Slony. Londiste – , . , .
, , SQL? . , , . , - . , .
, Postgres , . .
? .
– -, , -. -, . , -. - .
. , -. Postgres , Postgres , , , , , , .
. . .
, , , , , , .
. , . , , 10-20 .
. , , .
? -, . , -, 20 , , , , . - . . , . -.
. . , Postgres, . .
. delayed . , . , 8 , 8 , . , 6 , . . . , . . . , 200 – .
. . . . , , - , , . . . – . , . . , , .
![](https://habrastorage.org/webt/km/pc/lk/kmpclki5wedkfrszxi3dnr5ntay.png)
. ?
wal_keep_segments. , . - , , , wal- – 16 . . . 1 000 , , 1,5 . , .
, …, , -, , , . , «0» . , .
Max_standby_streaming_delay. . ? , . , - . , , . , , , .
, , , , . , Postgres , .
Synchronous_standby_names. - . . . . . . . . . .
Hot_standby_feedback. , , . , , , . .
, - : « , -. , , ». .
. . Hot_standby_feedback , -, . , . .
Recovery_min_apply_delay. CI/CD , , - , . 6 . 6 , . 8 .
, . , .
![](https://habrastorage.org/webt/fn/dr/1l/fndr1llehqthygjt5uqwykh8x70.png)
.
![](https://habrastorage.org/webt/ej/tq/m1/ejtqm1budhykipev2bjuv_iu_to.png)
Postgres , . .
, full story , -, - . -. .
? , , . , COUNT, MAX - , , .
![](https://habrastorage.org/webt/n0/uq/wp/n0uqwpt9y4_y9kvbwskylqivq0y.png)
. 20 , . . . , , - . Join, .
![](https://habrastorage.org/webt/vh/8d/ti/vh8dtijwx5g9qo2wwuahgybs-pe.png)
- , KPI -. . , . max_standby_streaming_delay. , 4 , .
, 2 , . . . OLAP-, , -, , . , OLAP-. .
, , HeadHunter , . - . . , , . .
RDBMS , , , RDBMS, . , ClickHouse, .
![](https://habrastorage.org/webt/ub/y0/np/uby0npfyqjxw-n7yxipktns5jcq.png)
. , latency. , , , , - . , . , . . . , . , , , .
, - , . - . , . .
, , , , . . . .
HeadHunter上的“上瘾阶段”方案看起来像这样。在那里,它们有11台用于级联服务的服务器。而且有效。他们拥有如此疯狂的巨石,可以像时钟一样毫无问题地工作。部分原因在于其支持团队的服务水平取决于停机时间。他们允许停机时间。以及他们从这段允许的时间中节省了多少,所以他们有丰厚的奖金。他们正在努力。他们有停机时间。
我有关于这个问题的一切。它比较全景,但我认为它将很有用。
视频: