mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-12 13:01:34 +01:00
Override global statement timeout when creating indexes in Postgres (#16085)
This commit is contained in:
parent
8a4fb7a6ba
commit
0377cb4fab
2 changed files with 13 additions and 0 deletions
1
changelog.d/16085.misc
Normal file
1
changelog.d/16085.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Override global statement timeout when creating indexes in Postgres.
|
|
@ -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()
|
||||
|
||||
|
@ -758,6 +759,11 @@ class BackgroundUpdater:
|
|||
logger.debug("[SQL] %s", sql)
|
||||
c.execute(sql)
|
||||
|
||||
# override the global statement timeout to avoid accidentally squashing
|
||||
# a long-running index creation process
|
||||
timeout_sql = "SET SESSION statement_timeout = 0"
|
||||
c.execute(timeout_sql)
|
||||
|
||||
sql = (
|
||||
"CREATE %(unique)s INDEX CONCURRENTLY %(name)s"
|
||||
" ON %(table)s"
|
||||
|
@ -778,6 +784,12 @@ class BackgroundUpdater:
|
|||
logger.debug("[SQL] %s", sql)
|
||||
c.execute(sql)
|
||||
finally:
|
||||
# mypy ignore - `statement_timeout` is defined on PostgresEngine
|
||||
# reset the global timeout to the default
|
||||
default_timeout = self.db_pool.engine.statement_timeout # type: ignore[attr-defined]
|
||||
undo_timeout_sql = f"SET statement_timeout = {default_timeout}"
|
||||
conn.cursor().execute(undo_timeout_sql)
|
||||
|
||||
conn.set_session(autocommit=False) # type: ignore
|
||||
|
||||
def create_index_sqlite(conn: Connection) -> None:
|
||||
|
|
Loading…
Reference in a new issue