入口
pkgsrc による設置
  php3
    php3-i18n
    database/php3-pgsql
    www/ap-php3
apache 版
postgres (1)
  php4-pgsql (3)
    make install
php4 (apache1)
  www/php4(2)
    php4 の版
  www/ap-php4(5)
  www/apache(4)
    IPv6
    IPv4+nossl
    Apache/SSL
php4(apache2) - 依存関係
  ap2-php4
    php4
    mod_php4.so
    /usr/pkg/etc/php.ini
  php4-session(6)
    session.so
    --enable-session
    core_globals
    map
    php4 i18n 無
    php4 i18n
  configure
セッション管理
  php3 互換モード
  php4 内蔵
  php4 + phplib
  phpinfo()
PostgreSQL 準備
  postmaster
  環境変数
  initdb
    実際の様子
    試しに起動
  postmaster 設定
  postgreql.conf
  pg_hba.conf
  postmaster の起動
  使用者登録
  pg_ctl
  /etc/rc.conf
  shutdown
データべースを作る
psql
  psql \h
  psql \?
  psql \h select
  psql \d
  psql \copy
  psql 操作
  Data Type
    DATE
Application
  pgpost
    pgpost 設置例
    psql で見る
  AuthPG
      create table
        GRANT
  pgimage
  pgimage psql
SQL
URL
  PostgreSQL
  PHP
良くある問題
    undefined pg_connect()
    Link-ID == false
    Call-time pass-by-reference
    session_register
    Undefined session_adapt_flush
    Failed opening for inclusion
  does not exist in ..
  pg_exec() query failed
  Undefined property: Port
  undefined function: preg_match()
  used in non-rule query
その他
適用例
  日記から等

PostgreSQL + Apache + PHP4 | PHP4 programming

initdb

initdb は PostgreSQL が使うデータべースを作成・初期化します。
例えば $PGDATA = /export/pgsql を使うすると、
setenv PGDATA /export/pgsql
のようにしておけば、
  1. sudo を使って
    > sudo mkdir         $PGDATA
    > sudo chown pgsql   $PGDATA
    
    しておいて pgsql になります。例えば
    > sudo -s
    # su - pgsql
    
    とするのも一つの方法でしょう。
  2. $ initdb --pgdata=$PGDATA
    
    あるいは
    $ initdb -D $PGDATA
    
    もしくは単に、(この画面の四行目のように $PGDATA 変数の設定がしてあれば)
    $ initdb 
    
    のようにします。

実際の様子

実際に作業の様子は 次のような表示になる。 (2007/08/27)
ttyq9:root@bologna 16:41:07/070827(...www/ap2-auth-pgsql)# echo $PGDATA
/export/pgsql
ttyq9:root@bologna 16:41:14/070827(...www/ap2-auth-pgsql)# su - pgsql 
$ export PGDATA=/export/pgsql
$ initdb --pgdata=$PGDATA
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.

The database cluster will be initialized with locale C.

fixing permissions on existing directory /export/pgsql ... ok
creating directory /export/pgsql/global ... ok
creating directory /export/pgsql/pg_xlog ... ok
creating directory /export/pgsql/pg_xlog/archive_status ... ok
creating directory /export/pgsql/pg_clog ... ok
creating directory /export/pgsql/pg_subtrans ... ok
creating directory /export/pgsql/base ... ok
creating directory /export/pgsql/base/1 ... ok
creating directory /export/pgsql/pg_tblspc ... ok
selecting default max_connections ... 40
selecting default shared_buffers ... 300
creating configuration files ... ok
creating template1 database in /export/pgsql/base/1 ... ok
initializing pg_shadow ... ok
enabling unlimited row size for system tables ... ok
initializing pg_depend ... ok
creating system views ... ok
loading pg_description ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... 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:

    postmaster -D /export/pgsql
or
    pg_ctl -D /export/pgsql -l logfile start

$ 
postmaster を起動すると
ttyq9:root@bologna 16:45:44/070827(...www/ap2-auth-pgsql)# env pgsql=YES !!
env pgsql=YES /etc/rc.d/pgsql start
Initializing PostgreSQL databases.
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /export/pgsql/data ... ok
creating directory /export/pgsql/data/global ... ok
creating directory /export/pgsql/data/pg_xlog ... ok
creating directory /export/pgsql/data/pg_xlog/archive_status ... ok
creating directory /export/pgsql/data/pg_clog ... ok
creating directory /export/pgsql/data/pg_subtrans ... ok
creating directory /export/pgsql/data/base ... ok
creating directory /export/pgsql/data/base/1 ... ok
creating directory /export/pgsql/data/pg_tblspc ... ok
selecting default max_connections ... 40
selecting default shared_buffers ... 300
creating configuration files ... ok
creating template1 database in /export/pgsql/data/base/1 ... ok
initializing pg_shadow ... ok
enabling unlimited row size for system tables ... ok
initializing pg_depend ... ok
creating system views ... ok
loading pg_description ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... 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/pkg/bin/postmaster -D /export/pgsql/data
or
    /usr/pkg/bin/pg_ctl -D /export/pgsql/data -l logfile start

Starting pgsql.
ttyq9:root@bologna 16:46:03/070827(...www/ap2-auth-pgsql)# 
以前に作業した時の記録: (2007/01/07)
ttyr5:makoto@mini 16:48:47/070107(~)> setenv PGDATA /export/postgres/
ttyr5:makoto@mini 16:48:54/070107(~)> sudo -s
ttyr5:root@mini 16:49:04/070107(~)# su  - postgres
postgres@mini  16:49:11/070107(~)> echo $PGDATA
PGDATA: Undefined variable.
postgres@mini  16:49:22/070107(~)> setenv PGDATA /export/postgres/
postgres@mini  16:49:27/070107(~)> initdb --pgdata=$PGDATA
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.

fixing permissions on existing directory /export/postgres ... ok
creating directory /export/postgres/global ... ok
creating directory /export/postgres/pg_xlog ... ok
creating directory /export/postgres/pg_xlog/archive_status ... ok
creating directory /export/postgres/pg_clog ... ok
creating directory /export/postgres/pg_subtrans ... ok
creating directory /export/postgres/base ... ok
creating directory /export/postgres/base/1 ... ok
creating directory /export/postgres/pg_tblspc ... ok
selecting default max_connections ... 40
selecting default shared_buffers ... 300
creating configuration files ... ok
creating template1 database in /export/postgres/base/1 ... ok
initializing pg_shadow ... ok
enabling unlimited row size for system tables ... ok
initializing pg_depend ... ok
creating system views ... ok
loading pg_description ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... 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:

    postmaster -D /export/postgres
or
    pg_ctl -D /export/postgres -l logfile start

postgres@mini  16:49:46/070107(~)> 

試しに起動

次に試しに起動してみます。
ttyr5:root@mini 17:22:39/070107(~)# cp /usr/pkg/share/examples/rc.d/pgsql /etc/rc.d
ttyr5:root@mini 17:23:27/070107(~)# /etc/rc.d/pgsql start
/etc/rc.d/pgsql: WARNING: $pgsql is not set properly - see rc.conf(5).
ttyr5:root@mini 17:23:36/070107(~)# vi /etc/rc.conf
ttyr5:root@mini 17:23:49/070107(~)# /etc/rc.d/pgsql start
Initializing PostgreSQL databases.
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /usr/pkg/pgsql/data ... ok
creating directory /usr/pkg/pgsql/data/global ... ok
creating directory /usr/pkg/pgsql/data/pg_xlog ... ok
creating directory /usr/pkg/pgsql/data/pg_xlog/archive_status ... ok
creating directory /usr/pkg/pgsql/data/pg_clog ... ok
creating directory /usr/pkg/pgsql/data/pg_subtrans ... ok
creating directory /usr/pkg/pgsql/data/base ... ok
creating directory /usr/pkg/pgsql/data/base/1 ... ok
creating directory /usr/pkg/pgsql/data/pg_tblspc ... ok
selecting default max_connections ... 40
selecting default shared_buffers ... 300
creating configuration files ... ok
creating template1 database in /usr/pkg/pgsql/data/base/1 ... ok
initializing pg_shadow ... ok
enabling unlimited row size for system tables ... ok
initializing pg_depend ... ok
creating system views ... ok
loading pg_description ... ok
creating conversions ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... 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/pkg/bin/postmaster -D /usr/pkg/pgsql/data
or
    /usr/pkg/bin/pg_ctl -D /usr/pkg/pgsql/data -l logfile start

Starting pgsql.
ttyr5:root@mini 17:24:02/070107(~)# 
(以下は以前の記録)
2004/09/18 に同じことをしたら、次のようになった。(2004/09/18 版)
ttyp1:makoto@st4200  17:33:06/040918(/export)> sudo mkdir postgres
ttyp1:makoto@st4200  17:33:14/040918(/export)> sudo chown pgsql postgres
ttyp1:makoto@st4200  17:33:19/040918(/export)> sudo su pgsql
$ tcsh
> env |grep JP
LANG=ja_JP.eucJP
> unsetenv LANG
> /usr/pkg/bin/initdb --pgdata=/export/postgres
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.

The database cluster will be initialized with locale C.

fixing permissions on existing directory /export/postgres... ok
creating directory /export/postgres/base... ok
creating directory /export/postgres/global... ok
creating directory /export/postgres/pg_xlog... ok
creating directory /export/postgres/pg_clog... ok
selecting default max_connections... 40
selecting default shared_buffers... 800
creating configuration files... ok
creating template1 database in /export/postgres/base/1... ok
initializing pg_shadow... ok
enabling unlimited row size for system tables... ok
initializing pg_depend... ok
creating system views... ok
loading pg_description... ok
creating conversions... ok
setting privileges on built-in objects... ok
creating information schema... ok
vacuuming database template1... ok
copying template1 to template0... ok

Success. You can now start the database server using:

    /usr/pkg/bin/postmaster -D /export/postgres
or
    /usr/pkg/bin/pg_ctl -D /export/postgres -l logfile start

> 
(2002/05/30 版)
postgres@u  17:55:52/020530(~)> initdb --pgdata=/a/j/postgres
This database system will be initialized with username "postgres".
This user will own all the data files and must also own the server process.

Fixing permissions on existing directory /a/j/postgres
Creating directory /a/j/postgres/base
Creating directory /a/j/postgres/global
Creating directory /a/j/postgres/pg_xlog
Creating template1 database in /a/j/postgres/base/1
DEBUG:  database system was shut down at 2002-05-30 17:55:59 JST
DEBUG:  CheckPoint record at (0, 8)
DEBUG:  Redo record at (0, 8); Undo record at (0, 8); Shutdown TRUE
DEBUG:  NextTransactionId: 514; NextOid: 16384
DEBUG:  database system is in production state
Creating global relations in /a/j/postgres/global
DEBUG:  database system was shut down at 2002-05-30 17:56:12 JST
DEBUG:  CheckPoint record at (0, 112)
DEBUG:  Redo record at (0, 112); Undo record at (0, 0); Shutdown TRUE
DEBUG:  NextTransactionId: 514; NextOid: 17199
DEBUG:  database system is in production state
Initializing pg_shadow.
Enabling unlimited row width for system tables.
Creating system views.
Loading pg_description.
Setting lastsysoid.
Vacuuming database.
Copying template1 to template0.

Success. You can now start the database server using:

    /usr/pkg/bin/postmaster -D /a/j/postgres
or
    /usr/pkg/bin/pg_ctl -D /a/j/postgres -l logfile start

postgres@u  17:56:27/020530(~)> 
この画面は Jeedosaquin によって表示しています。
Last Update: Fri, 03 May 2019 15:45:20 GMT 1.66 2008/03/08