Question

I want to vacuum a table in PostgreSQL version 9.1 which will take between 10 to 12 minutes. This needs to be done in real-time, in production use.

I just want to know that if any INSERT or UPDATE query comes, will they wait for the lock to be lifted, or will they time out?

NOTE: The Java code that will fire the query has not specified any timeout.

Was it helpful?

Solution

The documentation says the following:

ROW EXCLUSIVE

Conflicts with the SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes.

The commands UPDATE, DELETE, and INSERT acquire this lock mode on the target table (in addition to ACCESS SHARE locks on any other referenced tables). In general, this lock mode will be acquired by any command that modifies data in a table.

SHARE UPDATE EXCLUSIVE

Conflicts with the SHARE UPDATE EXCLUSIVE, SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE lock modes. This mode protects a table against concurrent schema changes and VACUUM runs.

Acquired by VACUUM (without FULL), ANALYZE, CREATE INDEX CONCURRENTLY, and some forms of ALTER TABLE.

There is no conflict between the two lock types involved. This means that neither INSERT/UPDATE blocks VACUUM, nor the other way around. This means furthermore that your queries should succeed without timeouts. Most probably the I/O activity of vacuuming won't do you any harm.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top