UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

PostgreSQL 8.3.3 install on RHEL5.2

PostgreSQL 8.3.3 install on RHEL5.2


0.改訂履歴

  • 2008.07.27 新規作成
  • 2008.09.21 8.3.3へバージョンアップ.

1.はじめに

 このドキュメントでは,PostgreSQLをRedHat Enterprise Linux 5.2(RHEL5.2)へインストールする手順を説明する.

 PostgreSQLをインストールする環境(gmakeのバージョン)の説明からconfigure,make等のインストール方法と,ldconfigによるライブラリの認識,initdbによる初期データベースを行う. 

2.環境の確認

  • インストールを行う前に,gmakeのバージョンを確認する.
[root@moon InstallBin]# gmake -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i686-redhat-linux-gnu
[root@moon InstallBin]#
  • gmakeは,3.76.1以上のバージョンが必要とされている.
  • PostgreSQL用のOSユーザを作成する
[root@moon InstallBin]# /usr/sbin/useradd postgres -d /home/postgres
[root@moon InstallBin]# passwd postgres
Changing password for user postgres.
New UNIX password: ■■■■■■■■■■
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password: ■■■■■■■■■
passwd: all authentication tokens updated successfully.
[root@moon InstallBin]#
  • ここで簡単なパスワード(postgre等)は付けない事.

3.モジュールの入手

  • モジュールをダウンロードする.
    • なお,新しいバージョンが出たら古い物は消える事があるので,その場合は公式サイトで最新版を確認する.
[root@moon InstallBin]# curl -O http://www.ring.gr.jp/pub/misc/db/postgresql/source/v
8.3.3/postgresql-8.3.3.tar.gz

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16.6M 100 16.6M 0 0 251k 0 0:01:08 0:01:08 --:--:-- 243k

[root@moon InstallBin]#
  • ダウンロードしたファイルを確認する.
[root@moon InstallBin]# ls -la postgresql-8.3.3.tar.gz 
-rw-r--r-- 1 root root 17500570 Sep 21 10:37 postgresql-8.3.3.tar.gz
[root@moon InstallBin]#
  • アーカイブを展開する
[root@moon InstallBin]# tar xfz postgresql-8.3.3.tar.gz 
[root@moon InstallBin]#
  • ファイルを確認する.
[root@moon InstallBin]# cd postgresql-8.3.3
[root@moon postgresql-8.3.3]# ls -la
total 1512
drwxrwxrwx 6 258 258 4096 Jun 9 09:58 .
drwxr-xr-x 4 root root 4096 Sep 21 10:39 ..
-rw-r--r-- 1 258 258 1192 Jan 2 2008 COPYRIGHT
-rw-r--r-- 1 258 258 3780 Feb 10 2007 GNUmakefile.in
-rw-r--r-- 1 258 258 609361 Jun 9 09:58 HISTORY
-rw-r--r-- 1 258 258 46251 Jun 9 09:58 INSTALL
-rw-r--r-- 1 258 258 1423 Jan 21 2007 Makefile
-rw-r--r-- 1 258 258 2026 Mar 6 2008 README
-rw-r--r-- 1 258 258 445 Apr 24 2004 aclocal.m4
drwxrwxrwx 2 258 258 4096 Sep 21 10:39 config
-rwxr-xr-x 1 258 258 775930 Jun 9 09:38 configure
-rw-r--r-- 1 258 258 51677 Jun 9 09:38 configure.in
drwxrwxrwx 37 258 258 4096 Sep 21 10:39 contrib
drwxrwxrwx 4 258 258 4096 Sep 21 10:39 doc
drwxrwxrwx 14 258 258 4096 Sep 21 10:39 src
[root@moon postgresql-8.3.3]#
  • confitureタイプだと判る.

4.configureの実行

  • configureを実行する.
[root@moon postgresql-8.3.3]# ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking which template to use... linux
checking whether to build with 64-bit integer date/time support... no
checking whether NLS is wanted... no
checking for default port number... 5432
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 ANSI C... none needed
checking if gcc supports -Wdeclaration-after-statement... yes
checking if gcc supports -Wendif-labels... yes
checking if gcc supports -fno-strict-aliasing... yes
checking if gcc supports -fwrapv... yes
configure: using CFLAGS=-O2 -Wall -Wmissing-prototypes -Wpointer-arith -
Winline -Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing -
fwrapv
checking whether the C compiler still works... yes
checking how to run the C preprocessor... gcc -E
checking allow thread-safe client libraries... no
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 for egrep... grep -E
configure: using CPPFLAGS= -D_GNU_SOURCE
configure: using LDFLAGS=
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/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 tar... /bin/tar
checking whether ln -s works... yes
checking for gawk... gawk
checking for bison... bison -y
configure: using bison (GNU Bison) 2.3
checking for flex... /usr/bin/flex
configure: using /usr/bin/flex version 2.5.4
checking for perl... /usr/bin/perl
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 shmget... none required
checking for -lreadline... yes (-lreadline -ltermcap)
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 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/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/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/shm.h usability... yes
checking sys/shm.h presence... yes
checking for sys/shm.h... yes
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 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 kernel/OS.h usability... no
checking kernel/OS.h presence... no
checking for kernel/OS.h... no
checking kernel/image.h usability... no
checking kernel/image.h presence... no
checking for kernel/image.h... no
checking SupportDefs.h usability... no
checking SupportDefs.h presence... no
checking for SupportDefs.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 preprocessor stringizing operator... yes
checking for signed types... yes
checking for working volatile... yes
checking for __func__... 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 struct cmsgcred... no
checking for struct fcred... no
checking for struct sockcred... no
checking for struct option... yes
checking for z_streamp... yes
checking for int timezone... yes
checking types of arguments for accept()... int, int, struct sockaddr *, size_
t *
checking whether gettimeofday takes only one argument... no
checking for cbrt... yes
checking for dlopen... yes
checking for fcvt... yes
checking for fdatasync... yes
checking for getpeereid... no
checking for getrlimit... yes
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 sysconf... yes
checking for towlower... yes
checking for utime... yes
checking for utimes... yes
checking for waitpid... yes
checking for wcstombs... yes
checking whether fdatasync is declared... yes
checking whether posix_fadvise 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... yese
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 fseeko... yes
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 strdup... yes
checking for strerror... yes
checking for strlcat... no
checking for strlcpy... no
checking for strtol... yes
checking for strtoul... yes
checking for unsetenv... yes
checking for getaddrinfo... yes
checking for getopt_long... yes
checking for rl_completion_append_character... yes
checking for rl_completion_matches... yes
checking for rl_filename_completion_function... yes
checking for replace_history_entry... 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 optreset... no
checking for strtoll... yes
checking for strtoull... yes
checking for atexit... yes
checking for _LARGEFILE_SOURCE value needed for large files... no
checking for fseeko... (cached) yes
checking test program... ok
checking whether long int is 64 bits... no
checking whether long long int is 64 bits... yes
checking snprintf format for long long int... %lld
checking for unsigned long... yes
checking size of unsigned long... 4
checking for size_t... yes
checking size of size_t... 4
checking for short... yes
checking alignment of short... 2
checking for int... yes
checking alignment of int... 4
checking for long... yes
checking alignment of long... 4
checking for long long int... yes
checking alignment of long long int... 4
checking for double... yes
checking alignment of double... 4
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 special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... 64
checking for _LARGE_FILES value needed for large files... no
checking for working memcmp... yes
checking for onsgmls... onsgmls
checking for openjade... openjade
checking for DocBook V4.2... yes
checking for DocBook stylesheets... /usr/share/sgml/docbook/dsssl-stylesheets
checking for collateindex.pl... /usr/bin/collateindex.pl
checking for sgmlspl... sgmlspl
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/interfaces/ecpg/include/ecpg_config.h
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/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
[root@moon postgresql-8.3.3]#
  • ライブラリ不足等の問題は出ていない.
  • gmakeでmakeを行う.
[root@moon postgresql-8.3.3]# gmake
gmake -C doc all
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/doc'
gzip -d -c man.tar.gz | /bin/tar xf -
/bin/tar: Read 1536 bytes from -
for file in man1/*.1; do \
mv $file $file.bak && \
sed -e 's/\\fR(l)/\\fR(7)/' $file.bak >$file && \
rm -f $file.bak || exit; \
done
/bin/sh ../config/mkinstalldirs man7
mkdir -p -- man7
for file in manl/*.l; do \
sed -e '/^\.TH/s/"l"/"7"/' \
-e 's/\\fR(l)/\\fR(7)/' \
$file >man7/`basename $file | sed 's/.l$/.7/'` || exit; \
done
gmake[1]: Leaving directory `/root/Download/postgresql-8.3.3/doc'
gmake -C src all
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/src'
gmake -C port all
gmake[2]: Entering directory `/root/Download/postgresql-8.3.3/src/port'
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Winline -Wdeclaration-
after-statement -Wendif-labels -fno-strict-aliasing -I../../src/port -
DFRONTEND -I../../src/include -D_GNU_SOURCE -c -o strlcat.o strlcat.c


〜略〜

gmake[2]: Leaving directory `/root/Download/postgresql-8.3.3/src/test/regress'
gmake[1]: Leaving directory `/root/Download/postgresql-8.3.3/src'
gmake -C config all
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/config'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/root/Download/postgresql-8.3.3/config'
All of PostgreSQL successfully made. Ready to install.
[root@moon postgresql-8.3.3]#
  • インストール可能と表示して完了している.
  • インストールを実行する.
[root@moon postgresql-8.3.3]# gmake install
gmake -C doc install
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/doc'
mkdir -p -- /usr/local/pgsql/doc/html
mkdir -p -- /usr/local/pgsql/man/man1 /usr/local/pgsql/man/man7
gzip -d -c ./postgres.tar.gz | ( cd /usr/local/pgsql/doc/html && /bin/tar xf - )
/bin/tar: Read 2560 bytes from -
for file in man1/*.1 man7/*.7 ; do \
/bin/sh ../config/install-sh -c -m 644 $file /usr/local/pgsql/man/$file
|| exit; \
done
gmake[1]: Leaving directory `/root/Download/postgresql-8.3.3/doc'
gmake -C src install
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/src'
/bin/sh ../config/mkinstalldirs '/usr/local/pgsql/lib/pgxs/src'

〜略〜

gmake -C config install
gmake[1]: Entering directory `/root/Download/postgresql-8.3.3/config'
mkdir -p -- /usr/local/pgsql/lib/pgxs/config
/bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/co
nfig/install-sh'
/bin/sh ../config/install-sh -c -m 755 ./mkinstalldirs '/usr/local/pgsql/lib/pgxs
/config/mkinstalldirs'
gmake[1]: Leaving directory `/root/Download/postgresql-8.3.3/config'
PostgreSQL installation complete.
[root@moon postgresql-8.3.3]#
  • インストールが完了した.

5.オーナの変更

  • インストールされたモジュールを確認する.
[root@moon postgresql-8.3.3]# cd /usr/local
[root@moon local]# ls -la
total 92
drwxr-xr-x 13 root root 4096 Sep 21 10:59 .
drwxr-xr-x 14 root root 4096 Sep 18 15:03 ..
drwxr-xr-x 15 root root 4096 Sep 21 10:24 apache2
drwxr-xr-x 2 root root 4096 Oct 11 2006 bin
drwxr-xr-x 2 root root 4096 Oct 11 2006 etc
drwxr-xr-x 2 root root 4096 Oct 11 2006 games
drwxr-xr-x 2 root root 4096 Oct 11 2006 include
drwxr-xr-x 2 root root 4096 Oct 11 2006 lib
drwxr-xr-x 2 root root 4096 Oct 11 2006 libexec
drwxr-xr-x 8 root root 4096 Sep 21 10:59 pgsql
drwxr-xr-x 2 root root 4096 Oct 11 2006 sbin
drwxr-xr-x 4 root root 4096 Sep 18 14:57 share
drwxr-xr-x 2 root root 4096 Oct 11 2006 src
[root@moon local]#
  • ファイルのオーナーがrootユーザになっているので,postgresユーザに変更する.
[root@moon local]# chown -R postgres:postgres pgsql 
[root@moon local]# cd pgsql
[root@moon pgsql]# ls -la
total 36
drwxr-xr-x 8 postgres postgres 4096 Sep 21 10:59 .
drwxr-xr-x 13 root root 4096 Sep 21 10:59 ..
drwxr-xr-x 2 postgres postgres 4096 Sep 21 10:59 bin
drwxr-xr-x 3 postgres postgres 4096 Sep 21 10:59 doc
drwxr-xr-x 6 postgres postgres 4096 Sep 21 10:59 include
drwxr-xr-x 3 postgres postgres 4096 Sep 21 10:59 lib
drwxr-xr-x 4 postgres postgres 4096 Sep 21 10:59 man
drwxr-xr-x 5 postgres postgres 4096 Sep 21 10:59 share
[root@moon pgsql]#
  • オーナーが変更された事が確認できた.

6.postgresユーザの設定追加

  • 次に,PostgreSQLのツールへのパスを設定する.
  • 今回はシェルにbashを使っているので,.bashrcファイルにパスを追加する.
  • まずは,postgresユーザの.bashrcファイルを確認する.
[root@moon pgsql]# cd /home/postgres 
[root@moon postgres]# ls -la
total 32
drwx------ 3 postgres postgres 4096 Sep 21 10:28 .
drwxr-xr-x 8 root root 4096 Sep 21 10:28 ..
-rw-r--r-- 1 postgres postgres 33 Sep 21 10:28 .bash_logout
-rw-r--r-- 1 postgres postgres 176 Sep 21 10:28 .bash_profile
-rw-r--r-- 1 postgres postgres 124 Sep 21 10:28 .bashrc
-rw-r--r-- 1 postgres postgres 515 Sep 21 10:28 .emacs
drwxr-xr-x 4 postgres postgres 4096 Sep 21 10:28 .mozilla
[root@moon postgres]#
  • パスは,bachrcファイルに記述する.他のシェルを利用している場合は,適時読み替える.
.bashrcへのパス設定
設定前
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions
設定後
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions

PATH=/usr/local/pgsql/bin:$PATH
  • 記述が正しいか,確認する.
  • まず,rootユーザからpostgresユーザにスイッチする.
[root@moon postgres]# su - postgres
[postgres@moon ~]$
  • パスを確認する.
[postgres@moon ~]$ env | grep PATH
PATH=/usr/local/pgsql/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/p
ostgres/bin
[postgres@moon ~]$ quit
[root@moon ~]#
  • パスが追加されている事が確認できた.

7.ライブラリパスを設定

  • 現在のライブラリパスを確認する.
[root@moon ~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@moon ~]#
  • インクルードファイルとなっているので,どのようなファイルがあるか確認する.
[root@moon ~]# ls -la /etc/ld.so.conf.d/
total 32
drwxr-xr-x 2 root root 4096 Sep 18 15:06 .
drwxr-xr-x 96 root root 12288 Sep 21 10:28 ..
-rw-r--r-- 1 root root 20 Sep 5 2007 qt-i386.conf
[root@moon ~]#
  • 今回は,qt関連のみ.
  • 念のため,ライブラリパスを確認してみる.
[root@moon ~]# cat /etc/ld.so.conf.d/qt-i386.conf 
/usr/lib/qt-3.3/lib
[root@moon ~]#
  • PostgreSQLのパスが設定されていない事が確認できた.
  • ライブラリパスを指定するファイルを作成する.
[root@moon ~]# echo /usr/local/pgsql/lib >> /etc/ld.so.conf.d/postgresql.i386.conf
[root@moon ~]# cat /etc/ld.so.conf.d/postgresql.i386.conf
/usr/local/pgsql/lib
[root@moon ~]#
  • ライブラリを再認識させる.
[root@moon ~]# /sbin/ldconfig
[root@moon ~]#
  • 認識されたか,確認する.
[root@moon ~]# /sbin/ldconfig -p|grep pgsql
libpq.so.5 (libc6) => /usr/local/pgsql/lib/libpq.so.5
libpq.so (libc6) => /usr/local/pgsql/lib/libpq.so
libpgtypes.so.3 (libc6) => /usr/local/pgsql/lib/libpgtypes.so.3
libpgtypes.so (libc6) => /usr/local/pgsql/lib/libpgtypes.so
libecpg_compat.so.3 (libc6) => /usr/local/pgsql/lib/libecpg_compat.so.3
libecpg_compat.so (libc6) => /usr/local/pgsql/lib/libecpg_compat.so
libecpg.so.6 (libc6) => /usr/local/pgsql/lib/libecpg.so.6
libecpg.so (libc6) => /usr/local/pgsql/lib/libecpg.so

[root@moon ~]#
  • ライブラリが認識された事が確認できた.

8.初期データベースの作成

  • ソフトウェアのインストールが終わったので,初期データベースを作成する.
  • 初期データベースとは,「データベースのデータベース」であり,データベースが自分自身を管理する為に作成されるデータベースの事である.
  • データベースの格納用ディレクトリを作成する.
[root@moon ~]# mkdir -p /db/pgsql/database
[root@moon ~]#
  • 作成したディレクトリのオーナーを変更する.
[root@moon ~]# chown -R postgres:postgres /db
[root@moon ~]#
  • postgresユーザにスイッチする.
[root@moon ~]# su - postgres 
[postgres@moon ~]$
  • データベースを作成する為にinitdbコマンドを実行する.
  • 今回は,文字コードをUTF-8として作成する.
[postgres@moon ~]$ /usr/local/pgsql/bin/initdb -D /db/pgsql/database --encoding=UTF-8
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 ja_JP.UTF-8.
initdb: could not find suitable text search configuration for locale ja_JP.UTF-8
The default text search configuration will be set to "simple".

fixing permissions on existing directory /db/pgsql/database ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers/max_fsm_pages ... 32MB/204800
creating configuration files ... ok
creating template1 database in /db/pgsql/database/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.

Success. You can now start the database server using:

/usr/local/pgsql/bin/postgres -D /db/pgsql/database
or
/usr/local/pgsql/bin/pg_ctl -D /db/pgsql/database -l logfile start

[postgres@moon ~]$
  • 作成されたデータベースファイルを確認する.
[postgres@moon ~]$ export LANG=C
[postgres@moon ~]$ ls -la /db/pgsql/database/
total 72
drwx------ 10 postgres postgres 4096 Sep 21 13:35 .
drwxr-xr-x 3 postgres postgres 4096 Sep 21 10:01 ..
-rw------- 1 postgres postgres 4 Sep 21 13:35 PG_VERSION
drwx------ 5 postgres postgres 4096 Sep 21 13:35 base
drwx------ 2 postgres postgres 4096 Sep 21 13:35 global
drwx------ 2 postgres postgres 4096 Sep 21 13:35 pg_clog
-rw------- 1 postgres postgres 3429 Sep 21 13:35 pg_hba.conf
-rw------- 1 postgres postgres 1460 Sep 21 13:35 pg_ident.conf
drwx------ 4 postgres postgres 4096 Sep 21 13:35 pg_multixact
drwx------ 2 postgres postgres 4096 Sep 21 13:35 pg_subtrans
drwx------ 2 postgres postgres 4096 Sep 21 13:35 pg_tblspc
drwx------ 2 postgres postgres 4096 Sep 21 13:35 pg_twophase
drwx------ 3 postgres postgres 4096 Sep 21 13:35 pg_xlog
-rw------- 1 postgres postgres 16591 Sep 21 13:35 postgresql.conf
[postgres@moon ~]$
  • ログ用ディレクトリを作成する.
[postgres@moon ~]$ mkdir /db/pgsql/database/log
[postgres@moon ~]$
  • ここまでの手順で,初期データベースの作成とデータベースが稼働した時にエラー等が書かれるログを格納するディレクトリの作成が完了した.

9.PostgreSQLの起動と終了

  • PostgreSQLの起動・終了をコントロールする為に,pg_ctlコマンドを使う.
  • pg_ctlコマンドが格納されている場所を確認する.
postgres@moon ~]$ locate pg_ctl
/usr/local/pgsql/bin/pg_ctl
/usr/local/pgsql/man/man1/pg_ctl.1
[postgres@moon ~]$
  • pg_ctlを使ってデータベースを起動する.
  • 起動する際には,-Dで初期データベースが格納されたディレクトリを指定し,-l(エル)でログファイルを指定する.
[postgres@moon ~]$ /usr/local/pgsql/bin/pg_ctl start -D /db/pgsql/database -l /
db/pgsql/database/log/postgresql.log

server starting
[postgres@moon ~]$
  • プロセスを確認して動作を確認する.
[postgres@moon ~]$ ps -ef|grep postgre
[postgres@moon ~]$ ps -ef|grep postgre
root 13843 5413 0 13:35 pts/0 00:00:00 su - postgres
postgres 13844 13843 0 13:35 pts/0 00:00:00 -bash
postgres 13922 1 4 13:42 pts/0 00:00:00 /usr/local/pgsql/bin/postgres
-D /db/pgsql/database

postgres 13924 13922 0 13:42 ? 00:00:00 postgres: writer process
postgres 13925 13922 0 13:42 ? 00:00:00 postgres: wal writer process
postgres 13926 13922 0 13:42 ? 00:00:00 postgres: autovacuum launcher
process
postgres 13927 13922 0 13:42 ? 00:00:00 postgres: stats collector
process
postgres 13928 13844 0 13:42 pts/0 00:00:00 ps -ef
postgres 13929 13844 0 13:42 pts/0 00:00:00 grep postgre
[postgres@moon ~]$
  • プロセスが起動している事が確認できた.
  • 次に,ステータスコマンドで確認する.
[postgres@moon ~]$ /usr/local/pgsql/bin/pg_ctl status -D /db/pgsql/database/
pg_ctl: server is running (PID: 13922)
/usr/local/pgsql/bin/postgres -D /db/pgsql/database

[postgres@moon ~]$
  • ログを確認する.
[postgres@moon ~]$ cat /db/pgsql/database/postgresql.log
LOG: database system was shut down at 2008-09-21 13:35:40 JST
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
[postgres@moon ~]$
  • PostgreSQLをシャットダウンする.
[postgres@moon ~]$ /usr/local/pgsql/bin/pg_ctl stop -D /db/pgsql/database/
waiting for server to shut down.... done
server stopped
[postgres@moon ~]$
  • プロセスを確認する.
[postgres@moon ~]$ ps -ef|grep postgre
root 13843 5413 0 13:35 pts/0 00:00:00 su - postgres
postgres 13844 13843 0 13:35 pts/0 00:00:00 -bash
postgres 13947 13844 0 13:49 pts/0 00:00:00 ps -ef
postgres 13948 13844 0 13:49 pts/0 00:00:00 grep postgre
[postgres@moon ~]$
  • プロセスは停止している.
  • ログファイルを確認する.
[postgres@moon ~]$ cat /db/pgsql/database/postgresql.log
LOG: database system was shut down at 2008-09-21 13:35:40 JST
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
LOG: received smart shutdown request
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
[postgres@moon ~]$
  • 正常にシャットダウンされている事が確認できた.

10.簡単に起動・停止・ステータス確認を行う設定

  • PostgreSQLを起動する時の記述を楽にする設定を行う.
  • 環境変数PGDATAにデータベースディレクトリを指定することで,pg_ctlコマンドを短くする事ができるので,次の様に.bashrcを修正する.
[postgres@moon ~]$ cd
[postgres@moon ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# User specific aliases and functions
PATH=/usr/local/pgsql/bin:$PATH
export PGDATA=/db/pgsql/database
alias pg_start="pg_ctl start -l /db/pgsql/database/log/postgresql.log"
alias pg_stop="pg_ctl stop"
alias pg_status='pg_ctl status'
[postgres@moon ~]$
  • 設定した内容を反映する.
[postgres@moon ~]$ . .bashrc
[postgres@moon ~]$
  • 反映されたか確認する.
[postgres@moon ~]$ env | grep PGDATA
PGDATA=/db/pgsql/database
[postgres@moon ~]$ alias | grep pg
alias pg_start='pg_ctl start -l /db/pgsql/database/log/postgresql.log'
alias pg_status='pg_ctl status'
alias pg_stop='pg_ctl stop'

[postgres@moon ~]$
  • 設定したコマンドを実行してみる.
[postgres@moon ~]$ pg_start
server starting
[postgres@moon ~]$ pg_status
pg_ctl: server is running (PID: 14354)
/usr/local/pgsql/bin/postgres
[postgres@moon ~]$ ps -ef|grep postgre
root 14292 5413 0 14:34 pts/0 00:00:00 su - postgres
postgres 14293 14292 0 14:34 pts/0 00:00:00 -bash
postgres 14354 1 2 14:37 pts/0 00:00:00 /usr/local/pgsql/bin/postgres
postgres 14356 14354 0 14:37 ? 00:00:00 postgres: writer process
postgres 14357 14354 0 14:37 ? 00:00:00 postgres: wal writer process
postgres 14358 14354 0 14:37 ? 00:00:00 postgres: autovacuum launcher
process
postgres 14359 14354 0 14:37 ? 00:00:00 postgres: stats collector
process
postgres 14361 14293 0 14:37 pts/0 00:00:00 ps -ef
postgres 14362 14293 0 14:37 pts/0 00:00:00 grep postgre
[postgres@moon ~]$ pg_stop
waiting for server to shut down.... done
server stopped
[postgres@moon ~]$ ps -ef|grep postgre
root 14292 5413 0 14:34 pts/0 00:00:00 su - postgres
postgres 14293 14292 0 14:34 pts/0 00:00:00 -bash
postgres 14365 14293 0 14:37 pts/0 00:00:00 ps -ef
postgres 14366 14293 0 14:37 pts/0 00:00:00 grep postgre
[postgres@moon ~]$ pg_status
pg_ctl: no server running
[postgres@moon ~]$
  • 動作する事が確認できた.


広告スペース
Google