1

We have a PostgreSQL database 'db1', which is having around 500 schemas. I am trying to create a read-only user for this particular PostgreSQL database.

I could find the following command for creating a user and granting permission schema wise

GRANT SELECT ON ALL TABLES IN SCHEMA schema_name TO readonly_user;

but

1) We have around 500 schemas, so granting permission to each schema is difficult.

2) These schemas will be dynamically created or dropped on a daily basis, so giving permission at each time a schema is created is also a difficult task.

Is there any way to give the read-only permission for a whole database instead of schema?

In MySQL, I can do it using the following command

grant select on *.* to 'user_name'@'IP';

I am looking for a similar command in PostgreSQL

We are using PostgreSQL 10.

asked Sep 3, 2019 at 8:51
1
  • Please don't write the same question on several stackexchange sites at once. Commented Sep 3, 2019 at 15:20

1 Answer 1

3

We have around 500 schemas, so granting permission to each schema is difficult.

No. It's tedious to do by hand, but it's also a prime candidate for automation, through scripting.

... dynamically created or dropped on a daily basis, so giving permission at each time a schema is created is also a difficult task.

I disagree. You're doing all the "difficult" stuff every day - dropping, recreating and repopulating all these schemas. I would suggest that adding this single statement to the end of that process is relatively trivial!

Is there any way to give the read-only permission for a whole database instead of schema?

Even if there is, you should not do so.

It sounds to me like these schemas are discrete entities (otherwise why not combine them into one?). Granting access across all of them strikes me as a Bad Idea.

answered Sep 3, 2019 at 11:22
3
  • Hi Phill, thank you for the response. Our requirement is, some internal users need read-only access to all these schemas, also we can't combine these schemas to a single schema for some reason. We have a similar structure in MySQL and I could fulfil my team's requirement using a single command that I mentioned above, but I failed to find such command in PostgreSQL. Commented Sep 3, 2019 at 12:05
  • I already thought of automation through scripting and adding the above single statement in the code while dropping and recreating schema as you mentioned, but all these things will be a waste if I could find a single command, that's why I need help to find out this command if it is there. Commented Sep 3, 2019 at 12:05
  • @jithingiri there is no command that would do what you need. The best you can do is what Phill suggests. Commented Sep 3, 2019 at 16:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.