What timeout parameters do you know in PostgreSQL? Tell about lock_timeout, statement_timeout, transaction timeout, and session timeout.
sobes.tech AI
Answer from AI
In PostgreSQL, there are several timeout parameters that help control operation execution time and prevent hangs:
-
lock_timeout — the maximum wait time for a lock. If a transaction cannot acquire the needed lock within this time, the operation is aborted with an error. Helps avoid long lockups.
-
statement_timeout — the maximum execution time for a single SQL query. If the query runs longer, it is terminated. Useful for preventing long and potentially problematic queries.
-
idle_in_transaction_session_timeout — the wait time for an idle session in a transaction. If a session remains idle in an open transaction longer than this, it is automatically terminated. Helps prevent long open transactions that can block resources.
-
session timeout as a separate parameter does not exist, but session lifetime can be controlled through application settings or external mechanisms.
Example of setting parameters:
SET lock_timeout = '5s';
SET statement_timeout = '30s';
SET idle_in_transaction_session_timeout = '1min';