Gestión de carga PostgreSQL, cuando un servidor no es suficiente. Andrey Salnikov

Propongo familiarizarme con la decodificación del informe de principios de 2019 de Andrey Salnikov, "Administrar la carga en PostgreSQL, cuando un servidor ya no es suficiente"


Puntos clave:
1) Prácticas de equilibrio de carga estándar PostgreSQL. Primero, discutimos las razones de la alta carga en la base de datos. El siguiente paso es considerar esos métodos de equilibrio de carga.
2) Se discutirán preguntas sobre cómo se organiza la replicación en PostgreSQL, cuáles son las diferencias entre réplicas síncronas y asíncronas, y cómo configurar las réplicas correctamente.




, . – Data Egret. . . HeadHunter, Lamoda. DBA PostgreSQL. DBA – . . , .


, - , .


Postgres open source’ community, . , Postgres.


, RDBMS . – enterprise: Oracle MSSQL, open source: MySQL Posgres, .


- . . . – Postgres .


– .


, - . , , , . . . Postgres, , , . , , .



. ? , . , -, .



, .



, , . . , , , , , , .


. , ? , raid 1 raid 0. . -. , , . , . , .



, , – 20 000-30 000. 40 000, , - . .


, . 50 000 . .



, , - - . . – , . . , . , . . . , , - , , , . .



. . , , . . , . .


, . – «exclusive», «share».


20 000 ( ), , - .


: HH Lamoda. , ? 10-20-50 , .


. , .



, , . , , . - . , , , , , , . .


, , Postgres , . . Postgres Posix, , , . – . , , : «, » sleep. , . , . , .



. .



timestamps.


, 30 . . . . RDBMS , . , - . , . , . .



-. , . .


, – idle-. Idle- , - pool connection. , , . , , , , , , , . overhead, , -, .


– . – , .


– , . - , : , . .


– - , . , , , .


? . .


, . ? -, . -, - Postgres ( MVCC), . update/delete, , , , .


idle in transaction , , Postgres . , . . , . , . , . - ( ), 10 , 300 , 400 . . Postgres, .


– waiting. , - . , , . , , .


, . . : - , . , Ruby, Python. , . , , - , . idle in transaction.


instances , . . - . . . , .



-. , pool connection . pools, . Hibernate pools. , pool. , pool .


, . , , idle-. . . , . , , , . , . , . . .


, , .



, , , . , .



.


, . . , , – . , - .


, , , . . , .


, 2,5 . 2 – transaction log. . , . , . . . 1,5 . : « . ». 0,5 . 2,5 0,5 . , .


. , . , , . .


. ORM-. . , , , . .


, , 2 , , 490 , . 490 , , . - . .


, , . , , , , , .


. , , , . . , - . , , , - , .


, , . , , . , . . , , . . , , – 3-4 , .


. . , .


? , . , , - . , : , , . , , « , ». , , , . , , , .


. Json, , . . . - Json . . , .


. , , , , . . . . , , , . , Json, . Json, . , .



. , 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 . , , – .



. . , : 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. «» . - – .


. .



?



. , , .


. , : , , , . , . , , . , , . , , . , .


. , , , , .


– . , , , : HDD SSD. NVMe . – , . , NVMe, .



? WHERE , , , .


, - . . .



– . – , . – , , . . – drop table, .


. - , , . - . , – Coca-Cola, Pepsi, Nike, Adidas . . , . . . .


, , , . . . , . . . . , . , , .



, , , 4 , 2 , 2 , , : « ?».


, - . , . , RDBMS .



. , , , .


: .


– , . 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 – .


. . . . , , - , , . . . – . , . . , , .



. ?


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 .


, . , .



.



Postgres , . .


, full story , -, - . -. .


? , , . , COUNT, MAX - , , .



. 20 , . . . , , - . Join, .



- , KPI -. . , . max_standby_streaming_delay. , 4 , .


, 2 , . . . OLAP-, , -, , . , OLAP-. .


, , HeadHunter , . - . . , , . .


RDBMS , , , RDBMS, . , ClickHouse, .



. , latency. , , , , - . , . , . . . , . , , , .


, - , . - . , . .


, , , , . . . .


El esquema de "Última etapa de adicción" en HeadHunter se parece a esto. Allí tienen 11 servidores en cascada para el servicio principal. Y funciona. Tienen un monolito tan loco que funciona sin problemas como un reloj. En parte debido al hecho de que su equipo de soporte tiene una prima que depende de cómo fue el tiempo de inactividad. Tienen tiempo de inactividad permitido. Y cuánto ahorraron de este tiempo permitido, por lo que tienen una buena bonificación. Y lo están intentando. Tienen un tiempo de inactividad.


Tengo todo sobre este tema. Es más panorámico, pero creo que será útil.


Vídeo:



All Articles