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:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of