PostgreSQL Read Only Access

Sometimes, we need to open up the database to allow certain users to access the database without modifying it, normally for report generation purposes, or other applications.

 

 

 

1) First, create the user, and specify the basic permissions

 

CREATE USER <username> ENCRYPTED PASSWORD '<the-user-password>' NO CREATEDB NO CREATEUSER;
 

2) Next, grant certain privileges to the user to certain database.... the following command will allow user to "Select", but not "INSERT, UPDATE, DELETE".

 

GRANT SELECT ON <database-name> TO <username>;   

 

3) Then modify the pg_hba.conf to allow user access the database remotely.