매번 서버에 셋팅할때 마다 햇갈려서 정리한다.
migrate하기 전에 DB와 접속계정부터 만들어 놔야 한다.
1. 접속
# su - postgres
$ psql
psql (17.4)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
-----------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
template0 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(3 rows)
2. 데이터 베이스 생성
postgres=# create database "pl.menggle.com" ;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | Locale | ICU Rules | Access privileges
----------------+----------+----------+-----------------+-------------+-------------+--------+-----------+-----------------------
pl.menggle.com | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
postgres | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | |
template0 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.UTF-8 | en_US.UTF-8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
3. 계정 생성
postgres=# \c pl.menggle.com
You are now connected to database "pl.menggle.com" as user "postgres".
pl.menggle.com=# create user appuser with password '********';
CREATE ROLE
pl.menggle.com=# alter role appuser set client_encoding to 'utf-8';
ALTER ROLE
pl.menggle.com=# alter role appuser set timezone to 'Asia/Seoul';
ALTER ROLE
계정삭제 : https://blog.daonelab.com/post/27/1991/
4. 권한 부여
postgres=# alter database "pl.menggle.com" owner to appuser;
ALTER DATABASE
5. Django migrate
(.venv) # python manage.py migrate --settings=base.settings.settings_prd
정상적으로 Table들이 생성된다.