rocky linux에 PostgreSQL16 설치

Jung Junkyo·2025년 1월 5일
0

[rocky9 postgres on wsl]

OS : Rocky linux 9.5 on wsl
DB : PostgreSQL 16.1.2

1. postgres user 생성

useradd -G wheel postgres
[postgres@DESKTOP-OUB301V ~]$ sudo hostname
DESKTOP-OUB301V

2. 설치 파일 준비

https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-9-x86_64/

  • wsl 경로로 파일 준비
[root@DESKTOP-OUB301V postgresql]# cd /mnt/c/WSL/postgresql
[root@DESKTOP-OUB301V postgresql]# ls
postgresql16-16.1-2PGDG.rhel9.x86_64.rpm
postgresql16-server-16.1-2PGDG.rhel9.x86_64.rpm
postgresql16-contrib-16.1-2PGDG.rhel9.x86_64.rpm
postgresql16-devel-16.1-2PGDG.rhel9.x86_64.rpm
postgresql16-docs-16.1-2PGDG.rhel9.x86_64.rpm
postgresql16-libs-16.1-2PGDG.rhel9.x86_64.rpm

3. PostgreSQL16 install

설치 순서: libs → postgresql → server → contrib → devel → docs

  • devel의 경우 'perl-IPC-Run' 의존성 오류가 발생할 수 있음.
  • 그럴 경우 'CRB' repo를 활성화 한후 설치 진행.
  • repo 활성화가 불가한 폐쇄망일 경우 힘들게 구해야함
dnf install ./postgresql16-libs-16.1-2PGDG.rhel9.x86_64.rpm
dnf install ./postgresql16-16.1-2PGDG.rhel9.x86_64.rpm
dnf install ./postgresql16-server-16.1-2PGDG.rhel9.x86_64.rpm
dnf install ./postgresql16-contrib-16.1-2PGDG.rhel9.x86_64.rpm
dnf install postgresql16-devel-16.1-2PGDG.rhel9.x86_64.rpm
-- dependency
dnf config-manager --set-enabled crb 
[root@DESKTOP-OUB301V data]# dnf repolist |grep CRB
crb                 Rocky Linux 9 - CRB

dnf install perl-IPC-Run
dnf install ./postgresql16-devel-16.1-2PGDG.rhel9.x86_64.rpm

4. PostgreSQL initdb

4.1 PostgreSQL DB 초기화

/usr/pgsql-16/bin/postgresql-16-setup initdb

  • 오류 발생
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
failed to find PGDATA setting in postgresql-16.service

-> WSL은 systemd 대신 init 시스템을 사용해 부팅하기 때문에, systemctl 명령어가 제대로 작동 x
https://learn.microsoft.com/ko-kr/windows/wsl/systemd

  • 해결방법
    WSL에서 systemd를 활성화 한 후, OS reboot
# WSL에서 systemd 활성화
vi /etc/wsl.conf
[boot]
systemd=true

# wsl 재시작
PS C:\Users> wsl --shutdown
PS C:\Users> wsl -l -v
 NAME      STATE           VERSION
* Ubuntu    Stopped         2
  Rocky9    Stopped         2
PS C:\Users> wsl -d Rocky9

# initdb
[root@DESKTOP-OUB301V Users]# /usr/pgsql-16/bin/postgresql-16-setup initdb
Initializing database ... OK 

3. PostgreSQL DB 활성화

[postgres@DESKTOP-OUB301V ~]$ sudo systemctl status postgresql-16
○ postgresql-16.service - PostgreSQL 16 database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql-16.service; disable>
     Active: inactive (dead)
       Docs: https://www.postgresql.org/docs/16/static/	   

[postgres@DESKTOP-OUB301V 16]$ sudo systemctl start postgresql-16

4. 접속 확인

[postgres@DESKTOP-OUB301V 16]$ psql -c 'select version();'
                                                 version

----------------------------------------------------------------------------
------------------------------
 PostgreSQL 16.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.4.1 202306
05 (Red Hat 11.4.1-2), 64-bit
(1 row)
profile
DB specialist를 꿈꾸는 초짜

0개의 댓글