처음 PostgresQL을 설치하는 단계라면 최초 init을 하기 전, 즉 서비스를 최초 실행하기 전 "/usr/lib/systemd/system/postgresql-12.service"를 수정하고 initdb를 수행하는 것이
show data_directory;
data_directory
------------------------
/var/lib/pgsql/12/data
systemctl stop postgresql-12
vi /var/lib/pgsql/12/data/postmaster.opts
# 기본 값
# /usr/pgsql-12/bin/postgres "-D" "/var/lib/pgsql/12/data/"
# 변경하고자 하는 값
# /usr/pgsql-12/bin/postgres "-D" "/desired_DIR"
/usr/pgsql-12/bin/postgres "-D" "/postgresql/data/"
vi /usr/lib/systemd/system/postgresql-12.service
# Location of database directory
# 다음 줄을 수정한다
#Environment=PGDATA=/var/lib/pgsql/12/data/
Environment=PGDATA=/postgresql/data/
cp -r /var/lib/pgsql/12/data /postgresql/
systemctl daemon-reload
systemctl start postgresql-12
show data_directory;
data_directory
------------------
/postgresql/data