Mysql – Does MySQL or PostgreSQL lock table on deletion

MySQLpostgresql

I am about to delete large amount of data from a database. I want to know if deletion of large number of records from table in MySQL or PostgreSQL, lock a table ?

Let's say my table has been adding 2 GB data per day since 2016, and I want to delete all records older than 6 months from now.

Would my table get locked and all my insert or update or delete queries fail during the deletion time ?

Best Answer

I don't know about MySQL but Postgres never locks the whole table when running DML statements - regardless of the number of affected rows.

Additionally writers never block readers, so even if you update all rows in a table, other transactions will still be able to SELECT from that table - obviously seeing the old values until your DML statement is committed.

Deleting rows from the table will also not block concurrent inserts (as long as there are no primary key conflicts). And inserting rows won't block deleting existing rows.

Again: the above is true for Postgres. I don't use MySQL, so I can't comment on that.