A
A
Alexander2020-11-21 05:25:44
PostgreSQL
Alexander, 2020-11-21 05:25:44

Why are the user rights not granted to work with the database?

Hello, why is it impossible to grant rights to the user, although this method has always worked in my case before.

CREATE DATABASE bot;
CREATE USER botuser WITH PASSWORD 'botpassword';
GRANT ALL PRIVILEGES ON DATABASE bot TO botuser;

\c bot

CREATE TABLE example (id int PRIMARY KEY, name text)

#Дальше через пользователя postgres, делаю коннект к базе командой:
 psql -d bot -U botuser

SELECT * FROM example;

#Выходит ошибка: нет доступа к таблице example

#Но если даю права именно на SELECT то получается под пользователем забирать данные:

GRANT SELECT ON ALL TABLES IN SCHEMA public TO botuser;


What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2020-11-21
@AlexMine

In postgres, permissions are granted to a specific type of object (database, schema, table, sequence, etc.) and depend on this type. In this case, the granted rights to the parent object do not mean the presence of any rights to the child objects.
You gave the user all rights to DATABASE, which means that he can connect to it and create schemas, publications and temporary tables in it. Everything.
You create the example table under a different user, botuser has no rights to it.
https://postgrespro.ru/docs/postgresql/13/ddl-priv

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question