1. 설치
apt install postgresql postgresql-client
설치 시 postgres라는 계정이 생성된다.
2. 관리도구 접속
postgres 계정은 패스워드 없이 생성되므로 아래와 같이 sudoers 계정으로 관리 도구를 실행한다.
sudo -u postgres psql
3. DB 사용자 생성
특이하게 user가 아닌 role 이라는 용어를 사용한다.
postgres=# create user MY_USER password '123123123';
CREATE ROLE
4. DB 생성
postgres=# create database MY_DB owner MY_USER;
CREATE DATABASE
5. DB 접속 (MySQL의 "USE")
postgres=# \c DB명
6. DB 로케일 확인 방법
기본 로케일은 UTF-8이다. 굳이 확인하고 싶다면 이렇게 하면 된다.
postgres=# \l
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
-----------+-----------+----------+-----------------+---------+---------+------------+-----------+-----------------------
my_db | my_user | UTF8 | libc | C.UTF-8 | C.UTF-8 | | |
postgres | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | |
template0 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | C.UTF-8 | C.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
7. 도움말
postgres=# \?