본문으로 바로가기



DB 를 하다보면 

프로젝트 및 DB 운영을 하다 보면,

특정 사용자에게 특정 권한을 주어야 할일이 생기게 된다. 


그러한 사용자에게 DBA 권한 혹은 sys 권한을 줄수는 없는 일이기에, 

특정 권한만 부여 하여 사용하게 하는 것이다. 


그럼 먼저 권한을 부여하고 조회하는 방법 부터 확인해보자. 



SQL> grant create any index, alter any index, drop any index to scott;


scott 사용자에게 권한을 주는 구문 이다. 


create any index : 인덱스 생성 권한

 alter any index : 인덱스 변경 권한

drop any index : 인덱스 삭제 권한


 의 권한을 scott 에게 준다. 


SQL> select * from dba sys privs where grantee='SCOTT';

SCOTT 사용자에게 권한이 재대로 들어 갔는지 확인


SQL> grant create table, alter any table, drop any table, select any table, update any table, delete any table to scott;


scott 사용자에게 권한 추가 설정


Create table : 테이블 생성 및 무결성 제약 조건 포함한 인덱스 생성

Alter any table : 테이블 변경 권한

Drop any table : 테이블 삭제 권한

Select any table : 테이블,,스냅샷의 질의 권한

Update any table : 테이블, 행의 갱신 권한

Delete any table : 테이블, 행을 삭제할 수 있는 권한 


SQL> select * from dba_sys_privs where grantee='SCOTT';

SCOTT 사용자의 권한 확인 


이외에도 개별 적인 권한을 설정 해줄수 있다. 



Create session : 데이터베이스 접속 권한

Alter session : 현제 세션의 환경의 변경 권한

restricted session : 데이터베이스 시작시 restrict 모드로 접속

Create tablespace : 테이블 스페이스 생성 권한

Alter tablespace : 테이블 스페이스 변경 권한

Drop tablespace : 테이블 스페이스 삭제 권한

unlimited tablespacle : 테이블 스페이스 무제한 사용 



위와 같이 많은 기능들이 세분화가 되어 있는데, 

이러한 권한들을 일일이 그때그때 마다 주기는 힘든 일이다. 

그러한 이유로 role 이라는 기능이 있으며,

role 권한부여 기능은 다음과 같다. 


SQL> create role r_test; // role 생성 role 명은 r_test 


SQL> grant create any index, drop any index, alter any index to r_test; 

create any index, drop any index, alter any index 권한을 r_test role 에 부여 


SQL> grant r_test to scott; 

r_test 이름을 가진 role 를 scott 에 부여 


SQL> select * from ( select grantee, granted_role from dba_role_priva)a,(select privilege, role from role_sys_privs)b

where a.granted_role=b.role and grantee='scott';


r_test 의 role 을 가지고 있는 유저 및 

그 유저가 가지고 있는 권한 을 확인 


위와 같이 권한을 부여 하였으나. 데이터가 입력이 안되는 경우가 있다. 

ora-01950 의 error 를 내뱉으면서 말이다.



그 경우에도 권한이 없어 발생 하는 문제이다. 


주어야 하는 권한은 다음과 같다. 


SQL> grant unlimited tablespace scott;

 

scott 사용자에게 unlimited tablespace 권한을 부여해 주는 것이다. 

테이블에 데이터를 입력해야 하는 사용자에게는 


Alter any table , alter tablespace, unlimited tablespace 


위 3가지 권한을 필수 적으로 권하부여 를 해주어야 데이터 입력이 가능하다.