Skip to content

Add POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT to terminate idle in transaction sessions - #37

Open
richturner wants to merge 1 commit into
mainfrom
feature/idle_in_transaction_timeout
Open

richturner wants to merge 1 commit into
mainfrom
feature/idle_in_transaction_timeout

Conversation

@richturner

@richturner richturner commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Description

Adds a POSTGRES_IDLE_IN_TRANSACTION_SESSION_TIMEOUT environment variable (default 10min), configured the same way as POSTGRES_MAX_CONNECTIONS. The entrypoint passes it to the server as -c idle_in_transaction_session_timeout=.... Setting it to 0 or an empty value disables it, and any PostgreSQL time value (e.g. 30s, 30min) is accepted.

A session left idle in a transaction holds back the xmin horizon, so autovacuum can't remove dead rows. On a production instance this left the frequently updated openremote.asset table with a 177 MB heap for about 2,900 rows (3.7 MB after VACUUM FULL). The timeout terminates such sessions before they cause bloat.

Setting it at image level, rather than with ALTER DATABASE or in compose command args, means:

  • It applies to every deployment, including custom projects that override command.
  • It survives a backup/restore. Database-level settings aren't included in pg_dump openremote.

Notes

  • It applies to the whole server, including Keycloak and manual psql sessions. 10 minutes is far longer than any legitimate manager or Keycloak transaction should sit idle. A terminated session's transaction is rolled back and the pool replaces the connection.
  • Like max_connections, the argument is appended after any compose command args, so it takes precedence over a -c idle_in_transaction_session_timeout set there.

Testing

  • Tested the entrypoint logic with 10min, 30s, 0 and empty values. Each produced the expected postgres arguments.
  • Still to do: build the image, check SHOW idle_in_transaction_session_timeout; returns 10min, and run the manager and Keycloak against it.

Related

Merge order: this PR, then the core deploy.yml PR, then the docs PR.

… transaction sessions

Sessions left idle in a transaction prevent autovacuum removing dead
rows, which bloats frequently updated tables such as the asset table.
Default the timeout to 10min; set to 0 to disable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant