简体   繁体   English

关系<table>的Postgres权限被拒绝

[英]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.

相关问题 postgres数据库:权限不足,关系表的权限被拒绝 - postgres database : Insufficient privilege, permission denied for relation table PostgreSQL 9.6 数据库上的关系权限被拒绝 - Permission denied for relation on PostgreSQL 9.6 database PGError:错误:关系被拒绝(使用Heroku时) - PGError: ERROR: permission denied for relation (when using Heroku) ActiveRecord::StatementInvalid (PG::InsufficientPrivilege: ERROR: permission denied for relationship - ActiveRecord::StatementInvalid (PG::InsufficientPrivilege: ERROR: permission denied for relation psycopg2.errors.InsufficientPrivilege:关系 django_migrations 的权限被拒绝 - psycopg2.errors.InsufficientPrivilege: permission denied for relation django_migrations 基于Rails关系导出Postgres表 - Export postgres table based on rails relation 错误:Heroku pg_dump之后导入到开发数据库后,该关系的权限被拒绝 - ERROR: permission denied for relation after Heroku pg_dump and import to development database 对对象“表”,数据库“ db”,模式“ dbo”的SELECT权限被拒绝。 - The SELECT permission was denied on the object 'table', database 'db', schema 'dbo'. 无法使用Postgres创建空数据库-更改目录时权限被拒绝 - Can't create empty database with postgres — permission denied when changing directory 火鸟:权限被拒绝? - Firebird: Permission Denied?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM