Lieber LÖSCHEN. Nikolay Samokhvalov (Postgres.ai)



Irgendwann in ferner Zukunft wird das automatische Löschen unnötiger Daten eine der wichtigen Aufgaben eines DBMS sein [1]. In der Zwischenzeit mĂŒssen wir uns selbst darum kĂŒmmern, unnötige Daten zu löschen oder auf kostengĂŒnstigere Speichersysteme zu verschieben. Angenommen, Sie möchten mehrere Millionen Zeilen löschen. Eine recht einfache Aufgabe, insbesondere wenn der Zustand bekannt ist und ein geeigneter Index vorhanden ist. "DELETE FROM table1 WHERE col1 =: value" - was könnte einfacher sein, oder?



Video:







  • Ich bin seit dem ersten Jahr, d. H. Seit 2007, im Highload-Programmkomitee.



  • Und ich bin seit 2005 bei Postgres. Verwendet es in vielen Projekten.



  • Eine Gruppe mit RuPostges auch seit 2007.



  • Bei Meetup sind wir auf ĂŒber 2100 Teilnehmer angewachsen. Es ist das zweitgrĂ¶ĂŸte der Welt nach New York und wurde lange Zeit von San Francisco ĂŒberholt.



  • . , . Postgres. .







https://postgres.ai/ – . , , .



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





https://www.seagate.com/files/www-content/our-story/trends/files/idc-seagate-dataage-whitepaper.pdf



VLDB -. . , , . .



– 1 000 000 . , 100 . .





https://vldb2019.github.io/files/VLDB19-keynote-2-slides.pdf



? , . . .



, , . , , .





, , , , . . , , . .





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





, , - .





, , . . .





. , – . staging – . – . – .





. DELETE .





, , . .





. - , .



dev, staging – . , , . , .





? . , - . , , . , DELETE .





? , . ?



  • , review, . . DBA- . , prod, .



  • , - .



  • .



  • - , Postgres MySQL .



  • , , - .



  • , - , ?







DBA. DBA , : « ». , GitLab, GitHub code review , DBA prod, DBA : « ».





, disk IO , , , .





http://bit.ly/nancy-hl2018-2



– . , prod , , staging . , 1 000 , .



, , . . , , . -.



. , , . , . , YouTube .





, ? , latency . , 100 %. , NVMe , , , . , , .



, . . Switchover. . .





- ? DBA , checkpoint tuning. , checkpoint tuning.



checkpoint? . , . , , , write-ahead log. - , , , , REDO. . , checkpoint. .





Postgres . 10-15- . checkpoint – .



c Postgres check-up, . . . - . , checkpoints 90 % .



? . Checkpoint timeout , , 10 . , .



max_wal_saze 1 . , Postgres 300-400 . checkpoint .



, , , , checkpoint , 30 , . .



, . . . max_wal_size. .



, , . . , .





, .



– max_wal_size. . 1 . DELETE .



, . , disk IO . , WAL , . . . , checkpoint . , .



max_wal_size. . , . . , 10 – , 1, 2, 4, 8 . . , prod. , Postgres .



, , DELETE, checkpoint’.



Checkpoint - – .



: DELETE , «» .





. . 1 max_wal_size , . – , . . . , DELETE .



prod, , , DELETE .





, 16 , , . – , . . , . . – . – . , , 16 .





64 , . , , - .



?





, , checkpoint tuning, , , , .



checkpoint , , , , , , , , . checkpoint , , .



checkpoint . .





. Postgres 8 , Linux 4 . full_page_writes. . , , , , .



WAL , , checkpoint , , . . 8 , , 100 . .



, .



, , checkpoint , . checkpoints, , full_page_writes = on , , . . WAL . , , .



, , .





max_wal_size, , checkpoint, wal writer. .



. ? , , checkpoint . REDO . .



, checkpoint , , kill -9 Postgres .



, , , . . REDO .



, . -, checkpoint, , . , -, . checkpoints -, , , WAL checkpoint. . . .



max_wal_size , , max_wal_size 64 , 10 . – . -. , - : « ? 3-5 ?». .



. Patroni. , , . autofailover Postgres. GitLab Data Egret .



autofailover, 30 , 10 ? , . . . , .



, . , , - 10 .



- , autofailover. , , 64, 100 – . . , .





, , , max_wal_size =1, 8, . . , . ?



, , . .



. , «BEGIN, DELETE, ROLLBACK», DELETE . . . , . . bloat . DELETE.



DELETE c ROLLBACK checkpoint tuning, database labs.





«i». Postgres . , . : ctid, xmid, xmax.



Ctid – . , .



, ROOLBACK . . . , . .





Xmax – . , Postgres , , , 0, – . , DELETE . database labs .





. DBA , : « ?». . , .



, . . DELETE . 20 , . , , , .



?



  • , , . , , throttling.



  • . , , , , , , autovacuum, , . , - , , - . .







https://postgres.ai/products/joe/



. , : « ?».



, , transaction overhead, . . . .



: , .



? , . . 50 . - , . , . - 100 , , , 100 , . .



, 10- , , - . , . . , transaction overhead . , .



. - . . . . . DELETE UPDATE.



, , , DELETE. , .



, . index scan, index only scan. . . .



, . , , - . , . database labs.



-, production . , , , . , . , - , .



, , . . . 30 , . - RESET, . . . .





https://docs.gitlab.com/ee/development/background_migrations.html



? 3 , .



. . , . . 100 , 5 , 1 000 . , . ID . .



– . Gitlab. . ID , 10 000 . - . . .



, , . .





https://medium.com/@samokhvalov/how-partial-indexes-affect-update-performance-in-postgres-d05e0052abc



. . , . . , , ID. ID, index only scan, heap .



, index only scan – , index scan.





, . BATCH_SIZE . , . , , , , . for update skip locked. Postgres , . . CTE – . CTE – returning *. returning id, *, .





? , . . ID created_at -. min, max . - . . .



. , , , heap only tuples updates. . . Postgres . pg_stat_user_tables . – hot updates .



, . updates, , . ( - updates, -), . . . , . . , - , , -, , .



, batches , - . .





— https://gitlab.com/snippets/1890447



Blocked autovacuum — https://gitlab.com/snippets/1889668



Blocking issue — https://gitlab.com/snippets/1890428



№ 5 . Okmeter Postgres. Postgres, , . - , - . Okmeter – , , . .



, dead tuples . , - . , , . .



IO, , .



. OLTP . , .



– ? . . autovacuum . . hot standby , . , .



, alert . . autovacuum. Avito, . , , autovacuum. , - . alert .



issues. . - - . Data Egret CTE, . . . . statement_timeout . lock_timeout .





.



, – . , . 2 – .



, production, . production.



. , . DBA , , . .



. , , REPACK . . , .



, , . -. : . , .





, , open source. GitLab. , DBA. database lab, . . , Joe. production. Joe slack, : «explain - » . DELETE , .





, 10 , database lab 10 . 10- 10 . , . , . . . .





thin provisioning. . , , . . . .



: 5 , , 30 . , . . , .



Postgres.ai . , , . . . .





, , , , . . . , , . , , . ?



. , pg_repack, , , 4- . , , 8 .



. . . . . . . . pg_repack. . , , . , . . , . , , .



pg_repack GitHub , , int 4 int 8, pg_repack . , , . , pg_repack : « », . . , . .



, .



Bloat , . , , . . . . Python, .



MySQL, . .



, 90 %. 5 %, .



! prod, - , ?



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



! , Postgres, - , . . Postgres, - DELETE deferent - , , - ?



SQL , Postgres ? . . . .



.



, checkpoint tuning . - , , . .



, , , ? .. ?



, . Nancy, checkpoint tuning. - Postgres? , . . , . . . , auto tuning . . checkpoint tuning . . . performance, shell buffer . .



checkpoint tuning : , cloud, Nancy . max_wal_size . , .



! . , autovacuum . ? . ?



Autovacuum – , , . , , . , . , . autovacuum – . OLTP: autovacuum. hot standby feedback , autovacuum , . , , . . , – . -, . . . . , autovacuum, .



! , . , , . , . . . live, live, , 60-70 %. ,



DBA, , , — . , . , , production . . . -. , – . .



garbage select , , deleted flag



, autovacuum Postgres.



, ?



Autovacuum garbage collector.



!



! , - ?



, .



Ist es dann möglich, uns zu schĂŒtzen, wenn wir einen Tisch gesperrt haben, der nicht verwendet werden sollte?



NatĂŒrlich gibt es. Aber das ist eine Frage wie ein Huhn und ein Ei. Wenn wir alle wissen, was in Zukunft passieren wird, werden wir natĂŒrlich alles großartig machen. Aber das GeschĂ€ft Ă€ndert sich, es gibt neue Spalten, neue Abfragen. Und dann - hoppla, das wollen wir entfernen. Aber diese ideale Situation tritt im Leben auf, aber nicht immer. Insgesamt ist dies jedoch eine gute Idee. Einfach abschneiden und fertig.




All Articles