Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Ensure we don't time out background index creation #15942

Closed
erikjohnston opened this issue Jul 14, 2023 · 3 comments · Fixed by #16085
Closed

Ensure we don't time out background index creation #15942

erikjohnston opened this issue Jul 14, 2023 · 3 comments · Fixed by #16085
Assignees
Labels
A-Database DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Critical Blocks development, potential data loss, more than 25% of users possibly affected, no workarounds. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@erikjohnston
Copy link
Member

erikjohnston commented Jul 14, 2023

We added a global timeout in #15853, which might break such (expected) long running queries.

@reivilibre reivilibre added T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. S-Critical Blocks development, potential data loss, more than 25% of users possibly affected, no workarounds. A-Database DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db O-Uncommon Most users are unlikely to come across this or unexpected workflow labels Jul 18, 2023
@reivilibre
Copy link
Contributor

As far as I know, this should be overridable at the transaction level with SET LOCAL statement_timeout. Shouldn't be a difficult fix but just needs someone to research that this actually works and add the exact incantation.

@H-Shay
Copy link
Contributor

H-Shay commented Aug 5, 2023

So looking into this SET LOCAL statement_timeout should work - the only caveat is that the SET LOCAL statement needs to be executed first rather than as part of the expected long-running statement, i.e.

        def test_set_local_tx(txn) -> None:
            sql = "SET LOCAL statement_timeout = 1"
            txn.execute(sql)
            more_sql = "SELECT pg_sleep(10)"
            txn.execute(more_sql)

        self.get_success(self.db_pool.runInteraction("", test_set_local_tx))

does the right thing and results in a psycopg2.errors.QueryCanceled: canceling statement due to statement timeout error but

        def test_set_local_tx(txn) -> None:
            sql = "SET LOCAL statement_timeout = 1; SELECT pg_sleep(10)"
            txn.execute(sql)

does not and merrily sleeps away. SET LOCAL statement_timeout = 0 is the incantation to disable the timeout for the next statement.
Should we put this in the documentation somewhere so people know to use this when creating a potentially long-running index?

@erikjohnston
Copy link
Member Author

@H-Shay I'd be tempted to set it automatically for all background index updates, i.e. somewhere around

conn.set_session(autocommit=True) # type: ignore

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Database DB stuff like queries, migrations, new/remove columns, indexes, unexpected entries in the db O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Critical Blocks development, potential data loss, more than 25% of users possibly affected, no workarounds. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants