[PostgreSQL] template0, template1 DB의 용도는?


    PostgreSQL는 데이터베이스 생성 시 기본적으로 template1 을 복사하여 생성합니다.
    template1 에 오브젝트 생성하면 이후 create database 시 초기 오브젝트에 포함되어 생성되는 것을 보면 알 수 있습니다.
    template0 은 postgreSQL의 초기 데이터베이스 템플릿입니다.
    
    
    sk1=# \l+
                                                                    List of databases
       Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   |  Size   | Tablespace |            Description             
    -----------+----------+----------+-------------+-------------+-----------------------+---------+------------+------------------------------------
     sk1       | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 42 MB   | pg_default | 
     sk2       | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |                       | 8801 kB | pg_default | 
     template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +| 8617 kB | pg_default | unmodifiable empty database
               |          |          |             |             | postgres=CTc/postgres |         |            | 
     template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +| 8769 kB | pg_default | default template for new databases
               |          |          |             |             | postgres=CTc/postgres |         |            | 
    (4 rows)
    
    

    DB 생성 시 template1 대신 template0을 지정할 수 있는데 template0을 복사하는 경우에는 새 인코딩 및 로케일(locale) 설정을 지정할 수 있습니다.
    template1은 초기 생성(initdb) 시 지정한 인코딩 및 로케일(locale)에 관한 데이터를 포함하지만 template0은 그렇지 않습니다.
    CREATE DATABASE sk2 WITH template=template0 ENCODING = 'UTF8' locale='C';


    댓글