IT story

오류 : Postgres를 사용하여 city_id_seq 시퀀스에 대한 권한이 거부되었습니다.

hot-time 2020. 5. 25. 08:09
반응형

오류 : Postgres를 사용하여 city_id_seq 시퀀스에 대한 권한이 거부되었습니다.


나는 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에 대한 선택, 삽입 및 삭제 권한을 www에 부여합니다. 그러나 이것은 내 문제를 해결하지 못합니다. 내가 무엇을 놓치고 있습니까?


PostgreSQL 8.2부터 다음을 사용해야합니다.

GRANT USAGE, SELECT ON SEQUENCE cities_id_seq TO www;

GRANT USAGE-시퀀스의 경우이 권한으로 currval 및 nextval 함수를 사용할 수 있습니다.

주석에서 @epic_fil이 지적한 것처럼 다음을 사용하여 스키마의 모든 시퀀스에 권한을 부여 할 수 있습니다.

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

@Phil은 눈에 띄지 않을만한 많은 공감을 얻는 의견을 가지고 있기 때문에 그의 구문을 사용하여 스키마의 모든 시퀀스에 대해 사용자에게 권한을 부여하는 답변을 추가하고 있습니다 (스키마가 기본 '공개'라고 가정) )

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

@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+에서만 작동합니다.

이것은 기존의 기본 권한을 덮어 쓰지 않고 추가 할 것이기 때문에 매우 안전합니다.


postgres에서 다음 명령을 실행하십시오.

postgres에 로그인 :

sudo su postgres;

psql dbname;

CREATE SEQUENCE public.cities_id_seq INCREMENT 1
MINVALUE 0
MAXVALUE 1
START 1 CACHE 1; ALTER TABLE public.cities_id_seq OWNER TO pgowner;

pgowner will be your database user.

참고URL : https://stackoverflow.com/questions/9325017/error-permission-denied-for-sequence-cities-id-seq-using-postgres

반응형