Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Postgres database with read only access.

Tags:

postgresql

Is it possible to restrict my connection to a database through the psql client to be read only. I.E. The role using to connect to the database has full privileges on it, but I want to restrict some of my connections to being read-only.

Is this possible or do I have to simply create a new database role with my desired privileges.

like image 319
tommy_p1ckles Avatar asked Jan 31 '17 14:01

tommy_p1ckles


People also ask

How check postgres database is read only?

In mysql we can check whether the database is in read-only mode by triggering the below query. SELECT schemaname||'. '||tablename FROM pg_tables WHERE has_table_privilege ( 'postgres', schemaname||'. '||tablename, 'select' ) AND schemaname NOT IN ( 'pg_catalog','information_schema');


1 Answers

You can create read-only user as -> create a new database user; grant connect on DB; then grant usage on schema and then grant select on tables.

Here is a reference, https://tableplus.com/blog/2018/04/postgresql-how-to-create-read-only-user.html

However allowing read-only to a fully privileged user over a (specific) connection isn't feasible (using built-in features).

like image 159
user27137772 Avatar answered Sep 21 '22 15:09

user27137772