1. Linux version 확인

# uname -a
Linux localhost.localdomain 3.10.0-327.36.1.el7.x86_64 #1 SMP Sun Sep 18 13:04:29 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

 

2. yum update

# sudo yum update -y

 

3. postgresql 9.2이상은 저장소 업데이트가 필요.
아래링크에서 버전에 맞는 rpm주소 복사
https://yum.postgresql.org/repopackages.php#pg12

# rpm -Uvh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

 

4. PostgreSQL 설치

# sudo yum install -y postgresql postgresql-server postgresql-devel postgresql-contrib postgresql-docs

 

5. PostgreSQL 초기화

# sudo service postgresql initdb
Hint: the preferred way to do this is now "postgresql-setup initdb"
Initializing database ... OK

 

6. 서비스 시작 및 서비스 자동실행 등록

# sudo systemctl start postgresql
# sudo systemctl enable postgresql
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.

 

7. 등록된 서비스 확인

# systemctl list-unit-files --type=service | grep postgre
postgresql.service                          enabled 

 

8. PostgreSQL 접속

# sudo -u postgres psql
could not change directory to "/root"
psql (9.2.24)
Type "help" for help.

postgres=# 
postgres=# select version();
                                                    version                                                    
---------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.2.24 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)