Permission denied for relation

2020-01-24 18:22发布

I tried to run simple sql command:

select * from site_adzone;

and I got this error

ERROR:  permission denied for relation site_adzone

What could be the problem here?

I tried also to do select for other tables and got same issue. I also tried to do this:

GRANT ALL PRIVILEGES ON DATABASE jerry to tom;

but I got this response from console

WARNING:  no privileges were granted for "jerry"

Do you have some idea what can be wrong?

10条回答
放荡不羁爱自由
2楼-- · 2020-01-24 19:18

This frequently happens when you create a table as user postgres and then try to access it as an ordinary user. In this case it is best to log in as postgres again and use ALTER TABLE OWNER TO someuser to change the table ownership to the user who will be using the table.

查看更多
Luminary・发光体
3楼-- · 2020-01-24 19:20

I was faced with this problem once. just change the database user to a superuser and your problem is solved.

ALTER USER myuser WITH SUPERUSER;

查看更多
放我归山
4楼-- · 2020-01-24 19:21

Make sure you log into psql as the owner of the tables. to find out who own the tables use \dt

psql -h CONNECTION_STRING DBNAME -U OWNER_OF_THE_TABLES

then you can run the GRANTS

查看更多
冷血范
5楼-- · 2020-01-24 19:21

As you are looking for select permissions, I would suggest you to grant only select rather than all privileges. You can do this by:

GRANT SELECT ON <table> TO <role>;
查看更多
登录 后发表回答