리눅스

CentOS 7에서 PostgreSQL을 설치하는 방법

변군이글루 2025. 7. 15. 15:48
반응형

CentOS 7에서 PostgreSQL을 설치하는 방법

PostgreSQL 저장소 추가

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

PostgreSQL 설치

sudo yum install -y postgresql postgresql-libs postgresql-server

데이터베이스 클러스터 초기화

sudo /bin/postgresql-setup initdb
Initializing database ... OK

PostgreSQL 서비스 시작 및 부팅 시 자동 실행

sudo systemctl enable --now postgresql.service

PostgreSQL 버전 확인

psql --version
psql (PostgreSQL) 9.2.24

외부 접속 허용 설정

postgresql.conf 수정

sudo vim /var/lib/pgsql/data/postgresql.conf
listen_addresses = '0.0.0.0'

pg_hba.conf 수정

sudo vim /var/lib/pgsql/data/pg_hba.conf
host    all             all             0.0.0.0/0               md5

PostgreSQL 재시작

sudo systemctl restart postgresql.service

PostgreSQL 접속 테스트

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

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

외부 클라이언트

psql -h <서버IP> -U postgres -d postgres

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------. GCC (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64 비트에 의해 편집 된 x86_64-redhat-linux-gnu의 postgresql 9.2.24 (1 줄)
 
반응형