add isolation level

This commit is contained in:
steve-chavez
2023-05-11 01:37:50 -03:00
committed by Steve Chavez
parent e0b0e98816
commit 789cedff08
2 changed files with 49 additions and 29 deletions
+48 -29
View File
@@ -59,10 +59,29 @@ Modifying the database inside READ ONLY transactions is not possible. PostgREST
The :ref:`options_requests` method doesn't start a transaction, so it's not relevant here.
.. _isolation_lvl:
Isolation Level
---------------
Every transaction uses the PostgreSQL default isolation level: READ COMMITTED.
Every transaction uses the PostgreSQL default isolation level: READ COMMITTED. Unless you modify `default_transaction_isolation <https://www.postgresql.org/docs/15/runtime-config-client.html#GUC-DEFAULT-TRANSACTION-ISOLATION>`_ for an impersonated role or function.
Using :ref:`impersonated_settings`, change the isolation level for all the role's requests with:
.. code-block:: postgresql
ALTER ROLE webuser SET default_transaction_isolation TO 'repeatable read';
Or to change the isolation level per function call.
.. code-block:: postgresql
CREATE OR REPLACE FUNCTION myfunc()
RETURNS text as $$
SELECT 'hello';
$$
LANGUAGE SQL
SET default_transaction_isolation TO 'serializable';
.. _tx_settings:
@@ -87,34 +106,6 @@ And you can set them with ``set_config``
SELECT
set_config('response.<setting>', 'value1' ,true);
Request Role and Search Path
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Because of :ref:`user_impersonation`, PostgREST sets the standard ``role``. You can get this in different ways:
.. code-block:: postgresql
SELECT current_role;
SELECT current_user;
SELECT current_setting('role', true);
Additionally it also sets the ``search_path`` based on :ref:`db-schemas` and :ref:`db-extra-search-path`.
.. _impersonated_settings:
Impersonated Role Settings
~~~~~~~~~~~~~~~~~~~~~~~~~~
The :ref:`Impersonated Role <user_impersonation>` settings are applied. For example, if you do:
.. code-block:: postgresql
ALTER ROLE webuser SET statement_timeout TO '5s';
Every ``webuser`` request gets its queries executed with a ``statement_timeout`` of 5 seconds.
.. _guc_req_headers_cookies_claims:
Request Headers, Cookies and JWT claims
@@ -153,6 +144,34 @@ The path and method are stored as ``text``.
SELECT current_setting('request.method', true);
Request Role and Search Path
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Because of :ref:`user_impersonation`, PostgREST sets the standard ``role``. You can get this in different ways:
.. code-block:: postgresql
SELECT current_role;
SELECT current_user;
SELECT current_setting('role', true);
Additionally it also sets the ``search_path`` based on :ref:`db-schemas` and :ref:`db-extra-search-path`.
.. _impersonated_settings:
Impersonated Role Settings
~~~~~~~~~~~~~~~~~~~~~~~~~~
The :ref:`Impersonated Role <user_impersonation>` settings are applied. For example, if you do:
.. code-block:: postgresql
ALTER ROLE webuser SET statement_timeout TO '5s';
Every ``webuser`` request gets its queries executed with a ``statement_timeout`` of 5 seconds.
.. _guc_resp_hdrs:
Response Headers
+1
View File
@@ -8,6 +8,7 @@ Transactions
~~~~~~~~~~~~
- New :ref:`impersonated_settings`.
- New configurable :ref:`isolation_lvl`.
Inserts
~~~~~~~