简体   繁体   中英

postgresql: delete all locks

question: there is a table with over 9000 rows. It must be cleaned but without any locks (table in active using). I tried to use pg_advisory_unlock_all, but no result.

select pg_advisory_unlock_all();
start transaction();
delete from table where id='1';
DELETE 1

start transaction();
delete from table where id='1';
(waiting for finish first transaction)

There is no way to delete data from a table without locking the rows you want to delete.

That shouldn't be a problem as long as concurrent access doesn't try to modify these rows or insert new ones with id = '1' , because writers never block readers and vice versa in PostgreSQL.

If concurrent transactions keep modifying the rows you want to delete, that's a little funny (why would you want to delete data you need?). You'd have to wait for the exclusive locks, and you might well run into deadlocks. In that case, it might be best to lock the whole table with the LOCK statement before you start. Deleting from a table that small should then only take a very short time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM