본문 바로가기

PostgreSQL

PostgreSQL 9.6 설치 구성

RPM 설치

yum install postgresql-server

postgresql-server-9.6.1-1.el7.x86_64
postgresql-libs-9.6.1-1.el7.x86_64
postgresql-9.6.1-1.el7.x86_64

OS 그룹, 유저 추가

root user 에서 수행

groupadd dba
useradd -g dba -s /bin/bash -d /data/postgres postgres

PostgreSQL 클러스터 초기화

/usr/pgsql-9.6/bin/pg_ctl initdb -D /data/postgres/data

-D 옵션에 해당하는 디렉토리가 존재하면 안 된다.

[postgres@testdb02:~]$ /usr/pgsql-9.6/bin/pg_ctl initdb -D /data/postgres/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 "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /data/postgres/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

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:

Parameter 수정

cd ..data

vi postgresql.conf

-- 재시작 필요
max_connections = 100 
shared_buffers = 128MB --> TOTAL 8GB 의 경우 2GB 로 셋팅

hba.conf 수정

기존 셋팅 삭제하고 아래 config 만 넣음

local all all md5

사용자편의 스크립트 구성

-- vi startup.sh

/usr/pgsql-9.6/bin/pg_ctl start -D /data/postgres/data -l /data/postgres/postgres.log


-- vi shutdown.sh

/usr/pgsql-9.6/bin/pg_ctl stop -D /data/postgres/data -l /data/postgres/postgres.log


-- vi reload.sh

/usr/pgsql-9.6/bin/pg_ctl reload -D /data/postgres/data -l /data/postgres/postgres.log

구동 문제 시 

[postgres@testdb02:~]$ cat postgres.log 
< 2017-05-18 15:50:02.528 KST > FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": No such file or directory
< 2017-05-18 15:50:02.529 KST > LOG: database system is shut down

/var/run/postgresql 디렉토리가 존재하면 삭제하고,
postgresql owner, group 으로 디렉토리를 생성합니다.