0

I have Azure postgresql single server database which I need to give read permission to a newly created user.

CREATE USER "test@hostName" PASSWORD 'XXXX'; GRANT CONNECT ON DATABASE "test" TO "test@hostName";

ALTER DEFAULT PRIVILEGES FOR USER pgadmin IN SCHEMA public GRANT SELECT ON TABLES TO "test@hostName" ;

SELECT * FROM information_schema.role_table_grants WHERE grantee = 'test@hostName';

This is the result enter image description here

But when this user executes a select query Permission Denied message appear and not allowed to select. Any help is appreciated.

enter image description here

SOUser
  • 31
  • 3
  • Default privileges work on new tables created after this statement, not the current tables. You have to grant select to all tables as well – Frank Heikens Jun 20 '23 at 03:51

1 Answers1

1

To assign permission to newly created user in Azure PostgreSQL follow below procedure:

  • First create a new database and a user in azure Postgres SQL and assign connect permission to it on newly created database.
--create a new database.
CREATE DATABASE newdb;
--create a new user.
CREATE USER newuser PASSWORD '<StrongPassword!>';
--grant new user to connect databse.
GRANT CONNECT ON DATABASE newdb TO newuser;
  • Then go to new database with current login and grant select to all tables on public schema to the new user with following command.
--to switch the database with current login
\c test
--Grant select on table with ath following schema
GRANT SELECT ON ALL TABLES IN SCHEMA schemaname TO newuser;

enter image description here

  • After this login with that user in Postgres SQL and select the table
select * from tablename;

enter image description here

Pratik Lad
  • 4,343
  • 2
  • 3
  • 11
  • Thanks for the answer. I could get the access. after granting the access, I create a view. but the user cannot read the view. The view is created after adding read permission to the user. I did ALTER DEFAULT PRIVILEGES FOR USER pgadmin IN SCHEMA public GRANT SELECT ON ALL TABLES IN SCHEMA public TO readuser; – SOUser Jun 26 '23 at 02:51
  • Any idea how to do that? – SOUser Jun 26 '23 at 02:53