0

There are 2 users in DB(PostgreSQL 9.3). 1) The X user do a lot of SELECT/INSERT queries. 2) The Y user do a query which need "ACCESS EXCLUSIVE" lock.

Is there a way to grand the Y user a privilege so the queries from Y user will 1) stop the queries of X users. 2) finish the query of Y user 3) restart the queries of X user

1 Answer 1

2

No, there isn't. PostgreSQL doesn't currently support aborting conflicting transactions on lock requests, though it'd be a nice-to-have. You can have a periodic task query pg_stat_activity and pg_locks looking for queries waiting on an AccessExclusiveLock and pg_terminate_backend any conflicting workers, but it's a bit heavy handed.

Nor can PostgreSQL re-run aborted queries, the application is expected to do that its self. Consider that the query might be the fourth in a transaction; it'd be completely wrong for Pg to just re-run the last query in the transaction. It must abort the whole transaction. And it doesn't know if it's even correct to re-run it. So the application must take care of this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.