【PostgreSQL】ソースファイルをコンパイルして CentOS7 系にインストールする手順【CentOS7、Red Hat 7】

公開日時:2019年04月04日 / 最終更新日時:2019年04月21日

旧バージョンの PostgreSQL をダウンロードして、ソースコードをコンパイルしてインストールする手順です。

将来の運用を考えると、基本的には yum コマンドでパッケージをインストールしたいですが、やむを得ない事情(アプリが昔のバージョンでしか稼働しない、且つ開発元がアプリのバージョンアップできないなど特殊な事情)の場合のみ、ソースファイルをコンパイルしてからのインストールをしたいところです。

 

 

今回実行する Red Hat 環境

今回実行する Red Hat 環境は 7.6 です。

[root@redhat7 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.6 (Maipo)
[root@redhat7 ~]#

 

 

現在 PostgreSQL はインストールされていません。

もしインストールされていた場合は、別途 PostgreSQL をアンインストールします。

[root@redhat7 ~]# rpm -qa | grep postgres
[root@redhat7 ~]#

 

 

 

PostgreSQL ソースファイルのダウンロード

PostgreSQL の各バージョンのソースファイルは以下の URL からダウンロードできます。

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

 

以下のように wget コマンドでもソースファイルをダウンロードできます。

[root@redhat7 ~]# wget https://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz 
--2019-04-02 23:00:48--  https://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz 
ftp.postgresql.org (ftp.postgresql.org) をDNSに問いあわせています... 87.238.57.227, 204.145.124.244, 217.196.149.55, ... 
ftp.postgresql.org (ftp.postgresql.org)|87.238.57.227|:443 に接続しています...  接続しました。 
HTTP による接続要求を送信しました、応答を待っています... 200 OK 
長さ: 21865589 (21M) [application/x-gzip] 
`postgresql-9.3.4.tar.gz' に保存中 
 
100%[======================================>] 21,865,589  1.23MB/s 時間 15s 
 
2019-04-02 23:01:05 (1.42 MB/s) - `postgresql-9.3.4.tar.gz' へ保存完了 [21865589/21865589] 
 
[root@redhat7 ~]#

 

今回は、例として PostgreSQL 9.3 ソースファイルのダウンロードをしてコンパイルしてインストールする手順を解説します。

 

 

 

PostgreSQL ソースファイルをコンパイルする前の準備

PostgreSQL ソースファイルをコンパイルする前に、以下のパッケージをインストールしておきます。

 

■gcc のインストール

[root@redhat7 postgres]# yum install gcc

 

■readline のインストール

[root@redhat7 postgres]# yum install readline readline-devel

 

 

■flex のインストール

[root@redhat7 ~]# yum install flex

 

 

■perl のインストール

[root@redhat7 ~]# yum install perl

 

 

■zlib-devel のインストール

[root@redhat7 ~]# yum install zlib-devel

 

 

 

PostgreSQL の設計

簡単ですが、PostgreSQL の設計をします。

今回は以下のように設計します。

 

 

postgres アカウントの作成

PostgreSQL をインストールする前に postgres アカウントを作成します。

[test@redhat7 ~]$ sudo su - 
最終ログイン: 2019/04/02 (火) 22:30:17 JST日時 pts/0 
[root@redhat7 ~]# useradd postgres ← postgres アカウントを作成します。
[root@redhat7 ~]# passwd postgres ← postgres アカウントのパスワードを設定します。
ユーザー postgres のパスワードを変更。 
新しいパスワード: ← postgres アカウントのパスワードを入力します。 
新しいパスワードを再入力してください: ← postgres アカウントのパスワードを入力します。 
passwd: すべての認証トークンが正しく更新できました。 
[root@redhat7 ~]#

 

 

 

 

PostgreSQL ソースファイルの展開

ダウンロードした PostgreSQL のソースファイルの所有者を postgres に変更します。

[root@redhat7 ~]# ls 
anaconda-ks.cfg  original-ks.cfg  postgresql-9.3.4.tar.gz 
[root@redhat7 ~]# cp postgresql-9.3.4.tar.gz /home/postgres/ ← postgresql-9.3.4.tar.gz を postgres アカウントのホームディレクトリにコピーします。
[root@redhat7 ~]# cd /home/postgres/ 
[root@redhat7 postgres]# ls -l 
合計 21356 
-rw-r--r--. 1 root root 21865589  4月  2 23:03 postgresql-9.3.4.tar.gz 
[root@redhat7 postgres]# chown postgres:postgres postgresql-9.3.4.tar.gz ← ソースファイルの所有者を postgres に変更します。 
[root@redhat7 postgres]# ls -l 
合計 21356 
-rw-r--r--. 1 postgres postgres 21865589  4月  2 23:03 postgresql-9.3.4.tar.gz ← ソースファイルの所有者が postgres に変わっています。  
[root@redhat7 postgres]#

 

 

postgresql アカウントにスイッチして、tar コマンドでソースファイルを展開します。

[root@redhat7 postgres]# su - postgres 
[postgres@redhat7 ~]$ tar zxvf postgresql-9.3.4.tar.gz

 

 

 

PostgreSQL ソースファイルのコンパイル

configure スクリプトを実行して makefile を作成します。

[postgres@redhat7 ~]$ cd postgresql-9.3.4 
[postgres@redhat7 postgresql-9.3.4]$ ./configure 
checking build system type... x86_64-unknown-linux-gnu 
checking host system type... x86_64-unknown-linux-gnu 
checking which template to use... linux 
checking whether to build with 64-bit integer date/time support... yes 
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... gcc 
checking for C compiler default output file name... a.out 
checking whether the C compiler works... yes 
checking whether we are cross compiling... no 
checking for suffix of executables... 
checking for suffix of object files... o 
checking whether we are using the GNU C compiler... yes 
checking whether gcc accepts -g... yes 
checking for gcc option to accept ISO C89... none needed 
checking whether gcc supports -Wdeclaration-after-statement... yes 
checking whether gcc supports -Wendif-labels... yes 
checking whether gcc supports -Wmissing-format-attribute... yes 
checking whether gcc supports -Wformat-security... yes 
checking whether gcc supports -fno-strict-aliasing... yes 
checking whether gcc supports -fwrapv... yes 
checking whether gcc supports -fexcess-precision=standard... yes 
checking whether gcc supports -funroll-loops... yes 
checking whether gcc supports -ftree-vectorize... yes 
checking whether the C compiler still works... yes 
checking how to run the C preprocessor... gcc -E 
checking allow thread-safe client libraries... yes 
checking whether to build with Tcl... no 
checking whether to build Perl modules... no 
checking whether to build Python modules... no 
checking whether to build with GSSAPI support... no 
checking whether to build with Kerberos 5 support... no 
checking whether to build with PAM support... no 
checking whether to build with LDAP support... no 
checking whether to build with Bonjour support... no 
checking whether to build with OpenSSL support... no 
checking whether to build with SELinux support... no 
checking for grep that handles long lines and -e... /bin/grep 
checking for egrep... /bin/grep -E 
checking for ld used by GCC... /bin/ld 
checking if the linker (/bin/ld) is GNU ld... yes 
checking for ranlib... ranlib 
checking for strip... strip 
checking whether it is possible to strip libraries... yes 
checking for ar... ar 
checking for a BSD-compatible install... /bin/install -c 
checking for tar... /bin/tar 
checking whether ln -s works... yes 
checking for gawk... gawk 
checking for a thread-safe mkdir -p... /bin/mkdir -p 
checking for bison... /bin/bison 
configure: using bison (GNU Bison) 3.0.4 
checking for flex... /bin/flex 
configure: using flex 2.5.37 
checking for perl... /bin/perl 
configure: using perl 5.16.3 
checking for main in -lm... yes 
checking for library containing setproctitle... no 
checking for library containing dlopen... -ldl 
checking for library containing socket... none required 
checking for library containing shl_load... no 
checking for library containing getopt_long... none required 
checking for library containing crypt... -lcrypt 
checking for library containing fdatasync... none required 
checking for library containing gethostbyname_r... none required 
checking for library containing shmget... none required 
checking for library containing readline... -lreadline 
checking for inflate in -lz... yes 
checking for ANSI C header files... yes 
checking for sys/types.h... yes 
checking for sys/stat.h... yes 
checking for stdlib.h... yes 
checking for string.h... yes 
checking for memory.h... yes 
checking for strings.h... yes 
checking for inttypes.h... yes 
checking for stdint.h... yes 
checking for unistd.h... yes 
checking crypt.h usability... yes 
checking crypt.h presence... yes 
checking for crypt.h... yes 
checking dld.h usability... no 
checking dld.h presence... no 
checking for dld.h... no 
checking fp_class.h usability... no 
checking fp_class.h presence... no 
checking for fp_class.h... no 
checking getopt.h usability... yes 
checking getopt.h presence... yes 
checking for getopt.h... yes 
checking ieeefp.h usability... no 
checking ieeefp.h presence... no 
checking for ieeefp.h... no 
checking ifaddrs.h usability... yes 
checking ifaddrs.h presence... yes 
checking for ifaddrs.h... yes 
checking langinfo.h usability... yes 
checking langinfo.h presence... yes 
checking for langinfo.h... yes 
checking poll.h usability... yes 
checking poll.h presence... yes 
checking for poll.h... yes 
checking pwd.h usability... yes 
checking pwd.h presence... yes 
checking for pwd.h... yes 
checking sys/ioctl.h usability... yes 
checking sys/ioctl.h presence... yes 
checking for sys/ioctl.h... yes 
checking sys/ipc.h usability... yes 
checking sys/ipc.h presence... yes 
checking for sys/ipc.h... yes 
checking sys/poll.h usability... yes 
checking sys/poll.h presence... yes 
checking for sys/poll.h... yes 
checking sys/pstat.h usability... no 
checking sys/pstat.h presence... no 
checking for sys/pstat.h... no 
checking sys/resource.h usability... yes 
checking sys/resource.h presence... yes 
checking for sys/resource.h... yes 
checking sys/select.h usability... yes 
checking sys/select.h presence... yes 
checking for sys/select.h... yes 
checking sys/sem.h usability... yes 
checking sys/sem.h presence... yes 
checking for sys/sem.h... yes 
checking sys/shm.h usability... yes 
checking sys/shm.h presence... yes 
checking for sys/shm.h... yes 
checking sys/socket.h usability... yes 
checking sys/socket.h presence... yes 
checking for sys/socket.h... yes 
checking sys/sockio.h usability... no 
checking sys/sockio.h presence... no 
checking for sys/sockio.h... no 
checking sys/tas.h usability... no 
checking sys/tas.h presence... no 
checking for sys/tas.h... no 
checking sys/time.h usability... yes 
checking sys/time.h presence... yes 
checking for sys/time.h... yes 
checking sys/un.h usability... yes 
checking sys/un.h presence... yes 
checking for sys/un.h... yes 
checking termios.h usability... yes 
checking termios.h presence... yes 
checking for termios.h... yes 
checking ucred.h usability... no 
checking ucred.h presence... no 
checking for ucred.h... no 
checking utime.h usability... yes 
checking utime.h presence... yes 
checking for utime.h... yes 
checking wchar.h usability... yes 
checking wchar.h presence... yes 
checking for wchar.h... yes 
checking wctype.h usability... yes 
checking wctype.h presence... yes 
checking for wctype.h... yes 
checking for net/if.h... yes 
checking for sys/ucred.h... no 
checking netinet/in.h usability... yes 
checking netinet/in.h presence... yes 
checking for netinet/in.h... yes 
checking for netinet/tcp.h... yes 
checking readline/readline.h usability... yes 
checking readline/readline.h presence... yes 
checking for readline/readline.h... yes 
checking readline/history.h usability... yes 
checking readline/history.h presence... yes 
checking for readline/history.h... yes 
checking zlib.h usability... yes 
checking zlib.h presence... yes 
checking for zlib.h... yes 
checking whether byte ordering is bigendian... no 
checking for an ANSI C-conforming const... yes 
checking for inline... inline 
checking for quiet inline (no complaint if unreferenced)... yes 
checking for preprocessor stringizing operator... yes 
checking for flexible array members... yes 
checking for signed types... yes 
checking for working volatile... yes 
checking for __func__... yes 
checking for _Static_assert... yes 
checking for __builtin_types_compatible_p... yes 
checking for __builtin_constant_p... yes 
checking for __builtin_unreachable... yes 
checking for __VA_ARGS__... yes 
checking whether struct tm is in sys/time.h or time.h... time.h 
checking for struct tm.tm_zone... yes 
checking for tzname... yes 
checking for union semun... no 
checking for struct sockaddr_un... yes 
checking for struct sockaddr_storage... yes 
checking for struct sockaddr_storage.ss_family... yes 
checking for struct sockaddr_storage.__ss_family... no 
checking for struct sockaddr_storage.ss_len... no 
checking for struct sockaddr_storage.__ss_len... no 
checking for struct sockaddr.sa_len... no 
checking for struct addrinfo... yes 
checking for intptr_t... yes 
checking for uintptr_t... yes 
checking for long long int... yes 
checking for locale_t... yes 
checking for struct cmsgcred... no 
checking for struct option... yes 
checking for z_streamp... yes 
checking for special C compiler options needed for large files... no 
checking for _FILE_OFFSET_BITS value needed for large files... no 
checking size of off_t... 8 
checking for int timezone... yes 
checking types of arguments for accept()... int, int, struct sockaddr *, socklen_t * 
checking whether gettimeofday takes only one argument... no 
checking for cbrt... yes 
checking for dlopen... yes 
checking for fdatasync... yes 
checking for getifaddrs... yes 
checking for getpeerucred... no 
checking for getrlimit... yes 
checking for mbstowcs_l... no 
checking for memmove... yes 
checking for poll... yes 
checking for pstat... no 
checking for readlink... yes 
checking for setproctitle... no 
checking for setsid... yes 
checking for sigprocmask... yes 
checking for symlink... yes 
checking for sync_file_range... yes 
checking for towlower... yes 
checking for utime... yes 
checking for utimes... yes 
checking for wcstombs... yes 
checking for wcstombs_l... no 
checking for fseeko... yes 
checking for _LARGEFILE_SOURCE value needed for large files... no 
checking for posix_fadvise... yes 
checking whether posix_fadvise is declared... yes 
checking whether fdatasync is declared... yes 
checking whether strlcat is declared... no 
checking whether strlcpy is declared... no 
checking whether F_FULLFSYNC is declared... no 
checking for struct sockaddr_in6... yes 
checking for PS_STRINGS... no 
checking for snprintf... yes 
checking for vsnprintf... yes 
checking whether snprintf is declared... yes 
checking whether vsnprintf is declared... yes 
checking for isinf... yes 
checking for crypt... yes 
checking for fls... no 
checking for getopt... yes 
checking for getrusage... yes 
checking for inet_aton... yes 
checking for random... yes 
checking for rint... yes 
checking for srandom... yes 
checking for strerror... yes 
checking for strlcat... no 
checking for strlcpy... no 
checking for unsetenv... yes 
checking for getpeereid... no 
checking for getaddrinfo... yes 
checking for getopt_long... yes 
checking for sigsetjmp... yes 
checking whether sys_siglist is declared... yes 
checking for syslog... yes 
checking syslog.h usability... yes 
checking syslog.h presence... yes 
checking for syslog.h... yes 
checking for opterr... yes 
checking for optreset... no 
checking for strtoll... yes 
checking for strtoull... yes 
checking for builtin locking functions... yes 
checking for rl_completion_append_character... yes 
checking for rl_completion_matches... yes 
checking for rl_filename_completion_function... yes 
checking for append_history... yes 
checking for history_truncate_file... yes 
checking for the pthreads library -lpthreads... no 
checking whether pthreads work without any flags... no 
checking whether pthreads work with -Kthread... no 
checking whether pthreads work with -kthread... no 
checking for the pthreads library -llthread... no 
checking whether pthreads work with -pthread... yes 
checking whether pthreads work with -pthreads... no 
checking whether pthreads work with -mthreads... no 
checking for the pthreads library -lpthread... yes 
checking whether pthreads work with --thread-safe... no 
checking whether pthreads work with -mt... no 
checking for the pthreads library -lpthreadGC2... no 
checking pthread.h usability... yes 
checking pthread.h presence... yes 
checking for pthread.h... yes 
checking for strerror_r... yes 
checking for getpwuid_r... yes 
checking for gethostbyname_r... yes 
checking whether getpwuid_r takes a fifth argument... yes 
checking whether strerror_r returns int... no 
checking test program... ok 
checking whether long int is 64 bits... yes 
checking size of void *... 8 
checking size of size_t... 8 
checking size of long... 8 
checking whether to build with float4 passed by value... yes 
checking whether to build with float8 passed by value... yes 
checking alignment of short... 2 
checking alignment of int... 4 
checking alignment of long... 8 
checking alignment of double... 8 
checking for int8... no 
checking for uint8... no 
checking for int64... no 
checking for uint64... no 
checking for sig_atomic_t... yes 
checking for POSIX signal interface... yes 
checking for working memcmp... yes 
checking for onsgmls... no 
checking for nsgmls... no 
checking for openjade... no 
checking for jade... no 
checking for DocBook V4.2... no 
checking for DocBook stylesheets... no 
checking for collateindex.pl... no 
checking for xsltproc... xsltproc 
checking for osx... no 
checking for sgml2xml... no 
checking for sx... no 
checking thread safety of required library functions... yes 
checking whether gcc supports -Wl,--as-needed... yes 
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) 
configure: using CFLAGS=-O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard 
configure: using CPPFLAGS= -D_GNU_SOURCE 
configure: using LDFLAGS=  -Wl,--as-needed 
configure: creating ./config.status 
config.status: creating GNUmakefile 
config.status: creating src/Makefile.global 
config.status: creating src/include/pg_config.h 
config.status: creating src/include/pg_config_ext.h 
config.status: src/include/pg_config_ext.h is unchanged 
config.status: creating src/interfaces/ecpg/include/ecpg_config.h 
config.status: src/interfaces/ecpg/include/ecpg_config.h is unchanged 
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s 
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c 
config.status: linking src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c 
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c 
config.status: linking src/backend/port/unix_latch.c to src/backend/port/pg_latch.c 
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h 
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h 
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port 
[postgres@redhat7 postgresql-9.3.4]$

 

 

 

make コマンドでコンパイルを実行します。

[postgres@redhat7 postgresql-9.3.4]$ make

 

 

 

インストール前にチェックをします。

[postgres@redhat7 postgresql-9.3.4]$ make check

 

 

 

PostgreSQL のインストール

make install で PostgreSQL をインストールします。

/usr ディレクトリ配下にアクセスする必要があるため、sudo コマンドで実行します。

[postgres@redhat7 postgresql-9.3.4]$ sudo make install

 

 

 

PostgreSQL インストール後の確認および設定

インストール環境を確認します。

[postgres@redhat7 pgsql]$ pwd 
/usr/local/pgsql 
[postgres@redhat7 pgsql]$ ls 
bin  include  lib  share 
[postgres@redhat7 pgsql]$

 

 

 

環境変数の設定

postgres アカウントの環境変数を設定します。

[postgres@redhat7 pgsql]$ vi ~/.bashrc

# .bashrc 
# Source global definitions 
if [ -f /etc/bashrc ]; then 
        . /etc/bashrc 
fi 
 
# Uncomment the following line if you don't like systemctl's auto-paging feature 

# export SYSTEMD_PAGER= 
 
# User specific aliases and functions 
 
export PATH="$PATH":/usr/local/pgsql/bin 
export POSTGRES_HOME=/usr/local/pgsql 
export PGLIB=$POSTGRES_HOME/lib 
export PGDATA=$POSTGRES_HOME/data 
export MANPATH="$MANPATH":$POSTGRES_HOME/man 
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$PGLIB"

 

 

.bashrc の設定変更を反映します。

[postgres@redhat7 pgsql]$ source ~/.bashrc
[postgres@redhat7 pgsql]$

 

/usr/loca/pgsql ディレクトリ配下の所有者を postgres に変更します。

[postgres@redhat7 local]$ sudo chown -R postgres:postgres /usr/local/pgsql 
[postgres@redhat7 local]$ ls -l 
合計 0 
drwxr-xr-x. 2 root     root      6 12月 15  2017 bin 
drwxr-xr-x. 2 root     root      6 12月 15  2017 etc 
drwxr-xr-x. 2 root     root      6 12月 15  2017 games 
drwxr-xr-x. 2 root     root      6 12月 15  2017 include 
drwxr-xr-x. 2 root     root      6 12月 15  2017 lib 
drwxr-xr-x. 2 root     root      6 12月 15  2017 lib64 
drwxr-xr-x. 2 root     root      6 12月 15  2017 libexec 
drwxr-xr-x. 6 postgres postgres 56  4月  2 23:33 pgsql 
drwxr-xr-x. 2 root     root      6 12月 15  2017 sbin 
drwxr-xr-x. 5 root     root     49 10月 17 21:18 share 
drwxr-xr-x. 2 root     root      6 12月 15  2017 src 
[postgres@redhat7 local]$

 

 

 

データベースの初期化

initdb コマンドでデータベースを初期化します。

[postgres@redhat7 local]$ initdb --no-locale

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 "C". 
The default database encoding has accordingly been set to "SQL_ASCII". 
The default text search configuration will be set to "english". 
 
Data page checksums are disabled. 
 
creating directory /usr/local/pgsql/data ... ok 
creating subdirectories ... ok 
selecting default max_connections ... 100 
selecting default shared_buffers ... 128MB 
creating configuration files ... ok 
creating template1 database in /usr/local/pgsql/data/base/1 ... ok 
initializing pg_authid ... ok 
initializing dependencies ... ok 
creating system views ... ok 
loading system objects' descriptions ... ok 
creating collations ... ok 
creating conversions ... ok 
creating dictionaries ... ok 
setting privileges on built-in objects ... ok 
creating information schema ... ok 
loading PL/pgSQL server-side language ... ok 
vacuuming database template1 ... ok 
copying template1 to template0 ... ok 
copying template1 to postgres ... 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: 
 
    postgres -D /usr/local/pgsql/data 
or 
    pg_ctl -D /usr/local/pgsql/data -l logfile start 
 
[postgres@redhat7 local]$

 

 

 

PostgreSQL サーバーのスタート

以下のコマンドで PostgreSQL サーバーを起動します。

[postgres@redhat7 local]$ postgres -D /usr/local/pgsql/data 
LOG:  database system was shut down at 2019-04-02 23:50:30 JST 
LOG:  database system is ready to accept connections 
LOG:  autovacuum launcher started

 

 

プロセスを確認します。

[root@redhat7 ~]# ps -efwww | grep postgres 
root     12037  6345  0 23:27 pts/0    00:00:00 su - postgres 
postgres 12038 12037  0 23:27 pts/0    00:00:00 -bash 
postgres 22893 12038  0 23:51 pts/0    00:00:00 postgres -D /usr/local/pgsql/data 
postgres 22895 22893  0 23:51 ?        00:00:00 postgres: checkpointer process   
postgres 22896 22893  0 23:51 ?        00:00:00 postgres: writer process 
postgres 22897 22893  0 23:51 ?        00:00:00 postgres: wal writer process 
postgres 22898 22893  0 23:51 ?        00:00:00 postgres: autovacuum launcher process 
postgres 22899 22893  0 23:51 ?        00:00:00 postgres: stats collector process 
root     22944 22926  0 23:53 pts/1    00:00:00 grep --color=auto postgres 
[root@redhat7 ~]#

 

 

 

動作確認

psql コマンドで動作確認をします。

[postgres@redhat7 ~]$ psql 
psql (9.3.4) 
Type "help" for help. 
 
postgres=# \l 
                             List of databases 
   Name    |  Owner   | Encoding  | Collate | Ctype |   Access privileges 
-----------+----------+-----------+---------+-------+----------------------- 
 postgres  | postgres | SQL_ASCII | C       | C     | 
 template0 | postgres | SQL_ASCII | C       | C     | =c/postgres          + 
           |          |           |         |       | postgres=CTc/postgres 
 template1 | postgres | SQL_ASCII | C       | C     | =c/postgres          + 
           |          |           |         |       | postgres=CTc/postgres 
(3 rows) 
 
postgres=#

 

 

 

起動スクリプトの作成

新規で「/usr/lib/systemd/system/postgresql.service」を作成して起動スクリプトを作成します。 

[root@redhat7 ~]# vi /usr/lib/systemd/system/postgresql.service

# It's not recommended to modify this file in-place, because it will be 
# overwritten during package upgrades.  If you want to customize, the 
# best way is to create a file "/etc/systemd/system/postgresql.service", 
# containing 
#   .include /lib/systemd/system/postgresql.service 
#   ...make your changes here... 
# For more info about custom unit files, see 
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F 
 
# For example, if you want to change the server's port number to 5433, 
# create a file named "/etc/systemd/system/postgresql.service" containing: 
#   .include /lib/systemd/system/postgresql.service 
#   [Service] 
#   Environment=PGPORT=5433 
# This will override the setting appearing below. 
 
# Note: changing PGPORT or PGDATA will typically require adjusting SELinux 
# configuration as well; see /usr/share/doc/postgresql-*/README.rpm-dist. 
 
# Note: do not use a PGDATA pathname containing spaces, or you will 
# break postgresql-setup. 
 
# Note: in F-17 and beyond, /usr/lib/... is recommended in the .include line 
# though /lib/... will still work. 
 
[Unit] 
Description=PostgreSQL database server 
After=network.target 
 
[Service] 
Type=forking 
 
User=postgres 
Group=postgres 
 
# Port number for server to listen on 
Environment=PGPORT=5432 
 
# Location of database directory 
Environment=PGDATA=/usr/local/pgsql/data 
 
# Where to send early-startup messages from the server (before the logging 
# options of postgresql.conf take effect) 
# This is normally controlled by the global default set by systemd 
# StandardOutput=syslog 
 
# Disable OOM kill on the postmaster 
OOMScoreAdjust=-1000 
 
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300 
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast 
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s 
 
# Give a reasonable amount of time for the server to start up/shut down 
TimeoutSec=300 
 
[Install] 
WantedBy=multi-user.target 

 

 

起動スクリプトの作成を反映させます。

[root@redhat7 ~]# systemctl daemon-reload 

 

 

 

PostgreSQL 起動確認

作成した起動スクリプトの起動確認をします。

[root@redhat7 ~]# systemctl start postgresql.service 
[root@redhat7 ~]# systemctl status postgresql.service 
● postgresql.service - PostgreSQL database server 
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled) 
   Active: active (running) since 水 2019-04-03 00:07:01 JST; 5s ago 
  Process: 23033 ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -o -p ${PGPORT} -w -t 300 (code=exited, status=0/SUCCESS) 
 Main PID: 23036 (postgres) 
   CGroup: /system.slice/postgresql.service 
           tq23036 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data -p 5432 
           tq23038 postgres: checkpointer process 
           tq23039 postgres: writer process 
           tq23040 postgres: wal writer process 
           tq23041 postgres: autovacuum launcher process 
           mq23042 postgres: stats collector process 
 
 4月 03 00:07:00 redhat7.ap-northeast-1.compute.internal systemd[1]: Starting PostgreSQL database server... 
 4月 03 00:07:00 redhat7.ap-northeast-1.compute.internal pg_ctl[23033]: LOG:  database system was shut down at 2019-04...JST 
 4月 03 00:07:00 redhat7.ap-northeast-1.compute.internal pg_ctl[23033]: LOG:  database system is ready to accept connections 
 4月 03 00:07:00 redhat7.ap-northeast-1.compute.internal pg_ctl[23033]: LOG:  autovacuum launcher started 
 4月 03 00:07:01 redhat7.ap-northeast-1.compute.internal systemd[1]: Started PostgreSQL database server. 
Hint: Some lines were ellipsized, use -l to show in full. 
[root@redhat7 ~]#

 

 

 

トラブルシューティング

「configure: error: zlib library not found」のエラーメッセージが出力されて configure スクリプトの実行が失敗した場合です。

[postgres@redhat7 postgresql-9.3.4]$ ./configure 

 

~ 省略 ~

configure: error: zlib library not found 
If you have zlib already installed, see config.log for details on the 
failure.  It is possible the compiler isn't looking in the proper directory. 
Use --without-zlib to disable zlib support. 
[postgres@redhat7 postgresql-9.3.4]$

 

 

zlib ではなく、zlib-devel をインストールします。

[root@redhat7 ~]# yum install zlib-devel

 

 

Posted by 100%レンタルサーバーを使いこなすサイト管理人

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

AlphaOmega Captcha Medica  –  What Do You See?
     
 

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

Secured By miniOrange