首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >错误:使用Postgres的sequence cities_id_seq权限被拒绝

错误:使用Postgres的sequence cities_id_seq权限被拒绝
EN

Stack Overflow用户
提问于 2012-02-17 16:24:32
回答 3查看 202.9K关注 0票数 260

我是postgres的新手(以及所有数据库信息系统的新手)。我在我的数据库上运行了以下sql脚本:

create table cities (
id serial primary key,
name text not null
);

create table reports (
id serial primary key,
cityid integer not null references cities(id),
reportdate date not null,
reporttext text not null
);

create user www with password 'www';

grant select on cities to www;
grant insert on cities to www;
grant delete on cities to www;

grant select on reports to www;
grant insert on reports to www;
grant delete on reports to www;

grant select on cities_id_seq to www;
grant insert on cities_id_seq to www;
grant delete on cities_id_seq to www;

grant select on reports_id_seq to www;
grant insert on reports_id_seq to www;
grant delete on reports_id_seq to www;

当用户www尝试执行以下操作时:

insert into cities (name) values ('London');

我得到以下错误:

ERROR: permission denied for sequence cities_id_seq

我知道问题出在序列类型上。这就是为什么我将*_id_seq的select、insert和delete权限授予www。然而,这并没有解决我的问题。我遗漏了什么?

EN

回答 3

Stack Overflow用户

发布于 2015-03-25 05:04:23

由于@Phil有一条评论获得了很多好评,但可能没有人注意到,我正在使用他的语法添加一个答案,该答案将授予用户对模式中所有序列的权限(假设您的模式是默认的“public”)。

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public to www;
票数 77
EN

Stack Overflow用户

发布于 2016-06-07 17:27:04

@Tom_Gerken、@epic_fil和@kupson的声明非常正确,它们提供了使用现有序列的权限。但是,用户将无法获得对将来创建的序列的访问权限。为此,您必须将GRANT语句与ALTER DEFAULT PRIVILEGES语句组合在一起,如下所示:

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO www;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
    GRANT USAGE, SELECT ON SEQUENCES TO www;

当然,这只适用于PostgreSQL 9+。

这将附加到现有的默认权限,而不是覆盖它们,因此在这方面是非常安全的。

票数 52
EN

Stack Overflow用户

发布于 2021-05-03 16:08:20

这是由于序列的权限问题造成的。

尝试使用以下命令来解决此问题,

GRANT USAGE, SELECT ON SEQUENCE sequence_name TO user_name;

例如:

GRANT USAGE, SELECT ON SEQUENCE cities_id_seq TO www;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9325017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档