【发布时间】:2017-07-21 19:45:58
【问题描述】:
我已经尝试了几乎所有方法来获取 postgres 中某些关系的用户权限。这是我尝试过的:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO myuser;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO myuser;
ALTER DEFAULT PRIVILEGES GRANT ALL ON TABLES TO myuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO myuser;
我已将我的 pg_hba.cnf 更改为:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 ident
#host replication postgres ::1/128 ident
如果你正确地摆弄这些命令,我确信这些命令会有所作为,但为什么这些命令中的任何一个都不做任何接近他们所说的事情呢?
我正在使用python:
>>> conn = psycopg2.connect(host="localhost", port="5432", dbname="mydb",user="myuser", password="mypassword")
>>> cur = conn.cursor()
>>> cur.execute('select count(*) from mytable')
这是我得到的错误:
>>> cur.execute('select count(*) from public.mytable')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
psycopg2.ProgrammingError: permission denied for relation mytable
我也试过了:
ALTER DATABASE mydb OWNER TO myuser;
当然还有重启。
【问题讨论】:
-
在出现错误之前执行了什么命令?
-
架构中的表是否为
public?当您连接psql时,您可以作为用户myuser访问它吗? -
显而易见:
mytable在架构中是公开的吗?或者它可能在 search_path 上的不同模式中? -
它可能不在公共架构中。我怎么把它弄进去?当我执行
\l时,它是我从shell postgres 默认用户创建的数据库,我已经使用sudo su postgresql进入...也不确定psql 中架构和数据库之间的区别... -
其实我的表是
public.mytable所以我相信它在公共模式中。
标签: postgresql