Skip to content

Commit da2a817

Browse files
committed
Update docs for row_security session variable
Fixes DOC-15036
1 parent 9bc9536 commit da2a817

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/current/_includes/v25.4/misc/session-vars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ The following session variables are exposed only for backwards compatibility wit
109109
| <a id="integer-datetimes"></a> `integer_datetimes` | `on` | No | Yes |
110110
| <a id="max-identifier-length"></a> `max_identifier_length` | `128` | No | Yes |
111111
| <a id="max-index-keys"></a> `max_index_keys` | `32` | No | Yes |
112-
| <a id="row-security"></a> `row_security` | `off` | No | Yes |
112+
| <a id="row-security"></a> `row_security` | `on` | Yes | Yes |
113113
| <a id="standard-conforming-strings"></a> `standard_conforming_strings` | `on` | No | Yes |
114114
| <a id="server-encoding"></a> `server_encoding` | `UTF8` | Yes | Yes |
115115
| <a id="synchronize-seqscans"></a> `synchronize_seqscans` | `on` | No | Yes |

src/current/v25.4/row-level-security.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ For examples, refer to:
128128
- [`ALTER TABLE ... ENABLE ROW LEVEL SECURITY`]({% link {{ page.version.version }}/alter-table.md %}#enable-row-level-security).
129129
- [`ALTER TABLE ... FORCE ROW LEVEL SECURITY`]({% link {{ page.version.version }}/alter-table.md %}#force-row-level-security).
130130

131+
### Detect when row-level security is applied to a query
132+
133+
The [`row_security`]({% link {{ page.version.version }}/set-vars.md %}#row-security) [session variable]({% link {{ page.version.version }}/session-variables.md %}#row-security) controls whether queries in the current session should silently honor RLS policies or error when those policies would filter out rows.
134+
135+
The variable defaults to `on`, which applies policies as normal. Setting it to `off` lets non-admin users detect when an RLS policy would alter their results by returning an error instead of silently filtering rows. [Admin users and table owners]({% link {{ page.version.version }}/alter-table.md %}#force-row-level-security) remain exempt from RLS regardless of this setting. Table owners will still be subject to RLS if [`ALTER TABLE ... FORCE ROW LEVEL SECURITY`]({% link {{ page.version.version }}/alter-table.md %}#force-row-level-security) is in effect.
136+
137+
The following example shows how this session setting works:
138+
139+
{% include_cached copy-clipboard.html %}
140+
~~~ sql
141+
-- Enable RLS error detection for the current session.
142+
SET row_security = off;
143+
144+
-- This query now errors if an applicable policy would filter rows.
145+
SELECT * FROM sensitive_table;
146+
147+
-- Restore the default behavior.
148+
RESET row_security;
149+
~~~
150+
131151
### RLS for data security (fine-grained access control)
132152

133153
In a fine-grained access control scenario, you will want to restrict access to specific rows within a table based on user [roles]({% link {{ page.version.version }}/security-reference/authorization.md %}#roles), attributes, or relationships defined within the data itself. This goes beyond table-level [`GRANT`]({% link {{ page.version.version }}/grant.md %}) permissions. Common examples include restricting access to salary information, personal data, or region-specific records.

0 commit comments

Comments
 (0)