This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing the help on how to create, a read-only user with limited access in PostgreSQL Database Server?.
As a Database Administrator, you should create different database users for the different purposes.
In the standard application, there are a few various types of Database Users like Application user, Read-only user, Admin user.
You should always create a shared database role group and assign roles to the user.
Here, I am sharing one script to create the read only user with limited access to PostgreSQL Database. This user can only SELECT table data and also restricted by schema access.
Create the Read-Only user:
1 2 |
CREATE ROLE Read_Only_User WITH LOGIN PASSWORD 'Test1234' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION VALID UNTIL 'infinity'; |
Assign permissions to the read only user:
1 2 3 4 |
GRANT CONNECT ON DATABASE YourDatabaseName TO Read_Only_User; GRANT USAGE ON SCHEMA public TO Read_Only_User; GRANT SELECT ON ALL TABLES IN SCHEMA public TO Read_Only_User; GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO Read_Only_User; |
In the above script, you can find that I restricted user by Database, Schema and gave only SELECT permission for tables.
If you need to give any additional permission like EXECUTE permission for functions, use below script.
1 |
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO Read_Only_User; |