반응형

/*
-- Title : [PGS15.6] Postresql 설치 매뉴얼 - ver.dBRang
*/


!!! 기존 9.4 버전에서 15.6 버전으로 설치 매뉴얼 업데이트

1. 서버 OS, CPU 체크

[root] # arch
ㅌ86_64

[root]  # cat /etc/redhat-release
Rocky Linux release 9.3 (Blue Onyx)

[root] #  uname -a
Linux localhost 5.14.0-362.8.1.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 8 17:36:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

[root]  #

• x86, x64 확인(32bit, 64bit)
• OS Version 확인 

 

2. 스토리지 체크

[root] # df -k
Filesystem          1K-blocks    Used Available Use% Mounted on
devtmpfs                 4096       0      4096   0% /dev
tmpfs                 1867752       0   1867752   0% /dev/shm
tmpfs                  747104    9336    737768   2% /run
/dev/mapper/rl-root  13037568 6078728   6958840  47% /
/dev/sda1              983040  305728    677312  32% /boot
tmpfs                  373548     100    373448   1% /run/user/0
/dev/sr0                52272   52272         0 100% /run/media/root/VBox_GAs_7.0.14

[root] # 

• Postgres 홈디렉토리 설치 용량 확인
• 데이터 및 아카이브 저장 위치 확인 

 

3. PostgreSQL 다운로드 및 압축 해제

[root] # cd /usr/local/src
[root] # wget https://ftp.postgresql.org/pub/source/v15.6/postgresql-15.6.tar.gz
...
postgresql-15.6.tar.gz     100%[=======================================>]  28.90M  6.41MB/s    in 4.5s    

2024-04-27 23:10:08 (6.41 MB/s) - `postgresql-15.6.tar.gz' saved [30299236/30299236]

[root] # tar zxvf postgresql-15.6.tar.gz

• 사용할 PostgreSQL 버전 다운로드 및 압축 해제

 

4. OS 파라미터 수정

--// limits.conf 수정
[root] # vi /etc/security/limits.conf
...
### PostgreSQL Install 내용 추가
postgres soft nofile 65535 
postgres hard nofile 65535

--// sysctl.conf 수정
[root] # vi /etc/sysctl.conf
...
### 아래 내용 추가
fs.file-max=65535

[root] # sysctl -p
fs.file-max=65535
  • Production 서비스를 위해서는 필수, 개발버전에서는 스킵 가능

 

5. 패키지 업데이트

[root] # yum -y install glibc make gcc gcc-c++ readline readline-devel zlib zlib-devel autoconf openssl openssl-devel uuid gettext gettext-devel python python-devel postgresql-libs

 

6. postgres 사용자 생성

[root] # useradd -d /home/postgres postgres
[root] # cat /etc/passwd    -- 사용자 등록 확인
...
postgres:x:1001:1001::/home/postgres:/bin/bash

[root] # passwd postgres   -- 사용자 PWD 생성
[root] # pwconv           -- PWD 반영

[root] # id postgres
uid=1001(postgres) gid=1001(postgres) groups=1001(postgres)

[root] #

• postgres 홈디렉토리 : /home/postgres

 

 7. bash_profile 변경

[root] # su - postgres
[postgres] $ vi .bash_profile    -- 아래 파란색 텍스트 붙여넣기

<BOF>

# .bash_profile
# Get the aliases and functions

if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs


PATH=$PATH:$HOME/bin
POSTGRES_HOME=/home/postgres/pgsql
LD_LIBRARY_PATH=/home/postgres/pgsql/lib
PGDATA=$POSTGRES_HOME/data
MANPATH=$MANPATH:$POSTGRES_HOME/man

PATH=$POSTGRES_HOME/bin:$PATH 

export PATH
export POSTGRES_HOME
export PGDATA
export MANPATH
export LD_LIBRARY_PATH

<EOF>
[postgres] $ source .bash_profile
[postgres] $ exit
로그아웃

[root] #

 

8. PostgreSQL 설치

[root] # cd /usr/local/src/postgresql-15.6
[root] # ./configure --prefix=/home/postgres/pgsql --enable-depend --enable-nls=ko --with-python

...
[root] # make
[root] # make install

• 설치디렉토리 : /home/postgres/pgsql
• 나머지 옵션은 그대로.
• 패키지 에러 발생시 # yum –y install로 해당 패키지 설치 후 재진행.

 

9. 데이터 디렉토리 추가/소유자 할당

[root] # mkdir –p /home/postgres/pgsql/data
[root] # chown -R postgres.postgres /home/postgres/pgsql

 

10. 데이터베이스 클러스터 생성

[root] # su - postgres
[postgres] $ cd /home/postgres/pgsql/bin
[postgres] $ ./initdb -E utf-8 -D /home/postgres/pgsql/data
...
작업완료. 이제 다음 명령을 이용해서 서버를 가동 할 수 있습니다:

    pg_ctl -D /home/postgres/pgsql/data -l 로그파일 start

[root] #

• 데이터디렉토리(PGDATA) : /home/postgres/pgsql/data

 

11. 데이터베이스 기동

[postgres] $ pg_ctl start
2024-04-27 23:38:04.841 KST [52989] 로그:  이제 데이터베이스 서버로 접속할 수 있습니다
 완료
서버 시작됨

[postgres] $

 

12. Superuser 생성

[postgres] $ psql
postgres=# create role {account} login password '{password}' superuser;
CREATE ROLE
postgres=# \q

 

13. postgresql.conf 변경

[postgres] $ vi /home/postgres/pgsql/data/postgresql.conf
...
listen_addresses = 'localhost' → '*' 로 변경

 

14. pg_hba.conf 변경

[postgres] $ vi /home/postgres/pgsql/data/pg_hba.conf
...
host    all             all             192.168.103.0/24        md5       #추가

 

15. DB 재시작

[postgres] $ pg_ctl restart
...
2024-04-27 23:50:34.519 KST [53033] 로그:  이제 데이터베이스 서버로 접속할 수 있습니다
 완료
서버 시작됨

[postgres] $

 

16. 방화벽 오픈/재시작

[postgres] $ exit
로그아웃

--// 방화벽 상태 확인
[root] # systemctl status firewalld
...
     Active: active (running) since Sat 2024-04-27 22:45:51 KST; 1h 7min ago
...

--// 영구 포트 허용
[root] # firewall-cmd --permanent --add-port=5432/tcp
success


--// 방화벽 리로드(필수)
[root] # firewall-cmd --reload
success

[root] #

 

17. 재부팅시 자동 시작 설정 및 재시작

[root] # vi /etc/rc.local
...
su - postgres -c'pg_ctl -D ''/home/postgres/pgsql/data'' start'     #추가

[root] # shutdown –r now
...
재부팅 
  •  중간Qutation 변환 주의

 

18. 재시작 확인

[postgres] $ pg_ctl status
pg_ctl: 가동 중인 서버가 없음

[postgres] $ pg_ctl start
...
서버 시작됨

[postgres] $ pg_ctl status
pg_ctl: 서버가 실행 중임 (PID: 2983)
/home/postgres/pgsql/bin/postgres

[postgres] $ psql
postgres=# select version();


                                                 version                        
----------------------------------------------------------------------------------------------------------

 PostgreSQL 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.4.1 20230605 (Red Hat 11.4.1-2), 64-bit

(1개 행)

postgres=#
  • Reboot 후 정상 '자동 시작'이 되지 않음. 확인 필요.

 


 

반응형

+ Recent posts