-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pg_repack is not terminating conflicting queries when repacking only indexes #310
Comments
ISTM you have a default lock_timeout that is kicking in before repack gets to the point where it's own wait_timeout would activate. |
Hello, Or I am mistaken... btw |
Per the docs, the wait-timeout of pg_repack only kicks in at the point of doing the pg_catalog updates for swapping a repacked table for the original table, it does not kick in (and in fact, because it uses the built in reindex sql command, cannot kick int) when rebuilding indexes. I wonder if it might be possible to set a local lock_timeout and then nest the index reindexes using savepoints and then terminate connections if it fails due to a lock_timeout error and retry, but the locking ramifications seem concerning. As a work around, it is probably easier to turn off the lock timeout on your pg_repack run. Out of curiosity, do you know what the query/queries are that lead to these 30 second lock waits? |
You are correct, probably turning off lock timeout for pg_repack run would resolve issue. I just wasn't aware that --wait-timeout will work only for swapping repacked table for the original table. It would be useful if pg_repack would terminate conflicting transactions when you specify wait-timeout for repacking indexes also. I don't have conflicting query/queries - I think problem is with highly concurrent tables. For example even when one conflict transaction finishes, newly opened transaction started meanwhile on the table will block CREATE INDEX CONCURRENTLY. If you have very concurrent table CREATE INDEX CONCURRENTLY could wait long time. This is why it would be useful to have option to terminate conflicting transactions for repacking indexes. Another problem is, if you have lock_timeout, after every pg_repack failure you are left with INVALID indexes on the table. |
IMHO, I would avoid using pg_repack with --only-indexes option. PG can only do 1 concurrent index creation at a time (per official documentation). So if you have multiple indexes to be concurrently created, this could cause problems for other competing transactions that might come in between the 1st and 2nd concurrent index build. I think this --only-indexes option should be done away with or else pg_repack has to get a lot more complicated to handle this option. The official pg_repack documentation alludes to this scenario when describing error outcomes:
I would suggest using ** REINDEX TABLE CONCURRENTLY table**, which rebuilds all the indexes without blocking and without regard to whether or not they already exist and are in INVALID state. In fact, I fail to see the difference between pg_repack --only-indexes and REINDEX table CONCURRENTLY table. |
Hello,
pg_repack is not terminating conflicting queries when repacking indexes only - wait-timeout is specified.
SESSION 1:
SESSION 2:
Operation failed and we have invalid indexes created:
Env:
OS: Centos 7
PG 11/14
The text was updated successfully, but these errors were encountered: