[HOME] [戻る]

玄箱インストールmemo(postgres)

目次

postgreSQL-8.0

postgresユーザの作成

データ領域を用意

su
mkdir /usr/local/pgsql
chown postgres.postgres pgsql

コンパイル

tar jxf tgz/postgresql-8.0.1.tar.bz2
cd postgresql-8.0.1/
./configure --with-odbc --enable-multibyte --disable-debug
su postgres
make

テスト

make check
============== starting postmaster                    ==============
running on port 65432 with pid 19753
============== creating database "regression"         ==============
CREATE DATABASE
============== dropping regression test user accounts ==============
============== installing PL/pgSQL                    ==============
============== running regression test queries        ==============
parallel group (13 tests):  char boolean text name varchar oid int2
int4 int8 float4 float8 bit numeric
     boolean              ... ok
     char                 ... ok
     name                 ... ok
     varchar              ... ok
     text                 ... ok
     int2                 ... ok
     int4                 ... ok
     int8                 ... ok
     oid                  ... ok
     float4               ... ok
     float8               ... ok
     bit                  ... ok
     numeric              ... ok
test strings              ... ok
test numerology           ... ok
:
略
:
     prepare              ... ok
     without_oid          ... ok
     conversion           ... ok
     truncate             ... ok
     alter_table          ... ok
     sequence             ... ok
     polymorphism         ... ok
     rowtypes             ... ok
test stats                ... ok
test tablespace           ... ok
============== shutting down postmaster               ==============
postmaster stopped

======================
 All 96 tests passed.
======================

インストール

make install
cd /usr/local/pgsql/bin
strip -p *
cd /usr/local/pgsql/lib
strip -p *

データベースの初期化

mkdir  /usr/local/pgsql/data
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

起動

nohup /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data &

18411 pts/2    S      0:00 /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
18413 pts/2    S      0:00 postgres: writer process
18414 pts/2    S      0:00 postgres: stats buffer process
18415 pts/2    S      0:00 postgres: stats collector process

ユーザ追加

su postgres
/usr/local/pgsql/bin/createuser
Enter name of user to add: jun
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) y
CREATE USER

データベース作成

$ whoami
jun

$ /usr/local/pgsql/bin/createdb
CREATE DATABASE

実行

$ /usr/local/pgsql/bin/psql
Welcome to psql 8.0.1, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

jun=# \h
Available help:
  ABORT                     CREATE INDEX              DROP TYPE
  ALTER AGGREGATE           CREATE LANGUAGE           DROP USER
  ALTER CONVERSION          CREATE OPERATOR CLASS     DROP VIEW
  ALTER DATABASE            CREATE OPERATOR           END
  ALTER DOMAIN              CREATE RULE               EXECUTE
  ALTER FUNCTION            CREATE SCHEMA             EXPLAIN
  ALTER GROUP               CREATE SEQUENCE           FETCH
  ALTER INDEX               CREATE TABLE              GRANT
  ALTER LANGUAGE            CREATE TABLE AS           INSERT
  ALTER OPERATOR CLASS      CREATE TABLESPACE         LISTEN
  ALTER OPERATOR            CREATE TRIGGER            LOAD
  ALTER SCHEMA              CREATE TYPE               LOCK
  ALTER SEQUENCE            CREATE USER               MOVE
  ALTER TABLE               CREATE VIEW               NOTIFY
  ALTER TABLESPACE          DEALLOCATE                PREPARE
  ALTER TRIGGER             DECLARE                   REINDEX
  ALTER TYPE                DELETE                    RELEASE SAVEPOINT
  ALTER USER                DROP AGGREGATE            RESET
  ANALYZE                   DROP CAST                 REVOKE
  BEGIN                     DROP CONVERSION           ROLLBACK
  CHECKPOINT                DROP DATABASE             ROLLBACK TO SAVEPOINT
  CLOSE                     DROP DOMAIN               SAVEPOINT
  CLUSTER                   DROP FUNCTION             SELECT
  COMMENT                   DROP GROUP                SELECT INTO
  COMMIT                    DROP INDEX                SET
  COPY                      DROP LANGUAGE             SET CONSTRAINTS
  CREATE AGGREGATE          DROP OPERATOR CLASS       SET SESSION AUTHORIZATION
  CREATE CAST               DROP OPERATOR             SET TRANSACTION
  CREATE CONSTRAINT TRIGGER DROP RULE                 SHOW
  CREATE CONVERSION         DROP SCHEMA               START TRANSACTION
  CREATE DATABASE           DROP SEQUENCE             TRUNCATE
  CREATE DOMAIN             DROP TABLE                UNLISTEN
  CREATE FUNCTION           DROP TABLESPACE           UPDATE
  CREATE GROUP              DROP TRIGGER              VACUUM
jun=# \q

起動スクリプト

cd /etc/rc.d/initd
vi postgres

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin
CMDPATH=/usr/local/pgsql/bin/
CMD=postmaster
FLAGS="-D /usr/local/pgsql/data"

test -f $CMDPATH$CMD || exit 0

start()
{
    echo -n "Starting $CMD ... "
    su - postgres -c "nohup $CMDPATH$CMD $FLAGS" &
    echo "done."
}

stop()
{
    echo -n "Stopping $CMD ... "
    start-stop-daemon --stop --quiet --exec $CMDPATH$CMD
    echo "done."
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 2
        start
        ;;
    *)
        echo "Usage: /etc/rc.d/init.d/postgres {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

cd /rc.d/rc2.d
ln -s ../init.d/postgres S20postgres
cd /rc.d/rc0.d
ln -s ../init.d/postgres K20postgres

2005/02/10
ご意見・ご感想は,こちらの掲示板 まで.