PostgreSQL 9.5: Row Level Security by Example

Hello guys, Since last two months I have published about the SQL Server Interview Questions and Answers.
During this time, I got lots of messages and requests about the PostgreSQL.

In this August – 2016, I am going to post about only PostgreSQL and will try to complete all pending requests of readers.

In this post, I am going to publish about The Row Level Security which is now a common feature of all newly version of RDBMSs like SQL Server 2016, PostgreSQL 9.5.

Postgre SQL Row Level Security

With the concept of Row Level Security, we can restrict the user for a particular set of records.
Previously, we are doing this kind of restriction using by creating filtered VIEWS and assign related VIEWS to related Users.

PostgreSQL 9.5 has this Row Level Security feature which extends the overall security policy of the PostgreSQL.

Let me demonstrate this.

Execute below all steps using Postgres Super user:

First create two sample users:

Create a table with sample data:
Add one new column for row level security:
Update table with specific user:
Give some DML grants to these users:
Create a security policy on tbl_Employee for current logged-in user only:
Enable ROW LEVEL SECURITY on tbl_Employees:
Execute this SELECT with the different logins:
Result of User abc:
Result of User xyz:
Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz