[PostgreSQL] 처음부터 시작하기: (9) 데이터베이스를 운영하기 위한 PostgreSQL-SQL 명령문

데이터베이스 인스턴스 및 데이터베이스

Oracle의 데이터베이스 인스턴스와 데이터베이스 간에는 일대일 관계가 있습니다.

하나의 데이터베이스 인스턴스는 PostgreSQL 및 MySQL의 여러 데이터베이스에 해당합니다.

데이터베이스 관련 작업

데이터베이스 생성

주문하다
CREATE DATABASE name
    [ WITH ] [ OWNER [=] user_name ]
           [ TEMPLATE [=] template ]
           [ ENCODING [=] encoding ]
           [ STRATEGY [=] strategy ] ]
           [ LOCALE [=] locale ]
           [ LC_COLLATE [=] lc_collate ]
           [ LC_CTYPE [=] lc_ctype ]
           [ ICU_LOCALE [=] icu_locale ]
           [ ICU_RULES [=] icu_rules ]
           [ LOCALE_PROVIDER [=] locale_provider ]
           [ COLLATION_VERSION = collation_version ]
           [ TABLESPACE [=] tablespace_name ]
           [ ALLOW_CONNECTIONS [=] allowconn ]
           [ CONNECTION LIMIT [=] connlimit ]
           [ IS_TEMPLATE [=] istemplate ]
           [ OID [=] oid ]
 매개변수
매개변수 중국어 설명
소유자 생성된 데이터베이스에 데이터베이스의 소유자가 될 역할을 할당합니다. OWNER 옵션을 생략하면 CREATE DATABASE 실행 시 데이터베이스의 소유자가 역할이 됩니다.
주형 기본적으로 PostgreSQL은 template을 사용하여 새 데이터베이스를 생성할 템플릿 데이터베이스를 지정합니다. 템플릿 데이터베이스를 명시적으로 지정하지 않으면 기본 데이터베이스가 템플릿 데이터베이스로 사용됩니다. defaulttempate1
부호화  새 데이터베이스의 문자 집합 인코딩을 결정합니다. 기본 언어는 시스템 언어와 동일합니다.
현지의  새 데이터베이스의 기본 조합 순서와 문자 분류를 설정합니다. 데이터 정렬은 문자열에 적용되는 정렬 순서(예: BY 순서를 사용하는 쿼리 및 텍스트 열의 인덱스에 사용되는 순서)에 영향을 줍니다. 문자 분류는 낮음, 높음, 숫자 등 문자 분류에 영향을 줍니다. 또한 운영 체제 환경 LC_COLLATE 및 LC_CTYPE의 관련 측면을 설정합니다. 기본 설정은 템플릿 데이터베이스의 설정과 동일합니다.
LC_COLLATE 새 데이터베이스가 사용할 데이터 정렬 순서(LC_COLLATE)를 지정합니다. 이 매개변수는 템플릿 데이터베이스를 포함하는 문자열 쿼리의 정렬 순서에 영향을 줍니다Order By.
LC_CTYPE 새 데이터베이스가 사용할 문자 분류를 지정합니다. 대문자, 소문자, 숫자 등의 문자 분류에 영향을 미치며, 기본적으로 템플릿 데이터베이스의LC_CTYPE
테이블스페이스 새 데이터베이스 TABLESPACE의 이름을 지정합니다. 기본값은 템플릿 데이터베이스의 테이블스페이스입니다. 기본 테이블스페이스 pg_default
연결 제한 새 데이터베이스에 대한 최대 동시 연결 수를 지정합니다. 기본값은 -1이며 제한이 없습니다. 이 매개변수는 특정 데이터베이스에 대한 최대 동시 연결을 구성할 수 있는 공유 호스팅 환경에서 매우 유용합니다.
ALLOW_CONNECTIONS 매개변수allow_connections의 데이터 유형은 부울입니다. false인 경우 데이터베이스에 연결할 수 없습니다.
IS_TEMPLATE IS_TEMPLATE이 true이면 모든 캐릭터CREATE DATABASE가 이를 복제할 수 있습니다. false인 경우 슈퍼유저나 데이터베이스 소유자만 복제할 수 있습니다.
ICU_로케일 이 데이터베이스에 대한 ICU 데이터 정렬입니다. 초기화 중에 ICU가 지정된 경우 이 필드에는 해당 규칙이 표시됩니다. ICU는 정교한 대조 및 텍스트 처리 기능을 포함하여 강력한 지역화 지원을 제공하는 라이브러리입니다.
ICU_RULES 이 데이터베이스의 기본 데이터 정렬 동작을 사용자 정의하려면 추가 데이터 정렬을 지정하세요.
LOCALE_PROVIDER 이 데이터베이스의 기본 데이터 정렬에 사용되는 공급자를 지정합니다. 가능한 값은 icu(서버가 ICU 지원으로 구축된 경우) 또는 libc입니다. 기본적으로 공급자는 템플릿의 공급자와 동일합니다.
COLLATION_VERSION 데이터베이스와 함께 저장된 데이터 정렬 버전 문자열을 지정합니다. 일반적으로 이는 생략되어야 하며, 그러면 운영 체제에서 제공하는 데이터베이스 데이터 정렬의 실제 버전을 기반으로 버전이 계산됩니다. 이 옵션은 pg_upgrade가 기존 설치에서 버전을 복사하는 데 사용됩니다.
1. ci_database_test01 생성
postgres=# create database ci_database_test01;
CREATE DATABASE
postgres=# \l
                                                            List of databases
        Name        |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |          |          |                 |             |             |            |           | postgres=CTc/postgres
(5 rows)

postgres=# 

생성된 데이터베이스 ci_database_test01에는 소유자 postgres가 있고 문자 집합은 UTF8이며 데이터 정렬 및 언어 기호와 분류는 zh_CN.UTF-8입니다.

2. ci_database_test02를 생성하고 문자 집합을 EUC_TW로 지정합니다.
postgres=# create database ci_database_test02 WITH ENCODING 'EUC_TW' LC_CTYPE="C" LC_COLLATE="C" TEMPLATE=template0;
CREATE DATABASE
postgres=# \l
                                                            List of databases
        Name        |  Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres | EUC_TW   | libc            | C           | C           |            |           | 
 circledba_test     | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |          |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |          |          |                 |             |             |            |           | postgres=CTc/postgres
(6 rows)

postgres=# 

파생된 질문:

(1) LC_CTYPE과 LC_COLLATE가 C로 설정된 이유는 무엇입니까?

답변: 현지화된 모든 설정을 제거하려면 C로 설정하세요.

(2).왜 TEMPLATE=template0을 설정해야 하나요?

답변: template1 템플릿 라이브러리를 사용하여 라이브러리를 구축할 때 새 인코딩과 로케일을 지정할 수 없지만 template0은 지정할 수 있습니다.

(3).template1과 template0의 차이점은 무엇입니까?

답변: 1.template1은 연결하여 개체를 생성할 수 있지만 template0은 연결할 수 없습니다.

postgres=# \c template1
You are now connected to database "template1" as user "postgres".
template1=# create table tmp_1( id int4);
CREATE TABLE
template1=# \c template0
FATAL: database "template0" is not currently accepting connections
Previous connection kept

template1은 객체를 생성할 수 있으며 non-clean 데이터베이스라고 하며 template0은 clean 데이터베이스라고 합니다.

(4).필요에 따라 자신의 코딩 방식에 맞는 데이터베이스를 생성합니다.

그런 다음 /etc/profile 파일에 다음을 추가합니다.

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8

다시 실행

CREATE DATABASE ci_database_test03
WITH
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.utf8'
LC_CTYPE = 'en_US.utf8'
TABLESPACE = pg_default
template = template0
CONNECTION LIMIT = -1;
3. 소유자가 Circledba 사용자인 ci_database_test04 데이터베이스를 생성합니다.
postgres=# create user circledba with password '12345678ab';
CREATE ROLE
postgres=# create database ci_database_test03 WITH OWNER 'circledba';
CREATE DATABASE
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(7 rows)

postgres=# 
4. pg_circle 테이블스페이스를 사용하여 ci_database_test05 데이터베이스를 생성합니다.
mkdir -p /data/16.1/tablespace/dba_circle
chown -R postgres:postgres /data/16.1/tablespace/dba_circle
chmod -R 700 /data/16.1/tablespace/dba_circle
postgres=# create tablespace dba_circle location '/data/16.1/tablespace/dba_circle';
CREATE TABLESPACE
postgres=# create database ci_database_test05 WITH TABLESPACE 'dba_circle';
CREATE DATABASE
postgres=# \l+
                                                                                              List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   |  Size   | Tablespace |                Description                 
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------+---------+------------+--------------------------------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7561 kB | pg_default | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           |                       | 7481 kB | pg_default | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7561 kB | pg_default | 
 ci_database_test05 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7561 kB | dba_circle | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7724 kB | pg_default | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7636 kB | pg_default | default administrative connection database
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +| 7481 kB | pg_default | unmodifiable empty database
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres |         |            | 
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +| 7716 kB | pg_default | default template for new databases
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres |         |            | 
(8 rows)

postgres=# 
 

데이터베이스 수정

주문하다:
Command:     ALTER DATABASE
Description: change a database
Syntax:
ALTER DATABASE name [ [ WITH ] option [ ... ] ]

where option can be:

    ALLOW_CONNECTIONS allowconn
    CONNECTION LIMIT connlimit
    IS_TEMPLATE istemplate

ALTER DATABASE name RENAME TO new_name

ALTER DATABASE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }

ALTER DATABASE name SET TABLESPACE new_tablespace

ALTER DATABASE name REFRESH COLLATION VERSION

ALTER DATABASE name SET configuration_parameter { TO | = } { value | DEFAULT }
ALTER DATABASE name SET configuration_parameter FROM CURRENT
ALTER DATABASE name RESET configuration_parameter
ALTER DATABASE name RESET ALL

URL: https://www.postgresql.org/docs/16/sql-alterdatabase.html
1. 데이터베이스 이름 수정
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test05 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test06 | circledba | EUC_TW   | libc            | C           | C           |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(9 rows)

postgres=# alter database ci_database_test06 rename to ci_database_test04;
ALTER DATABASE
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test04 | circledba | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test05 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(9 rows)

postgres=# 
2. 데이터베이스를 소유한 사용자를 수정합니다.
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test04 | circledba | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test05 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(9 rows)

postgres=# alter database ci_database_test05 owner to circledba;
ALTER DATABASE
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test04 | circledba | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test05 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(9 rows)

postgres=# 

데이터베이스 삭제

주문하다
DROP DATABASE [ IF EXISTS ] name [ [ WITH ] ( option [, ...] ) ]

where option can be:

    FORCE

URL: https://www.postgresql.org/docs/16/sql-dropdatabase.html
1. ci_database_test05 데이터베이스 삭제
postgres=# DROP DATABASE ci_database_test05;
DROP DATABASE
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test04 | circledba | EUC_TW   | libc            | C           | C           |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(8 rows)

postgres=# 
2. ci_database_test04 데이터베이스를 강제 삭제합니다.

강제 삭제란 프로세스에 의해 데이터가 연결되어 있는 경우 일반적인 삭제로는 데이터를 삭제할 수 없으므로 FORCE 명령을 추가해야 합니다.

FORCE 명령: 현재 사용자에게 다른 연결을 종료할 수 있는 권한이 없으면 이 작업이 실패합니다. 필수 권한은 pg_terminate_backend 와 동일합니다.

postgres=# DROP DATABASE ci_database_test04 WITH (FORCE);
DROP DATABASE
postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(7 rows)

postgres=# 

데이터베이스 보기

\l명령

postgres=# \l
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(7 rows)

postgres=#

\l+ 명령

postgres=# \l+
                                                                                              List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   |  Size   | Tablespace |                Description                 
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------+---------+------------+--------------------------------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7561 kB | pg_default | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           |                       | 7481 kB | pg_default | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7561 kB | pg_default | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7724 kB | pg_default | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           |                       | 7636 kB | pg_default | default administrative connection database
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +| 7481 kB | pg_default | unmodifiable empty database
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres |         |            | 
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +| 7716 kB | pg_default | default template for new databases
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres |         |            | 
(7 rows)

postgres=# 

 \list 명령

postgres=# \list
                                                            List of databases
        Name        |   Owner   | Encoding | Locale Provider |   Collate   |    Ctype    | ICU Locale | ICU Rules |   Access privileges   
--------------------+-----------+----------+-----------------+-------------+-------------+------------+-----------+-----------------------
 ci_database_test01 | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 ci_database_test02 | postgres  | EUC_TW   | libc            | C           | C           |            |           | 
 ci_database_test03 | circledba | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 circledba_test     | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 postgres           | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | 
 template0          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
 template1          | postgres  | UTF8     | libc            | zh_CN.UTF-8 | zh_CN.UTF-8 |            |           | =c/postgres          +
                    |           |          |                 |             |             |            |           | postgres=CTc/postgres
(7 rows)

postgres=# 

선택 명령 

postgres=# SELECT datname FROM pg_database;
      datname       
--------------------
 postgres
 circledba_test
 template1
 template0
 ci_database_test01
 ci_database_test02
 ci_database_test03
(7 rows)

postgres=# 

PostgreSQL 문자 집합 참조 테이블

이름 설명 언어 섬기는 사람? 중환자실? 바이트/문자 별칭
BIG5 빅 파이브 중국어 번체 아니요 아니요 1-2 WIN950Windows950
EUC_CN 확장 UNIX 코드-CN 중국어 간체 1-3
EUC_JP 확장 UNIX 코드-JP 일본어 1-3
EUC_JIS_2004 확장 UNIX 코드-JP, JIS X 0213 일본어 아니요 1-3
EUC_KR 확장 유닉스 코드-KR 한국인 1-3
EUC_TW 확장 UNIX 코드-TW 중국어(번체), 대만어 1-3
GB18030 국가표준 중국인 아니요 아니요 1-4
GBK 확장된 국가 표준 중국어 간체 아니요 아니요 1-2 WIN936Windows936
ISO_8859_5 ISO 8859-5, ECMA 113 라틴어/키릴 문자 1
ISO_8859_6 ISO 8859-6, ECMA 114 라틴어/아랍어 1
ISO_8859_7 ISO 8859-7, ECMA 118 라틴어/그리스어 1
ISO_8859_8 ISO 8859-8, ECMA 121 라틴어/히브리어 1
JOHAB 요압 한국어(한글) 아니요 아니요 1-3
KOI8R KOI8-R 키릴 문자(러시아어) 1 KOI8
KOI8U KOI8-U 키릴 문자(우크라이나어) 1
LATIN1 ISO 8859-1, ECMA 94 서유럽 1 ISO88591
LATIN2 ISO 8859-2, ECMA 94 중앙 유럽 1 ISO88592
LATIN3 ISO 8859-3, ECMA 94 남유럽 1 ISO88593
LATIN4 ISO 8859-4, ECMA 94 북유럽 1 ISO88594
LATIN5 ISO 8859-9, ECMA 128 터키어 1 ISO88599
LATIN6 ISO 8859-10, ECMA 144 북유럽 인 1 ISO885910
LATIN7 ISO 8859-13 발트 어파 1 ISO885913
LATIN8 ISO 8859-14 켈트 말 1 ISO885914
LATIN9 ISO 8859-15 LATIN1(유로 및 악센트 포함) 1 ISO885915
LATIN10 ISO 8859-16, ASRO SR 14111 루마니아 사람 아니요 1 ISO885916
MULE_INTERNAL 뮬 내부 코드 다국어 Emacs 아니요 1-4
SJIS 시프트 JIS 일본어 아니요 아니요 1-2 MskanjiShiftJISWIN932Windows932
SHIFT_JIS_2004 시프트 JIS, JIS X 0213 일본어 아니요 아니요 1-2
SQL_ASCII unspecified (see text) any Yes No 1
UHC Unified Hangul Code Korean No No 1-2 WIN949Windows949
UTF8 Unicode, 8-bit all Yes Yes 1-4 Unicode
WIN866 Windows CP866 Cyrillic Yes Yes 1 ALT
WIN874 Windows CP874 Thai Yes No 1
WIN1250 Windows CP1250 Central European Yes Yes 1
WIN1251 Windows CP1251 Cyrillic Yes Yes 1 WIN
WIN1252 Windows CP1252 Western European Yes Yes 1
WIN1253 Windows CP1253 Greek Yes Yes 1
WIN1254 Windows CP1254 Turkish Yes Yes 1
WIN1255 Windows CP1255 Hebrew Yes Yes 1
WIN1256 Windows CP1256 Arabic Yes Yes 1
WIN1257 Windows CP1257 Baltic Yes Yes 1
WIN1258 Windows CP1258 Vietnamese Yes Yes 1 ABCTCVNTCVN5712VSCII

추천

출처blog.csdn.net/sinat_36528886/article/details/134997925