티스토리 뷰

728x90
반응형

 포스팅은 PostgreSQL Linux Installation 및 WildFly 연동 방법에 대해 가이드하겠습니다.


최근 Cloud 환경으로 넘어 오면서 급격하게 OpenSource Software를 사용하는 빈도가 늘어나고 있습니다. Standalone 환경에서 ScaleOut, ScaleIn이 유동적으로 이루어 질수 있도록 기반을 잡고 있고, PostgreSQL이 앞으로 DB 시장에 어떠한 역할을 할지 귀추가 주목됩니다.

 

1. PostgreSQL Linux 설치

지난 시간에 알아본 Windows 설치 방법 및 WildFly 연동 방법은 아래 포스팅을 참고하세요.

 

○ 나라의 IT 정복기 ○/ - Database [PostgreSQL] Install & wildfly 연동 for Windows

 

 

금일은 Linux 설치 방법 및 기동 종료 방법에 대해 알아 보겠습니다.

 

먼저 바이너리 다운로드 방법입니다.

위 포스팅에서 설명했듯이 아래와 같이 다운받을 수 있습니다.

 

바이너리 파일은 

https://www.enterprisedb.com/downloads/postgres-postgresql-downloads#windows

에서 다운로드 가능합니다.

 

 

         

- URL 접속 시 위와 같은 화면으로 이동되게 됩니다.

- 필수 선택 사항인 Select your version (postgreSQL Version 선택), Select your operation system(postgreSQL을 설치할 운영체제)를 선택하고

DOWNLOAD NOW를 클릭하면 설치 바이너리가 다운로드 됩니다.

제가 포스팅에 사용할 버전과 운영체제는 다음과 같습니다.

    

postgresql-10.3-1-linux-x64.run

 

바이너리 파일에서 알수 있듯이 postgresql 10.3.1 버전에 Linux 64bits 환경입니다.

설치 과정은 다음과 같습니다.

 

[postgres@NRSON ~]$ sudo ./postgresql-10.3-1-linux-x64.run --mode text
----------------------------------------------------------------------------
Welcome to the PostgreSQL Setup Wizard.

 

----------------------------------------------------------------------------
Please specify the directory where PostgreSQL will be installed.

 

Installation Directory [/opt/PostgreSQL/10]: /home/postgres/PostgreSQL/10

 

----------------------------------------------------------------------------
Select the components you want to install; clear the components you do not want
to install. Click Next when you are ready to continue.

 

PostgreSQL Server [Y/n] :

 

pgAdmin 4 [Y/n] :

 

Stack Builder [Y/n] :

 

Command Line Tools [Y/n] :

 

Is the selection above correct? [Y/n]:

 

----------------------------------------------------------------------------
Please select a directory under which to store your data.

 

Data Directory [/home/postgres/PostgreSQL/10/data]:

 

----------------------------------------------------------------------------
Please provide a password for the database superuser (postgres). A locked Unix
user account (postgres) will be created if not present.

 

Password :
Retype password :
----------------------------------------------------------------------------
Please select the port number the server should listen on.

 

Port [5432]:

 

----------------------------------------------------------------------------
Advanced Options

 

Select the locale to be used by the new database cluster.

 

Locale

 

[1] [Default locale]
[2] C
[3] POSIX
....
[460] ko_KR
[461] ko_KR.euckr
[462] ko_KR.utf8
[463] kok_IN
[464] kok_IN.utf8
[465] korean
[466] korean.euc
...
[762] zh_CN
[763] zh_CN.gb2312
[764] zh_CN.utf8
[765] zh_HK.utf8
[766] zh_SG
[767] zh_SG.gb2312
[768] zh_SG.utf8
[769] zh_TW.euctw
[770] zh_TW.utf8
[771] zu_ZA
[772] zu_ZA.iso88591
[773] zu_ZA.utf8
Please choose an option [1] :

 

----------------------------------------------------------------------------
Pre Installation Summary

 

The following settings will be used for the installation::

 

Installation Directory: /home/postgres/PostgreSQL/10
Server Installation Directory: /home/postgres/PostgreSQL/10
Data Directory: /home/postgres/PostgreSQL/10/data
Database Port: 5432
Database Superuser: postgres
Operating System Account: postgres
Database Service: postgresql-10
Command Line Tools Installation Directory: /home/postgres/PostgreSQL/10
pgAdmin4 Installation Directory: /home/postgres/PostgreSQL/10/pgAdmin 4
Stack Builder Installation Directory: /home/postgres/PostgreSQL/10

 

Press [Enter] to continue:

 

----------------------------------------------------------------------------
Setup is now ready to begin installing PostgreSQL on your computer.

 

Do you want to continue? [Y/n]:

 

----------------------------------------------------------------------------
Please wait while Setup installs PostgreSQL on your computer.

 

 Installing
 0% ______________ 50% ______________ 100%
 #########################################

 

----------------------------------------------------------------------------
Setup has finished installing PostgreSQL on your computer.

 

[postgres@NRSON ~]$

 

 

과정을 하나씩 세분화 해서 살펴보면 다음과 같습니다.

1) sudo ./postgresql-10.3-1-linux-x64.run --mode text

- 다운로드 받은 바이너리 파일을 실행합니다.

2) Installation Directory [/opt/PostgreSQL/10]: /home/postgres/PostgreSQL/10

- postgreSQL을 설치할 인스톨 디렉토리를 선택합니다.

3) 설치 정보를 선택합니다. (Server, pgAdmin, StackBuilder, CLI Tool)

PostgreSQL Server [Y/n] :

pgAdmin 4 [Y/n] :

Stack Builder [Y/n] :

Command Line Tools [Y/n] :

Is the selection above correct? [Y/n]:

4) Data Directory [/home/postgres/PostgreSQL/10/data]:

- data file 설치 정보를 선택합니다.

5) 패스워드를 입력합니다.

Password :
Retype password :

6) 포트를 입력합니다.

Port [5432]:

7) Locale을 선택합니다.

Locale

[1] [Default locale]
[2] C
[3] POSIX

....

8) Summary 정보를 확인합니다.

Pre Installation Summary

The following settings will be used for the installation::

9) Installing 작업을 수행합니다.

 Installing
 0% ______________ 50% ______________ 100%
 #########################################

10) 완료

- Setup has finished installing PostgreSQL on your computer.

 

위와 같은 과정으로 수행하면 postgreSQL을 정상적으로 설치하게 됩니다.

설치가 완료되면, 편의를 위해 .bash_profile or .profile에 환경변수를 등록합니다.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/bin

export PATH
set -o vi

export PATH=/home/postgres/PostgreSQL/10/bin:$PATH
export PGDATA=/home/postgres/PostgreSQL/10/data
export PG_HOME=/home/postgres/PostgreSQL/10
export PGDATABASE=postgres
export PGUSER=postgres
export PGPORT=5432

export MANPATH=$MANPATH:/home/postgres/PostgreSQL/10/share/man

 

alias pbin='cd /home/postgres/PostgreSQL/10/bin'
alias pdata='cd /home/postgres/PostgreSQL/10/data'
alias pstop='/home/postgres/PostgreSQL/10/bin/pg_ctl -m fast stop'
alias pstart='/home/postgres/PostgreSQL/10/bin/pg_ctl start' 

 

 

환경 변수를 위와 같이 등록하게 되면 pg_ctl, psql 등의 cli 명령어를 수행할 때 database, datafile등을 선언하지 않아도 선택할 수 있도록 하기 위함입니다.

 

2. postgreSQL 기동 종료

profile에 등록한 pstart, pstop으로 postgreSQL을 기동 또는 종료 해보록 하겠습니다.

- pstart (pg_ctl start)

[postgres@NRSON ~]$ pstart
waiting for server to start....2018-04-04 14:19:56.516 KST [28648] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-04-04 14:19:56.516 KST [28648] LOG:  listening on IPv6 address "::", port 5432
2018-04-04 14:19:56.535 KST [28648] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-04-04 14:19:56.573 KST [28648] LOG:  redirecting log output to logging collector process
2018-04-04 14:19:56.573 KST [28648] HINT:  Future log output will appear in directory "log".
 done
server started
[postgres@NRSON ~]$ ps -ef | grep postgres
root     27542 26095  0 13:16 pts/2    00:00:00 su - postgres
postgres 27545 27542  0 13:17 pts/2    00:00:00 -bash
postgres 28648     1  0 14:19 pts/2    00:00:00 /home/postgres/PostgreSQL/10/bin/postgres
postgres 28649 28648  0 14:19 ?        00:00:00 postgres: logger process
postgres 28651 28648  0 14:19 ?        00:00:00 postgres: checkpointer process
postgres 28652 28648  0 14:19 ?        00:00:00 postgres: writer process
postgres 28653 28648  0 14:19 ?        00:00:00 postgres: wal writer process
postgres 28654 28648  0 14:19 ?        00:00:00 postgres: autovacuum launcher process
postgres 28655 28648  0 14:19 ?        00:00:00 postgres: stats collector process
postgres 28656 28648  0 14:19 ?        00:00:00 postgres: bgworker: logical replication launcher
postgres 28657 27545  0 14:20 pts/2    00:00:00 ps -ef
postgres 28658 27545  0 14:20 pts/2    00:00:00 grep --color=auto postgres
[postgres@NRSON ~]$

위와 같이 pstart 또는 pg_ctl start로 postgresql을 기동할 수 있습니다.

process는 위와 같이 여러개의 process가 기동되는것을 확인 할수 있습니다.

 

- pstop (pg_ctl stop) 

[postgres@NRSON ~]$ pstop
waiting for server to shut down.... done
server stopped
[postgres@NRSON ~]$ ps -ef | grep postgres

postgres 29030 28970  0 14:36 pts/2    00:00:00 grep --color=auto postgres
[postgres@NRSON ~]$

 

위와 같이 pstop 또는 pg_ctl stop으로 postgresql을 다운할 수 있습니다.

pstart나 pstop은 profile에 등록한 alias임을 기억하며 다음으로 넘어 가겠습니다.

위 명령어 들은 실제로는 다음과 같이 구성되어 있습니다.

[postgres@NRSON ~]$ pstart
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
[postgres@NRSON ~]$ pstop
pg_ctl: no database directory specified and environment variable PGDATA unset
Try "pg_ctl --help" for more information.
[postgres@NRSON ~]$

 

위와 같은 현상이 발생될 경우에는 profile에 PGDATA가 등록되어 있지 않을 경우입니다.

직접 datafile위치를 지정해 주어도 기동 종료를 수행할 수 있습니다.

[postgres@NRSON ~]$ pg_ctl -D /home/postgres/PostgreSQL/10/data start
waiting for server to start....2018-04-04 14:45:02.628 KST [29261] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-04-04 14:45:02.628 KST [29261] LOG:  listening on IPv6 address "::", port 5432
2018-04-04 14:45:02.647 KST [29261] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-04-04 14:45:02.686 KST [29261] LOG:  redirecting log output to logging collector process
2018-04-04 14:45:02.686 KST [29261] HINT:  Future log output will appear in directory "log".
 done
server started
[postgres@NRSON ~]$ pg_ctl -D /home/postgres/PostgreSQL/10/data stop
waiting for server to shut down.... done
server stopped
[postgres@NRSON ~]$

 

위와 같은 방법으로 직접 -D 옵션으로 datafile의 위치를 지정하여 기동 종료를 수행할 수 있습니다.

 

다음 포스팅에서는 CLI 환경에서 유용하게 사용할 수 있는 Command에 대해 알아 보도록 하겠습니다.

감사합니다.


728x90
반응형