mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Do not always start a db txn on Postgres (#14840)
This commit is contained in:
parent
218a383c43
commit
c1d2ce2901
1
changelog.d/14840.misc
Normal file
1
changelog.d/14840.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Prevent "WARNING: there is already a transaction in progress" lines appearing in PostgreSQL's logs on some occasions.
|
@ -23,7 +23,7 @@ from typing_extensions import Counter as CounterType
|
|||||||
|
|
||||||
from synapse.config.homeserver import HomeServerConfig
|
from synapse.config.homeserver import HomeServerConfig
|
||||||
from synapse.storage.database import LoggingDatabaseConnection
|
from synapse.storage.database import LoggingDatabaseConnection
|
||||||
from synapse.storage.engines import BaseDatabaseEngine, PostgresEngine
|
from synapse.storage.engines import BaseDatabaseEngine, PostgresEngine, Sqlite3Engine
|
||||||
from synapse.storage.schema import SCHEMA_COMPAT_VERSION, SCHEMA_VERSION
|
from synapse.storage.schema import SCHEMA_COMPAT_VERSION, SCHEMA_VERSION
|
||||||
from synapse.storage.types import Cursor
|
from synapse.storage.types import Cursor
|
||||||
|
|
||||||
@ -108,8 +108,13 @@ def prepare_database(
|
|||||||
# so we start one before running anything. This ensures that any upgrades
|
# so we start one before running anything. This ensures that any upgrades
|
||||||
# are either applied completely, or not at all.
|
# are either applied completely, or not at all.
|
||||||
#
|
#
|
||||||
# (psycopg2 automatically starts a transaction as soon as we run any statements
|
# psycopg2 does not automatically start transactions when in autocommit mode.
|
||||||
# at all, so this is redundant but harmless there.)
|
# While it is technically harmless to nest transactions in postgres, doing so
|
||||||
|
# results in a warning in Postgres' logs per query. And we'd rather like to
|
||||||
|
# avoid doing that.
|
||||||
|
if isinstance(database_engine, Sqlite3Engine) or (
|
||||||
|
isinstance(database_engine, PostgresEngine) and db_conn.autocommit
|
||||||
|
):
|
||||||
cur.execute("BEGIN TRANSACTION")
|
cur.execute("BEGIN TRANSACTION")
|
||||||
|
|
||||||
logger.info("%r: Checking existing schema version", databases)
|
logger.info("%r: Checking existing schema version", databases)
|
||||||
|
Loading…
Reference in New Issue
Block a user