Struggling with the load in PostgreSQL, does replication help with this. Andrey Salnikov (Data Egret)



What to do when the PostgreSQL master server dies under load?



Quite often, a situation occurs when the database does not support the existing load and vertical scaling of hardware does not help. Swap PostgreSQL for another database or redesign the application architecture and abandon the DBMS?



Let me introduce myself.





. Postgres. Data Egret. DBA . Postgres. , , .



. . Postgres – open source , , , . . . .





– - , . , , , . .





– . , . . .





, , . 50 000 - – Postgres. – 20 000-30 000. . , , , - .





, CPU. , , CPU , , .





. , 20 000 . .



, . , .



. , Postgres, , . , , , , , . . , . , , . . . .





, . . 40 000 , .



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





– , . , 10-20 .





, , . , - .





, – , idle in transaction.



Idle in transaction – , transaction id . : , . . , .





, , , .



, pool connections. pool connections, : Hibernate , Python . , , . .



, , . PgBouncer Odyssey, , .





- . .



, . , , . , , - , .





, . 100 % .



  • 50 % . - , , , 80 % 90 % . ? , , , . , , - , , . . , . , . - , . RDBMS . RDBMS - -, , , , . – - , -, .



  • , 50 % . , , . , , , , , -. , 10 , , 10 . , , . - , , 50 % .



  • – , . , , , 10 , . . , , , . , , , , . , , . , , , , .



  • , . , .



    • , , . ID, ID . , , . Postgres , . , . . JSON, , JSON, JSON. JSON – , , Postgres.
    • . . JSON - , , JSON. , , . - , - , . . , . , , , . , , , - - . , . , . . . .






  • . – , . . , , . , , - . ORM, . , 1 , 200 . . , , 20 , , , , - . . . , , , , . Postgres, , , , .



  • , DISTINCT n*JOIN. , DISTINCT GROUP BY , , - . , JOIN, JOIN , . . , , , , . , JOIN . , . - , DISTINCT, . - , 10 . – , , .



  • – COUNT, MAX, MIN, SUM , . , . , , 5 . 5 , , - – , - . , , , .



  • , . WHERE id IN SELECT . . EXISTS (SELECT…). . SELECT - , . , .



  • LEFT JOIN , EXISTS (SELECT…) , LEFT JOIN. ? LEFT JOIN , . EXISTS. . . , LEFT JOIN, EXISTS, , .



    β€”



  • . , . . , , - -, , - , , , , -, . . , , . , , Postgres. , . , superuser. , . , . -, - . . , . cron. report . , - , - , , , , . . - , .







  • , Postgres. . . , . . RabbitMQ, ZeroMQ, Kafka. , , . DBA , . . , . . . , , .



    • PgQ – , , . , , . PgQ , microsoft’ .


  • . - .



    • , - , idle- . , . Postgres . 100-200-300 – , . 1 000 – , pools . idle-, . , , .
    • – PgBouncer transaction . . . prepared statements . set- PgBouncer. , , , . , , , , , . . , Odyssey PgBouncer .


  • . ? , , wraparound vacuum, vacuum, .



    • . - , , . . - . : , . , 99 % . 1 %. , , . . , – .
    • (). «», . - – . . , . .






, , 100 % . , . - . , , . .



  • , , , , , , - Data Lake, Big Data. . . , , . , . , . . .




? , .



, , , , . - , web-. , , . . - ID, - JOIN. -.



, . , .



. , . . , . , . , Fault Tolerance, . . , . , .





. ? , , COUNT, MAX, MIN, . . , , . , , , . , .



? - . , . . . , .



, – max_streaming_delay, . , – , . , .



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





? . , , - . , . , max_streaming_delay. , . , , . .



, - -, . , . , .





? , , . , -, , latency. latency – 10-20 . .



, . , . , .



. , . , , , , .



Β«() Β»? . . bloat . . - . - , , .





, Postgres?



Max_standby_streaming_delay – . , , , . . , . , . . , , , . . , . . , . , .



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



hot_standby_feedback , , , , .



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



– max_standby_streaming_delay, . – , .





, Postgres, . . .



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



, , , , . . , .



. , -, , -, , -. , : . , . , . , , .



, delayed . recovery.conf Postgres , , , . -.



? deploy. , , - , , . delayed , .



. . , deploy. , , , – . , .



. , . , . , .



. , , .





, ! WAL . , , , , - ? , .



, . . . , , . . - , , - , . . , - . , . . WAL . - . .



?



-, . , . . . . , WAL-G, - . , , , - , . , , . .



!



! ! . , – PgBouncer ? ? per_request ? . . , , PgBouncer , PgBouncer – ?



, . transaction PgBouncer -. . . - - idle-, , . , , . . , , - , . , , , , . , , , , .



. . ?



PgBouncer . . PgBouncer . . , . , .



!



, ! ! , , , . . ?



– .



, 100 % ?



, , - . WAL-, - , . . . . , .



- ?



. , . , . . . .



!



, ! . , . , . - . failover? . . – ? ?



, , tools, auto_failover Postgres , - , - . , . . - , . . , . , WAL . -. , auto_failover, . , .



!



- , ? , , , - .



. instance Postgres . , . , : , , . , . . , . . – , , .



! ! , COUNT, - ? , , ?



COUNT, , -, – ? , , , . , , 10 . COUNT . , 10 5 . 10 . – ? . , 3-5 .



-, .



. COUNT 100 000 , 100 000 5 100 000 , , , COUNT . . , - , . .



, , !



, ! , . . , ? PgBouncer - , instance , instance? - , ?



. . , - . - , , . ? SELECT, . ? , ? , , , . , , . . . , , . . , .



? Discovery, . , . , , . .



, ! , , , , , , - . , ? , .



PgPool , , .



, !




All Articles