I have a postgres database in Google Cloud SQL which was created by the user "api". Now I would like to read some of the data on that database using my own user. I can connect to the database but when I run
SELECT * FROM data;
I get the error:
ERROR: permission denied for table data
EDIT
I tried GRANT ALL PRIVILEGES ON DATABASE website TO sev;
but that didn't work. The SQL defining the databse looks like this:
CREATE DATABASE website
WITH
OWNER = cloudsqlsuperuser
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.UTF8'
LC_CTYPE = 'en_US.UTF8'
TABLESPACE = pg_default
CONNECTION LIMIT = -1;
GRANT ALL ON DATABASE website TO cloudsqlsuperuser;
GRANT TEMPORARY, CONNECT ON DATABASE website TO PUBLIC;
GRANT ALL ON DATABASE website TO sev;
CodePudding user response:
The GRANT
must be run by the owning user api
.
Granting privileges on the database is not enough. To access a table, you must have privileges on the table itself as well as privileges on the schema that contains the table.