PostgreSQL/Install
[Linux] PostgreSQL 설치 (Source file Install)
인성장
2023. 11. 24. 15:52
본 문서는 [Linux]CentOS 7.9에 PostgreSQL 12.11 source file 방식 설치에 대한 문서입니다.
설치 환경
1. OS : CentOS Linux Release 7.9 2009
2. DB : PostgreSQL 12.11
* PostgreSQL 버전(11 이상)이 달라도 설치방법은 해당 문서내용과 동일합니다. 설치파일은 아래 링크에서 다운받으세요.
PostgreSQL source file Download 경로 https://www.postgresql.org/ftp/source/
Linux에 PostgreSQL 설치 방법
패키지 설치
# yum -y install gcc gcc-c++ make autoconf readline readline-devel zlib zlib-devel openssl openssl-devel gettext-devel python python-devel perl
방화벽 비활성화, selinux disable
# vi /etc/selinux/config
..(생략)..
SELINUX=disabled
..(생략)..
# systemctl stop firewalld
# systemctl disable firewalld
Resource limit 설정
# vi /etc/security/limits.conf
..(생략)..
postgres soft nofile 1024
postgres hard nofile 65536
# End of file
커널 파라미터 설정
# vi /etc/sysctl.conf
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.rp_filter = 2
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 9000 65500
-- 적용
# sysctl –p
재부팅
# reboot
그룹 및 유저, 설치 디렉토리 생성
# groupadd dba
# useradd -g dba -G dba postgres
*** 비밀번호 설정 ***
# passwd postgres
*** PostgreSQL Home 디렉토리 생성 및 권한 부여 ***
# mkdir -p /postgres/app/postgres/pgsql12
# chown -R postgres:dba /postgres
postgres 계정 환경변수 설정
# su - postgres
$ vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export PG_HOME=/postgres/app/postgres/pgsql12
export PGDATA=$PG_HOME/data
export PGLIB=$PG_HOME/lib
export PATH=$PG_HOME/bin:$PATH
-- 환경변수 적용
$ source ~/.bash_profile
설치파일 압축해제, PostgreSQL Configure
$ cd /home/postgres
$ ls
postgresql-12.11.tar.gz
$ tar -zxvf postgresql-12.11.tar.gz
$ cd postgresql-12.11
$ ./configure --prefix=/postgres/app/postgres/pgsql12 --enable-depend --enable-nls=utf-8 --with-python
컴파일 진행
$ make
$ make check
$ make install
DB 생성
$ initdb -E utf-8 --locale=ko_KR.UTF-8 -D /postgres/app/postgres/pgsql12/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "ko_KR.UTF-8".
initdb: could not find suitable text search configuration for locale "ko_KR.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
creating directory /postgres/app/postgres/pgsql12/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Seoul
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
- -auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/postgres/app/postgres/pgsql12/bin/pg_ctl -D /postgres/app/postgres/pgsql12/data -l logfile start
DB Start
$ cd /postgres/app/postgres/pgsql12/bin/
$ ./pg_ctl -D /postgres/app/postgres/pgsql12/data/ -l logfile start
프로세스 확인
$ ps -x
45185 ? Ss 0:00 /postgres/app/postgres/pgsql12/bin/postgres -D /postgres/app/postgres/pgsql12/data
45187 ? Ss 0:00 postgres: checkpointer
45188 ? Ss 0:00 postgres: background writer
45189 ? Ss 0:00 postgres: walwriter
45190 ? Ss 0:00 postgres: autovacuum launcher
45191 ? Ss 0:00 postgres: stats collector
45192 ? Ss 0:00 postgres: logical replication launcher
45199 pts/0 R+ 0:00 ps -x
관리자 계정 초기 비밀번호 설정
$ psql
psql (12.11)
Type "help" for help.
postgres=# \password postgres
Enter new password for user "postgres": password
Enter it again: password
postgres=#
설치 완료