Şöyle yaparız
Açıklaması şöyleBEGIN; -- BEGIN A TRANASCATIONWITH batch_cursor AS (SELECT id FROM state_transitionsORDER BY id ASCLIMIT 10000 --- 10k record in a batch)FOR batch IN (SELECT * FROM batch_cursor)LOOPDELETE FROM large_tableWHERE id = batch.id;END LOOP;COMMIT; -- COMMITING THE TRANSACTION
With batch deletion, we’re gently removing a bunch of records in each go. This not only keeps our database humming but also reduces the risk of causing chaos. ALWAYS RUN THIS IN A TRANSACTION AND COMMIT IT TOGETHER
Hiç yorum yok:
Yorum Gönder