Repository navigation
Description
In short: Before every write transaction the adapter sends a
ROLLBACK, even when nothing is open. Postgres answers each one with a warning in its log.Impact:
- One wasted round trip per write.
- Under write load 99.7 % of the Postgres log is this warning, and with Docker's log rotation the log only covers a few minutes: real errors get lost.
👟 Reproduction steps
-
Run Appwrite 2.3.0 with
_APP_DB_ADAPTER=postgresql. -
Enable statement logging:
ALTER SYSTEM SET log_statement = 'all'; SELECT pg_reload_conf(); -
Create one row:
POST /v1/tablesdb/{db}/tables/{table}/rows. -
docker logs appwrite-postgresql:LOG: statement: ROLLBACK WARNING: there is no transaction in progress LOG: statement: BEGIN LOG: statement: SET LOCAL statement_timeout = '15000ms' LOG: statement: INSERT INTO "appwrite"."_1_database_1_collection_2" … LOG: statement: COMMIT
The WARNING line is logged with default settings (no log_statement needed) on every write.
👍 Expected behavior
No ROLLBACK is sent when no transaction is open, and normal writes do not produce a server warning.
👎 Actual Behavior
Summary
SQL::startTransaction() cleans up the pooled connection before BEGIN:
- If PDO reports an open transaction, it calls
rollBack(). - Otherwise it still executes a plain
ROLLBACK(SQL.php#L75-L105, theprepare('ROLLBACK')at L84).
In the normal case no transaction is open, so every write transaction pays one extra round trip. PostgreSQL also answers every such ROLLBACK with:
WARNING: there is no transaction in progress
Suggested fix
- Trust the connection state: send
ROLLBACKonly when the driver or connection reports an open transaction (PDO::inTransaction()), or when the adapter's own counter is out of sync. - If a desynced proxy state must be covered (the reason for fix(transaction): tolerate desynced cleanup rollback on startTransaction utopia-php/database#895), do the cleanup once when a connection is taken from or returned to the pool, or after a reconnect, not before every
BEGIN. - If PDO's own state is not trustworthy after a reconnect, reset the adapter's transaction counter in the reconnect path instead.
Impact on throughput is small (one short round trip per write). The main problem is the log flood.
Since when / regression?
Version numbers refer to utopia-php/database unless an Appwrite version is named.
- The cleanup
ROLLBACKhas been instartTransaction()since 0.53.13. MariaDB ignores aROLLBACKoutside a transaction without a warning. - With PostgreSQL the warning appears in every Appwrite release that uses the Postgres adapter (2.0.0 onwards). It is not a regression.
Risks / things to consider for the fix
- The desync case from fix(transaction): tolerate desynced cleanup rollback on startTransaction utopia-php/database#895 must stay covered: a connection that reconnected mid-transaction can report a transaction it no longer has, or the other way round. Moving the cleanup to the reconnect or pool-return path must not leave a connection inside an aborted transaction.
PDO::inTransaction()reflects the driver's view. If a proxy layer keeps its own counter, that counter must be reset on reconnect.
Related: utopia-php/database#895, #14075 (same test setup).
Related issues from the same analysis (Appwrite 2.3.0 with Postgres, same test setup):
- 🐛 Bug Report: Two uncached team queries on every API request #14077 – every request runs two uncached queries for the project team
- 🐛 Bug Report: Postgres insert reads back
_idwith an extra query #14078 –_idread back after every insert instead ofINSERT … RETURNING - 🐛 Bug Report: Postgres adapter sets and resets
statement_timeoutaround every query #14079 –SET/RESET statement_timeoutaround every query - 🐛 Bug Report: Postgres: fulltext search never uses an index #14081 – fulltext indexes on Postgres are plain B-trees,
searchcannot use them - 🐛 Bug Report:
total=falseon list endpoints is ignored #14082 –total=falseon list endpoints is ignored - 🐛 Bug Report: Pool adapter checks out a connection for every capability getter #14083 – pool adapter checks out a connection for constant capability getters
- 🐛 Bug Report: Usage queue backlog evicts the cache from Redis #14084 – usage queue backlog evicts the cache in the shared Redis
- 🐛 Bug Report: PostgreSQL adapter never uses the
_uidindex – every create, get and update by row ID scans the whole table #14075 – Postgres adapter never uses the_uidindex (collation)
🎲 Appwrite version
Version 2.3.0 (self-hosted)
💻 Operating system
Linux (Debian 12, Docker 29.8)
🧱 Your Environment
Self-hosted Appwrite 2.3.0 with _APP_DB_ADAPTER=postgresql, PostgreSQL 18.3 (appwrite/postgres:0.1.0), utopia-php/database 7.3.11. Test setup: Postgres, Redis and ClickHouse on one 4 vCPU node, the API on two separate 4 vCPU nodes, load from oha. The code in question lives in utopia-php/database; filed here because it ships with Appwrite and affects every Appwrite install that uses Postgres. Related test setup: #14075.
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity
subhu339 commentedon Oct 4, 2026
Hey @JoshiJoshiJoshi 👋
Opened a PR to address this in utopia-php/database#989.
It drops the unconditional ROLLBACK fallback in SQL::startTransaction(), which gets rid of the extra round trip and Postgres log warnings while keeping the #895 desync handling intact.
[-]🐛 Bug Report: Postgres adapter sends `ROLLBACK` before every `BEGIN` – one extra round trip and one server WARNING per write, flooding the Postgres log[/-][+]🐛 Bug Report: Postgres adapter sends `ROLLBACK` before every `BEGIN`[/+]