[rocky9 postgres on wsl]
OS : Rocky linux 9.5 on wsl
DB : PostgreSQL 16.1.2
useradd -G wheel postgres
[postgres@DESKTOP-OUB301V ~]$ sudo hostname
DESKTOP-OUB301V
https://download.postgresql.org/pub/repos/yum/16/redhat/rhel-9-x86_64/
[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
설치 순서: libs → postgresql → server → contrib → devel → docs
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
/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 활성화
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
[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
[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)