Schema 와 User 명이 다를 때 Default Schema 설정 (search_path)
PostgreSQL 은 User 명과 Schema 명이 동일한 경우, 오브젝트 생성 시 Schema 명을 지정하지 않아도 동일한 Schema 명 안에 오브젝트를 생성한다. 만약 다르다고 하면 기본적으로 public Schema 에 저장된다. 그 이유는 search_path 의 기본 설정이 "$user", public 이므로 자기 자신과 동일한 스키마가 있으면 해당 스키마에 오브젝트를 생성하고 없으면 다음 순위인 public Schema 에 저장되게 된다.
Defualt Schema 변경(searc_path)은 아래의 방법을 참고하기 바란다.
-- User 명 : post_mgr
-- Schema 명 : postschema
-- DB 명 : postdb
-- IP/Port : 10.10.41.22/5432
-- 변경할 User 명으로 DB 접속
$ psql -U post_mgr -d postdb -h 10.10.41.22 -p 5432
-- 현재 search_path 설정 확인
postdb=> show search_path;
search_path
-----------------
"$user", public
(1 row)
-- search_path 기본 설정을 postschema 로 변경
postdb=> alter role post_mgr set search_path = postschema;
-- 세션 종료 및 재접속 (재접속해야 변경된 search_path 가 적용된다.)
postdb=> \q
$ psql -U post_mgr -d postdb -h 10.10.41.22 -p 5432
-- 변경된 search_path 확인
postdb=> show search_path;
search_path
-------------
postschema
(1 row)
-- TEST 테이블 생성하여 Default Schema 명 확인
postdb=> CREATE TABLE TEST (X VARCHAR(10));
postdb=> \dt+
List of relations
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
------------+------+-------+----------+-------------+---------------+---------+-------------
postschema | test | table | post_mgr | permanent | heap | 0 bytes |
(1 row)
postdb=> DROP TABLE TEST;
postdb=> \q
반응형
댓글