간마늘작업소

[PGSQL] PostgreSQL 15 – 01.설치 본문

Linux/31.PostgreSQL

[PGSQL] PostgreSQL 15 – 01.설치

간마늘 2022. 7. 4. 15:01

0.개요

  • PostgreSQL 15 설치 진행.
    • PostgreSQL 10 이상이면 설치 방법이 동일함.

 

1.사전 준비

 

  • 선택을 완료하면 설치할 PostgreSQL 버전과 운영체제, CPU 아키텍처 방식을 지정할 수 있음.
    1. 설치할 PostgreSQL 버전은 PostgreSQL 15.
    2. 서버의 운영체제는 CentOS 7.9이므로 이에 맞는 버전 지정.
    3. CPU 아키텍처 방식은 AMD64이므로 x86_64 지정.
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

dnf -qy module disable postgresql                       ## RHEL 8 및 CentOS 8, Rocky Linux 8 등 RHEL 8 기반 운영체제 및 그 이상 버전에서 실시

yum grouplist -y
  • PostgreSQL 리포지토리 설치 진행.

 

2.설치

yum install glibc* gcc* perl
yum install postgresql15-server postgresql15-contrib postgresql15-devel
  • PostgreSQL 15 패키지 설치.
mkdir -p /var/lib/pgsql/15/data/
chown -R postgres.postgres /var/lib/pgsql/15
chown -R postgres.postgres /usr/pgsql-15
  • 데이터 디렉토리 생성 및 postgres 계정 할당.
usermod -d /usr/pgsql-15 postgres
cat /etc/passwd | grep postgres
  • postgres 계정의 홈 디렉토리를 변경.
cd /usr/pgsql-15

cp /etc/skel/.* .
chown -R postgres.postgres .
  • bash 쉘 터미널 적용.
su - postgres

cd /usr/pgsql-15/bin
./initdb -D /var/lib/pgsql/15/data/

exit
  • PostgreSQL 15 데이터 디렉토리 설치.

 

3.초기 설정

su - postgres

cd /var/lib/pgsql/15/data/
vi postgresql.conf
(전략)
listen_addresses = '*' 
(중략)
port = 5432
(중략)
password_encryption = scram-sha-256
(후략)
  • postgresql.conf 파일에서 'listen_addresses' 설정 항목을 찾아서 내용 수정.
    1. 기본 값은 '#listen_addresses = 'localhost'로 되어 있음.
  • postgresql.conf 파일에서 'port' 설정 항목을 찾아서 내용 수정.
    1. 기본 값은 '#port = 5432'로 되어 있음.
  • postgresql.conf 파일에서 'password_encryption' 설정 항목을 찾아서 내용 수정.
    1. 기본 값은 '#port = 5432'로 되어 있음.
      • 암호 형식
        1. md5 : PostgreSQL 14 미만 버전에서의 기본 값.
        2. scram-sha-256 : PostgreSQL 14 이상 버전에서의 기본 값.
vi pg_hba.conf
(전략)
# IPv4 local connections:
(중략)
host    all             all             0.0.0.0/0               scram-sha-256
(후략)
  • pg_hba.conf 파일 하단에 위치한 '# IPv4 local connections:' 부분에 내용 추가 후 저장.
    • 암호 형식
      1. md5 : PostgreSQL 14 미만 버전에서의 기본 값.
      2. scram-sha-256 : PostgreSQL 14 이상 버전에서의 기본 값.

 

4.실행

sudo systemctl start postgresql-15.service

sudo systemctl status postgresql-15.service
  • PostgreSQL 실행 및 프로세스 상태 확인.
Comments