Redshift : has_table_privilege (특정 user의 table 권한 보유 여부 파악하기)
Syntax
has_table_privilege(user_name, table_name, privilege)
has_table_privilege() function은
user_name이 table_name에 대해 privilege에 대한 권한을 가지고 체크합니다.
권한을 가지고 있다면 true를 return하고
권한이 없다면 false를 return합니다.
select has_table_privilege('test_user', 'test_schema.test_table', 'select') as priv_yn
;
-- Result
priv_yn
true
위처럼 사용할 수 있습니다.
test_user가
test_schema.test_table에 대해
select 권한이 있는지를 체크합니다.
만약 권한이 있다면 true를 return하고
권한이 없다면 false를 return합니다.
select has_table_privilege('test_user', 'test_schema.test_table', 'select')
, has_table_privilege('test_user', 'test_schema.test_table', 'delete')
, has_table_privilege('test_user', 'test_schema.test_table', 'drop')
, has_table_privilege('test_user', 'test_schema.test_table', 'insert')
, has_table_privilege('test_user', 'test_schema.test_table', 'update')
;
select 뿐 아니라 다양한 table에 변경을 줄 수 있는 권한들에 대한 보유 여부를 알아볼 수 있습니다.
select t.*
, t.schemaname + '.' + t.tablename as full_tablename
, has_table_privilege('test_user', full_tablename, 'select')
from pg_tables as t
;
응용하면 위와 같은 방식으로 pg_tables를 이용하여 database에 존재하는 모든 테이블에 대해 특정 유저가 권한을 가지고 있는지 아닌지도 볼 수 있습니다.
https://cosmosproject.tistory.com/763
Redshift : pg_tables (table 종류, owner 종류 추출)
select *from pg_tables; Redshift에서는 pg_table를 이용하면 database에 있는 table의 종류와 각 tabe의 owner를 알 수 있습니다. 위 쿼리의 output column은 아래 링크를 보면 됩니다.https://www.postgresql.org/docs/8.0/view-
cosmosproject.tistory.com
FYI
https://docs.aws.amazon.com/ko_kr/redshift/latest/dg/r_HAS_TABLE_PRIVILEGE.html
HAS_TABLE_PRIVILEGE - Amazon Redshift
CURRENT_SCHEMA는 리더 노드 함수이기 때문에 사용자 생성 테이블, STL 또는 STV 시스템 테이블, SVV 또는 SVL 시스템 뷰를 참조하는 경우에는 오류를 반환합니다. 권한에 대한 자세한 내용은 GRANT 섹션을
docs.aws.amazon.com