[英]Postgres permission denied for relation <table>
I'm trying to learn Postgres and Ive made two basic tables and I can't join them together. 我正在努力学习Postgres,我已经制作了两个基本表格,我不能将它们加在一起。
here is my list Of relations: 这是我的关系列表:
Schema | Name | Type | Owner
--------+--------------+----------+----------
public | login | table | postgres
public | login_id_seq | sequence | postgres
public | users | table | test
(3 rows)
When I use the command 当我使用命令
SELECT * FROM users JOIN login ON users.name = login.name;
I get 我明白了
ERROR: permission denied for relation login
错误:关系登录的权限被拒绝
I have no idea what to do or what I did wrong. 我不知道该做什么或做错了什么。
You should grant the SELECT
permission to user test : 您应该向用户测试授予
SELECT
权限:
GRANT SELECT ON login TO test;
If if might allow test to modify login
, you should grant other permissions as well: 如果if可能允许测试修改
login
,您还应该授予其他权限:
GRANT SELECT, INSERT, UPDATE, DELETE ON login TO test;
You should execute these statements as database owner or as user postgres . 您应该将这些语句作为数据库所有者或用户postgres执行 。 In general, you can use
一般来说,你可以使用
psql -Upostgres -dtest
if you're running this command on the same machine where the Postgres server is running. 如果您在运行Postgres服务器的同一台机器上运行此命令。
You may also change the ownership of login
to test : 您还可以将
login
的所有权更改为test :
ALTER TABLE login OWNER TO test;
ALTER SEQUENCE login_id_seq OWNER TO test;
But have to execute this as user postgres as well. 但必须以用户postgres的形式执行此操作。
Edit : You can try to change the user with 编辑 :您可以尝试更改用户
SET ROLE 'postgres';
as suggested by @lat long . 正如@lat long所建议的那样 。
So this is what I did to finally get it to work...I basically just went into the login properties on pgAdmin4, found the owner and switched it to test and ran: SELECT * FROM users JOIN login ON users.name = login.name;
所以这就是我最终让它发挥作用...我基本上只是进入了pgAdmin4的登录属性,找到了所有者并将其切换为测试并运行:
SELECT * FROM users JOIN login ON users.name = login.name;
and finally got what I was looking for. 终于得到了我想要的东西。 Surprisingly a simple fix.
令人惊讶的简单修复。
The "test" user doesn't have permission to login and use the related tables. “test”用户无权登录和使用相关表。 Run the query with the "postgres" user:
使用“postgres”用户运行查询:
SET ROLE 'postgres';
Then run your query. 然后运行您的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.