Denbun POP version Manual
User's Manual | Administrator's Manual | Installation Guide | Initial Settings Guide
Back to Menu
 

Installing and configuring database (PostgreSQL)

PostgreSQL is an open source RDBMS (Relational Database Management System). Please refer the official web site (http://www.postgresql.jp/) for more information about PostgreSQL

Please refer the system requirements for the version that Denbun supports.
1. Expand Package
Use su command to switch to the root user.

[guest@xxxxxx guest]# su
Password:

Expand the file you transferred by FTP.In this example, it assumes that the file exists in "/home/guest" directory.

[root@xxxxxx guest]# cd /usr/local/src
[root@xxxxxx src]# tar xvzf /home/guest/postgresql-9.2.x.tar.gz

After the expansion, a directory named "postgresql-9.2.x" is created in "/usr/local/src" directory.
2. Install Package
To configure the package, use configure scripts.
In this example, use the default with no command line options.
Move to the directory you expand the package and run the configure script.

[root@xxxxxx src]# cd /usr/local/src/postgresql-9.2.x/
[root@xxxxxx postgresql-9.2.x]# ./configure


Make the package.User GNU make to make the package.It takes 5 to 30 minutes for the making (it depends on hardware).

[root@xxxxxx postgresql-9.2.x]# gmake
      .
      .(Omitted)
      .
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/usr/local/src/postgresql-9.2.x/config'.
All of PostgreSQL successfully made. Ready to install.
[root@xxxxxx postgresql-9.2.x]#

After the making, it is ready to perform regression tests to test for the SQL implementation.
The regression tests cannot be run with the super user (root). You should use any non administrative user.In this example, the user "neo" is used.
[root@xxxxxx postgresql-9.2.x]# su neo
[neo@xxxxxx postgresql-9.2.x]# gmake check
      .
      .(Omitted)
      .
=======================
 All 131 tests passed.
=======================

gmake[1]: Leaving directory `/usr/local/src/postgresql-9.2.x/src/test/regress'.
[neo@xxxxxx postgresql-9.2.x]#


Now, it is ready to install the package.This step requires the super user (root).
[neo@xxxxxx postgresql-9.2.x]$ su
Password:
[root@xxxxxx postgresql-9.2.x]# gmake install
      .
      .(Omitted)
      .
/bin/sh ../config/install-sh -c -m 755 ./install-sh '/usr/local/pgsql/lib/pgxs/config/install-sh'
gmake[1]: Leaving directory `/usr/local/src/postgresql-9.2.x/config'.
PostgreSQL installation complete.
[root@xxxxxx postgresql-9.2.x]#

After the checking the installation, use gmake clean command to cleaning.This command deletes unnecessary files and makes free space.
[root@xxxxxx postgresql-9.2.x]# gmake clean
3. Create User Named "dnpwml"
After the installation of PostgreSQL, create an administrative user.

 

[root@xxxxxx postgresql-9.2.x]# useradd postgres

Use passwd command to set the password.

The administrative user will use administrative commands of PostgreSQL, set the PATH in the environment variable of the user "postgres".
Normally, edit the file ".bash_profile" in the home directory of the user by using an editor such as vi.
[root@xxxxxx postgresql-9.2.x]# cd /home/postgres
[root@xxxxxx postgres]# vi .bash_profile

# .bash_profile

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

# User specific environment and startup programs

PATH=/usr/local/pgsql/bin:$PATH:$HOME/bin <-Add

export PATH
4. Create Database
Create a PostgreSQL database
Create a directory for the database files and change the owner to the administrative user ("postgres").
In this example, the directory is "/var/pgsql/data".

 

[root@xxxxxx ~]# mkdir /var/pgsql
[root@xxxxxx ~]# mkdir /var/pgsql/data
[root@xxxxxx ~]# chown -R postgres:postgres /var/pgsql


Create a database with the administrative user.
Use -D option to specify the directory for the database files.
[root@xxxxxx ~]# su - postgres
[postgres@xxxxxx ~]$ /usr/local/pgsql/bin/initdb \
> --encoding=utf8 --no-locale -D /var/pgsql/data
      .
      .(Omitted)
      .
Success. You can now start the database server using:

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

[postgres@xxxxxx ~]$


It is ready to run PostgreSQL. Use the administrative command to run PostgreSQL.
If PostgreSQL runs normally, create a test database and connect.
[postgres@xxxxxx ~]$ /usr/local/pgsql/bin/pg_ctl -D /var/pgsql/data -l logfile start
server starting
[postgres@xxxxxx ~]$ /usr/local/pgsql/bin/createdb test
[postgres@xxxxxx ~]$ /usr/local/pgsql/bin/psql test
psql (9.2.x)
Type "help" for help.

test=#

If you see like that, the database runs normally.
5. Automatic Start Database Setting
To run PostgreSQL automatically when the server is started, you can configure "/etc/rc.d/rc.local" file.However this version supposes using Red Hat Enterprise Linux, we use the scripts and the chkconfig command in the PostgreSQL package.
This step requires the super user (root).

Copy "contrib/start-scripts/linux" in the source code of PostgreSQL to "/etc/rc.d/init.d" and name it "postgresql".

 

[postgres@xxxxxx ~]$ su
Password:
[root@xxxxxx postgres]# cd /usr/local/src/postgresql-9.2.x/contrib/start-scripts/
[root@xxxxxx start-scripts]# cp linux /etc/rc.d/init.d/postgresql
[root@xxxxxx start-scripts]# chmod 755 /etc/rc.d/init.d/postgresql


In the "postgresql", the path can be specified.
Change PGDATA that meets your operating environment.
[root@xxxxxx ~]# vi /etc/rc.d/init.d/postgresql
      .
      .(Omitted)
      .
## EDIT FROM HERE

# Installation prefix
prefix=/usr/local/pgsql

# Data directroy
PGDATA="/var/pgsql/data" <- Edit here according to your environment

# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

## STOP EDITING HERE


User chkconfig command to set.
[root@xxxxxx ~]# chkconfig --add postgresql
[root@xxxxxx ~]# chkconfig --list | grep postgresql
postgresql 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Now, the database is started automatically when the server is started.
Restart the server and confirm the database runs.

 
Copyright (C) NEOJAPAN Inc. All Rights Reserved.