You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add: per request statement timeout using prefer header
Adds a feature to set `statement_timeout` using `Prefer: timeout`
header. This also introduces a `PGRST129` error which is returned
when the timeout preferred exceeds the per-role timeout, which
prevents misuse of this feature.
Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
Copy file name to clipboardExpand all lines: docs/references/api/preferences.rst
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ The following preferences are supported.
15
15
- ``Prefer: missing``. See :ref:`prefer_missing`.
16
16
- ``Prefer: max-affected``, See :ref:`prefer_max_affected`.
17
17
- ``Prefer: tx``. See :ref:`prefer_tx`.
18
+
- ``Prefer: timeout``. See :ref:`prefer_timeout`.
18
19
19
20
.. _prefer_handling:
20
21
@@ -296,3 +297,62 @@ With :ref:`RPC <functions>`, the preference is honored completely on the basis o
296
297
.. note::
297
298
298
299
It is important for functions to return ``SETOF`` or ``TABLE`` when called with ``max-affected`` preference. A violation of this would cause a :ref:`PGRST128 <pgrst128>` error.
300
+
301
+
.. _prefer_timeout:
302
+
303
+
Timeout
304
+
=======
305
+
306
+
You can set `statement_timeout <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STATEMENT-TIMEOUT>`_ for the request using this preference. This works in combination with ``handling=strict`` preference in the same header.
307
+
308
+
The header only accepts integer value indicating the ``seconds`` that are set as timeout value. To demonstrate, see the following example:
"message": "canceling statement due to statement timeout"
333
+
}
334
+
335
+
It is important to note the timeout value cannot exceed the ``statement_timeout`` set :ref:`per-role <impersonated_settings>`. This restriction prevents misuse of this feature. PostgREST returns a :ref:`PGRST129 <pgrst129>` error in this case.
336
+
337
+
.. code-block:: postgres
338
+
339
+
ALTER ROLE postgrest_test_anonymous SET statement_timeout = '3s';
details (TimeoutConstraintError t rt role) =Just$JSON.String$"Timeout preferred: "<>show t <>"s, statement_timeout of role '"<>T.decodeUtf8 role <>"': "<>T.decodeUtf8 rt
0 commit comments