错误:使用 Postgres 拒绝序列 city_id_seq 的权限 [英] ERROR: permission denied for sequence cities_id_seq using Postgres

查看:40
本文介绍了错误:使用 Postgres 拒绝序列 city_id_seq 的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new at postgres (and at database info systems all in all). I ran following sql script on my database:

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 试图:

When, as the user www, trying to:

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

我收到以下错误:

ERROR: permission denied for sequence cities_id_seq

我知道问题出在串行类型上.这就是为什么我将 *_id_seq 的选择、插入和删除权限授予 www.但这并不能解决我的问题.我错过了什么?

I get that the problem lies with the serial type. That's why I grant select, insert and delete rights for the *_id_seq to www. Yet this does not fix my problem. What am I missing?

推荐答案

自 PostgreSQL 8.2 起你必须使用:

Since PostgreSQL 8.2 you have to use:

GRANT USAGE, SELECT ON SEQUENCE cities_id_seq TO www;

GRANT USAGE - 对于序列,此权限允许使用 currval 和 nextval 函数.

GRANT USAGE - For sequences, this privilege allows the use of the currval and nextval functions.

正如@epic_fil 在评论中指出的,您可以通过以下方式授予对架构中所有序列的权限:

Also as pointed out by @epic_fil in the comments you can grant permissions to all the sequences in the schema with:

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

注意:在执行权限授予命令之前不要忘记选择数据库(c )

Note: Don't forget to choose the database (c <database_name>) before executing the privilege grant commands

这篇关于错误:使用 Postgres 拒绝序列 city_id_seq 的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆