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

Commit

Permalink
use session instead of local when setting statement_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Aug 15, 2023
1 parent 6de8215 commit 3502fea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion synapse/storage/background_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class BackgroundUpdater:
def __init__(self, hs: "HomeServer", database: "DatabasePool"):
self._clock = hs.get_clock()
self.db_pool = database
self.hs = hs

self._database_name = database.name()

Expand Down Expand Up @@ -760,7 +761,7 @@ def create_index_psql(conn: Connection) -> None:

# override the global statement timeout to avoid accidentally squashing
# a long-running index creation process
timeout_sql = "SET LOCAL statement_timeout = 0"
timeout_sql = "SET SESSION statement_timeout = 0"
c.execute(timeout_sql)

sql = (
Expand All @@ -777,6 +778,11 @@ def create_index_psql(conn: Connection) -> None:
logger.debug("[SQL] %s", sql)
c.execute(sql)

# mypy ignore - `statement_timeout` is defined on PostgresEngine
default_timeout = self.db_pool.engine.statement_timeout # type: ignore[attr-defined]
undo_timeout_sql = f"SET statement_timeout = {default_timeout}"
c.execute(undo_timeout_sql)

if replaces_index is not None:
# We drop the old index as the new index has now been created.
sql = f"DROP INDEX IF EXISTS {replaces_index}"
Expand Down

0 comments on commit 3502fea

Please sign in to comment.