結局の原因はサーバーの起動時にiオプションがついていなかったという。
サーバーの起動スクリプトはPostgreSQL 8.4のソースコードに付属の(./contrib/start-scripts/linux)を使っていたが、これにiオプションがついていないからいけないのかな?ということで適当に修正してみる。
./contrib/start-srcipts/linuxをUbuntu 9.04ならば/etc/init.dにコピーしてpostgresとかに適当にリネーム。
startとrestartの部分でそれぞれサーバーを起動させている行である以下の部分を、
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
下記のように変更した。っていうか-iを付けただけー。
su - $PGUSER -c "$DAEMON -D '$PGDATA' -i &" >>$PGLOG 2>&1
その後chkconfig --add postgresで導入。
service postgres statusや、ps aux |grep postgresなどのコマンドで動作を確認。
TCP/IPでの接続もできるようになりました。
(もちろんpostgresql.confやpg_hba.confの設定は必要)
以下サーバーの起動スクリプトの全文。
#! /bin/sh
# chkconfig: 2345 98 02
# description: PostgreSQL RDBMS
# This is an example of a start/stop script for SysV-style init, such
# as is used on Linux systems. You should edit some of the variables
# and maybe the 'echo' commands.
#
# Place this file at /etc/init.d/postgresql (or
# /etc/rc.d/init.d/postgresql) and make symlinks to
# /etc/rc.d/rc0.d/K02postgresql
# /etc/rc.d/rc1.d/K02postgresql
# /etc/rc.d/rc2.d/K02postgresql
# /etc/rc.d/rc3.d/S98postgresql
# /etc/rc.d/rc4.d/S98postgresql
# /etc/rc.d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# chkconfig --add postgresql
#
# Proper init scripts on Linux systems normally require setting lock
# and pid files under /var/run as well as reacting to network
# settings, so you should treat this with care.
# Original author: Ryan Kirkpatrick
# $PostgreSQL: pgsql/contrib/start-scripts/linux,v 1.8 2006/07/13 14:44:33 petere Exp $
## EDIT FROM HERE
# Installation prefix
prefix=/usr/local/pgsql
# Data directory
PGDATA="/usr/local/pgsql/data"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
## STOP EDITING HERE
# The path that is to be used for the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# What to use to start up the postmaster (we do NOT use pg_ctl for this,
# as it adds no value and can cause the postmaster to misrecognize a stale
# lock file)
DAEMON="$prefix/bin/postmaster"
# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"
set -e
# Only start if we can find the postmaster.
test -x $DAEMON || exit 0
# Parse command line parameters.
case $1 in
start)
echo -n "Starting PostgreSQL: "
su - $PGUSER -c "$DAEMON -D '$PGDATA' -i &" >>$PGLOG 2>&1
# su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
stop)
echo -n "Stopping PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
echo "ok"
;;
restart)
echo -n "Restarting PostgreSQL: "
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
su - $PGUSER -c "$DAEMON -D '$PGDATA' -i &" >>$PGLOG 2>&1
# su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
echo "ok"
;;
reload)
echo -n "Reload PostgreSQL: "
su - $PGUSER -c "$PGCTL reload -D '$PGDATA' -s"
echo "ok"
;;
status)
su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
;;
*)
# Print help
echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
exit 1
;;
esac
exit 0
今回はpostmasterを利用しているので、オプションは以下のコマンドで確認した。
# /usr/local/pgsql/bin/postmaster --help
postmaster is the PostgreSQL server.
Usage:
postmaster [OPTION]...
Options:
-B NBUFFERS number of shared buffers
-c NAME=VALUE set run-time parameter
-d 1-5 debugging level
-D DATADIR database directory
-e use European date input format (DMY)
-F turn fsync off
-h HOSTNAME host name or IP address to listen on
-i enable TCP/IP connections
-k DIRECTORY Unix-domain socket location
-N MAX-CONNECT maximum number of allowed connections
-o OPTIONS pass "OPTIONS" to each server process (obsolete)
-p PORT port number to listen on
-s show statistics after each query
-S WORK-MEM set amount of memory for sorts (in kB)
--NAME=VALUE set run-time parameter
--describe-config describe configuration parameters, then exit
--help show this help, then exit
--version output version information, then exit
Developer options:
-f s|i|n|m|h forbid use of some plan types
-n do not reinitialize shared memory after abnormal exit
-O allow system table structure changes
-P disable system indexes
-t pa|pl|ex show timings after each query
-T send SIGSTOP to all backend servers if one dies
-W NUM wait NUM seconds to allow attach from a debugger
Options for single-user mode:
--single selects single-user mode (must be first argument)
DBNAME database name (defaults to user name)
-d 0-5 override debugging level
-E echo statement before execution
-j do not use newline as interactive query delimiter
-r FILENAME send stdout and stderr to given file
Options for bootstrapping mode:
--boot selects bootstrapping mode (must be first argument)
DBNAME database name (mandatory argument in bootstrapping mode)
-r FILENAME send stdout and stderr to given file
-x NUM internal use
Please read the documentation for the complete list of run-time
configuration settings and how to set them on the command line or in
the configuration file.
Report bugs to.