postgresql 关系 <table> 的 Postgres 权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49313595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgres permission denied for relation <table>
提问by Joe Escobedo
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.
我不知道该怎么做或我做错了什么。
采纳答案by Joe Escobedo
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;
and finally got what I was looking for. Surprisingly a simple fix.
所以这就是我为最终让它工作所做的一切......我基本上只是进入了 pgAdmin4 上的登录属性,找到了所有者并将其切换到 test 并运行:
SELECT * FROM users JOIN login ON users.name = login.name;
最后得到了我正在寻找的东西。令人惊讶的是一个简单的修复。
回答by clemens
You should grant the SELECT
permission to user test:
您应该授予SELECT
用户test权限:
GRANT SELECT ON login TO test;
If if might allow testto modify login
, you should grant other permissions as well:
如果可能允许test修改login
,您还应该授予其他权限:
GRANT SELECT, INSERT, UPDATE, DELETE ON login TO test;
You should execute these statements as database owner or as user postgres. In general, you can use
您应该以数据库所有者或用户postgres 的身份执行这些语句。一般来说,你可以使用
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
to test的所有权:
ALTER TABLE login OWNER TO test;
ALTER SEQUENCE login_id_seq OWNER TO test;
But have to execute this as user postgresas well.
但是也必须以用户postgres 的身份执行它。
Edit: You can try to change the user with
编辑:您可以尝试更改用户
SET ROLE 'postgres';
as suggested by @lat long.
正如@lat long所建议的那样。
回答by lat long
The "test" user doesn't have permission to login and use the related tables. Run the query with the "postgres" user:
“test”用户无权登录和使用相关表。使用“postgres”用户运行查询:
SET ROLE 'postgres';
Then run your query.
然后运行您的查询。