-
PostgreSQL Schema & Objects카테고리 없음 2019. 11. 22. 15:18
Schema는 Objects의 논리적인 집합으로 PostgreSQL은 여러 개의 Schemas로 구성되어 있다.
Schema는 table, view, sequence, function등의 Objects로 구성되어 있다.
- Schema를 사용하는 이유
- 여러 사용자가 서로 간섭하지 않고 하나의 데이터베이스를 사용할 수 있게 한다.
- 데이터베이스 개체를 논리적 그룹으로 구성하여 관리하기 쉽게 만든다.
- 타사 응용 프로그램을 별도의 Schema에 넣을 수 있으므로 다른 개체의 이름과 충돌하지 않는다.
PostgreSQL은 여러 데이터베이스를 생성할 수 있으며, 각 데이터베이스는 하나 이상의 schema를 가진다.
PostgreSQL은 기본 스키마 ‘public’과 특수 스키마인 ‘pg_catalog’가 있다. 'pg_catalog' 에는 모든 시스템 테이블, 데이터 유형, 함수 및 연사자의 정보를 가지고 있다.
- schema 조회
agens=# \dn agens=# select oid, * from pg_namespace;
- Schema information 조회
PostgreSQL은 schema의 정보를 담고 있는 information schema view가 있다.
schema의 소유자는 database cluster가 생성될 때의 소유자와 동일하다.
information schema에 정의 된 특수 데이터 형식을 사용하며, information schema의 모든 column은 다섯 가지 유형 중 하나를 가진다.
- Data Type
Data Type Description cardinal_number A nonnegative integer character_data A character string (without specific maximum length) sql_identifier A character string. This type is used for SQL identifiers, the type character_data is used for any other kind of text data time_stamp A domain over the type timestamp with time zone yes_or_no A character string domain that contains either YES or NO. This is used to represent Boolean (true/false) data in the information schema -
- information_schema list 조회
SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema = 'information_schema';
- Schema를 사용하는 이유