PostgreSQL 이 어떤건지, 어떤 역사를 가지고 있는지에 대해서 알아봤으니 이제 설치를 해보도록 합시다.

나는 개발자가 아니기에 PostgreSQL 문서중 Server Admin 에 대한 내용을 중점으로 다루도록 하겠습니다.


설치는 AWS Amazon Linux 기준으로 진행하도록 하겠습니다. 


가장 쉬운 방법인 "yum" 을 통한 설치를 하게되면 PostgreSQL 9.2.22 버전이 설치 됩니다. 



우선 PostgreSQL 다운로드 해보도록 하자


https://www.postgresql.org/download/


여러가지 Download Link 가 있다. 


[BSD]

FreeBSD 

- https://www.postgresql.org/download/freebsd/

- https://www.freebsd.org/cgi/ports.cgi?query=postgresql&stype=name&sektion=databases

OpenBSD

- https://www.postgresql.org/download/openbsd/

- http://www.openbsd.org/faq/faq15.html


[Linux]

Redhat Family Linux (including CentOS/Fedora/Scientfic/Oracle variants)

- https://www.postgresql.org/download/linux/redhat/

Debian GNU/Linux and derivatives]

- https://www.postgresql.org/download/linux/debian/

Ubuntu Linux and derivatives

 - https://www.postgresql.org/download/linux/ubuntu/

SuSE and OpenSuSE

- https://www.postgresql.org/download/linux/suse/

Other Linux

- https://www.postgresql.org/download/linux/


[macOS]

- https://www.postgresql.org/download/macosx/

[Solaris]

- https://www.postgresql.org/download/solaris/

[Windows]

- https://www.postgresql.org/download/windows/


위의 링크는 Binary Packages 형태의 설치 가이드 입니다. 


하지만 저는 기본적으로 소스설치 기준으로 설치를 진행해보도록 하겠습니다. 


[Source]

- https://www.postgresql.org/ftp/source/

- https://git.postgresql.org/gitweb/?p=postgresql.git;a=summary

 

Git 으로 설치하는것과 Make 를 이용한 설치 두가지중 Make 를 이용한 설치를 우선적으로 해보도록 하겠습니다. 


"https://www.postgresql.org/ftp/source/v10.0/" 여기에서 파일을 다운로드 하시면 됩니다. 


[root@ip-10-90-10-49 postgresql]# wget https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz

--2017-10-27 03:10:39--  https://ftp.postgresql.org/pub/source/v10.0/postgresql-10.0.tar.gz

Resolving ftp.postgresql.org (ftp.postgresql.org)... 87.238.57.227, 174.143.35.246, 204.145.124.244, ...

Connecting to ftp.postgresql.org (ftp.postgresql.org)|87.238.57.227|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 25830653 (25M) [application/x-gzip]

Saving to: ‘postgresql-10.0.tar.gz’


postgresql-10.0.tar.gz               100%[======================================================================>]  24.63M  4.69MB/s    in 6.8s


2017-10-27 03:10:48 (3.62 MB/s) - ‘postgresql-10.0.tar.gz’ saved [25830653/25830653]


[root@ip-10-90-10-49 postgresql]#


[root@ip-10-90-10-49 postgresql]# ll
total 25228
-rw-r--r-- 1 root root 25830653 Oct  2 21:15 postgresql-10.0.tar.gz
[root@ip-10-90-10-49 postgresql]# tar xfz postgresql-10.0.tar.gz
[root@ip-10-90-10-49 postgresql]# ll
total 25232
drwxrwxrwx 6 1107 1107     4096 Oct  2 21:15 postgresql-10.0
-rw-r--r-- 1 root root 25830653 Oct  2 21:15 postgresql-10.0.tar.gz
[root@ip-10-90-10-49 postgresql]# cd postgresql-10.0
[root@ip-10-90-10-49 postgresql-10.0]#

[root@ip-10-90-10-49 postgresql-10.0]# ./configure && make && make install

checking build system type... x86_64-pc-linux-gnu

checking host system type... x86_64-pc-linux-gnu

checking which template to use... linux

checking whether NLS is wanted... no

checking for default port number... 5432

checking for block size... 8kB

checking for segment size... 1GB

checking for WAL block size... 8kB

checking for WAL segment size... 16MB

checking for gcc... no

checking for cc... no

configure: error: in `/root/postgresql/postgresql-10.0':

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details

[root@ip-10-90-10-49 postgresql-10.0]#


메뉴얼에 나와있는대로 ./configure 를 진행하였으나 오류가 발생하였습니다. 위의 메시지를 잘보시면 gcc, cc 가 no 라는 메시지를 발견할수 있습니다. gcc 및 기타 개발관련 Package 를 설치해 줍니다. 


[root@ip-10-90-10-49 postgresql-10.0]# yum groupinstall 'Development Tools'


대략 77개의 Package 를 추가 설치 해주는걸 볼수 있습니다. 


다시 설치를 하다보니 이번에는 readline 에서 오류가 발생하는군요


checking for library containing readline... no

configure: error: readline library not found

If you have readline already installed, see config.log for details on the

failure.  It is possible the compiler isn't looking in the proper directory.

Use --without-readline to disable readline support.

[root@ip-10-90-10-49 postgresql-10.0]#


https://www.postgresql.org/message-id/3F997D62.3070401%401scom.net
위의 링크를 확인 해보면 libreadline 라이브러리를 설치해주라는 안내가 나와있습니다. 


http://rpmfind.net/linux/rpm2html/search.php?query=readline-devel 

readline 라이브러리는 "readline-devel" 설치하면 해결이 될듯 합니다. 


[root@ip-10-90-10-49 postgresql-10.0]# yum install readline-devel


오 노 .... zlib 라이브러리가 없다네요 찾아서 설치해봅니다. 

checking for inflate in -lz... no

configure: error: zlib library not found


[root@ip-10-90-10-49 postgresql-10.0]# yum install zlib-devel -y

설치가 잘 됩니다.



make[1]: Leaving directory `/root/postgresql/postgresql-10.0/src'

make -C config install

make[1]: Entering directory `/root/postgresql/postgresql-10.0/config'

/bin/mkdir -p '/usr/local/pgsql/lib/pgxs/config'

/usr/bin/install -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'

/usr/bin/install -c -m 755 ./missing '/usr/local/pgsql/lib/pgxs/config/missing'

make[1]: Leaving directory `/root/postgresql/postgresql-10.0/config'

PostgreSQL installation complete.

[root@ip-10-90-10-49 postgresql-10.0]#


설치가 잘 완료되었습니다. 


Amazon Linux 에서 PostgreSQL을 설치할때에 3가지를 추가 설치 하였습니다. 


'Development Tools'

readline-devel

zlib-devel


PostgreSQL 을 설치하기 위한 기본 라이브러리 리스트가 있을듯 하지만 추 후 추가 하도록 하겠습니다. 


다음 해야할 일은 "PostgreSQL" 을 운영하기 위한 user 의 등록과 서비스 올리기 입니다. 


[root@ip-10-90-10-49 postgresql-10.0]# useradd postgres

postgres 유저를 생성합니다. 


[root@ip-10-90-10-49 postgresql-10.0]# mkdir /usr/local/pgsql/data

postgreSQL 이 사용할 data 디렉토리를 생성합니다. 


[root@ip-10-90-10-49 postgresql-10.0]# chown postgres /usr/local/pgsql/data

/usr/local/pgsql/data 디렉토리에 "postgres" 유저가 접근할수 있도록 권한을 설정 합니다. 


[root@ip-10-90-10-49 postgresql-10.0]# su - postgres

다음 작업들은 postgres 유저로 해야하기에 user 를 변경합니다.


[postgres@ip-10-90-10-49 ~]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
postgreSQL 을 실행하는데 data 디렉토리는 /usr/local/pgsql/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.

fixing permissions on existing directory /usr/local/pgsql/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:

    /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

[postgres@ip-10-90-10-49 ~]$ /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 30666

[postgres@ip-10-90-10-49 ~]$ /usr/local/pgsql/bin/createdb test
createdb: could not connect to database template1: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[postgres@ip-10-90-10-49 ~]$ /usr/local/pgsql/bin/psql test
psql: FATAL:  database "test" does not exist


[postgres@ip-10-90-10-49 ~]$ ps -ef | grep postgres
root     30632  2628  0 03:53 pts/0    00:00:00 su - postgres
postgres 30633 30632  0 03:53 pts/0    00:00:00 -bash
postgres 30666 30633  0 03:54 pts/0    00:00:00 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
postgres 30669 30666  0 03:54 ?        00:00:00 postgres: checkpointer process
postgres 30670 30666  0 03:54 ?        00:00:00 postgres: writer process
postgres 30671 30666  0 03:54 ?        00:00:00 postgres: wal writer process
postgres 30672 30666  0 03:54 ?        00:00:00 postgres: autovacuum launcher process
postgres 30673 30666  0 03:54 ?        00:00:00 postgres: stats collector process
postgres 30674 30666  0 03:54 ?        00:00:00 postgres: bgworker: logical replication launcher
postgres 30687 30633  0 03:57 pts/0    00:00:00 ps -ef
postgres 30688 30633  0 03:57 pts/0    00:00:00 grep --color=auto postgres
[postgres@ip-10-90-10-49 ~]$


[postgres@ip-10-90-10-49 ~]$ netstat -lpn | grep post
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:5432              0.0.0.0:*                   LISTEN      30666/postgres
unix  2      [ ACC ]     STREAM     LISTENING     19992  30666/postgres      /tmp/.s.PGSQL.5432
[postgres@ip-10-90-10-49 ~]$


우선 postgres process 가 정상적으로 올라왔으며, 5432 Port 가 정상적으로 Listen 을 하고 있습니다. 

위의 테스트중 test db 를 생성하는 부분에서 문제가 발생을 하는데 이 부분은 추가로 확인해봐야 할듯 합니다. 


이상으로 PostgreSQL 의 소스설치에 대해서 간략하게 마무리를 하겠습니다. 



'Database > PostgreSQL' 카테고리의 다른 글

6. PostgreSQL 커널 리소스 관리  (0) 2017.11.03
5. PostgreSQL 데몬구동 설정 및 운영  (0) 2017.10.31
4. PostgreSQL 설치 시 요구사항  (0) 2017.10.31
2. PostgreSQL 의 역사  (0) 2017.10.27
1. PostgreSQL ?  (0) 2017.10.26

+ Recent posts