PostgreSql服务器的配置(二)

2014-11-24 10:45:54 · 作者: · 浏览: 3
This user will own all the files and must also own the server process. Creating Postgres database system directory /var/lib/pgsql/base Creating template database in /var/lib/pgsql/base/template1 Creating global classes in /var/lib/pgsql/base Adding template1 database to pg_database... Vacuuming template1 Creating public pg_user view Creating view pg_rules Creating view pg_views Creating view pg_tables Creating view pg_indexes Loading pg_des cription

-D 选项声明数据存储的位置。你可以使用任何你想用的路径,它不必在安装目录里。在运行 initdb 前只要确保数据库超级用户帐户可以写(或者创建)那个目录就行了。
8、启动postgresql服务;
前面的步骤应该已经告诉你如何启动数据库服务器。现在就做。
$ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
这样将在前台启动数据库服务器。要把它放到后台,使用 -S。
4.配置Postgresql的脚本文件
配置“/etc/rc.d/ini.d/postgresql”脚本文件,用来启动和停止PostgreSQL服务器。
创建“postgresql”脚本文件(touch /etc/rc.d/init.d/postgresql)并加入:
#! /bin/sh 
# postgresql This is the init s cript for starting up the PostgreSQL 
# server 
# chkconfig: 345 85 15 
# des cription: Starts and stops the PostgreSQL backend daemon that handles 
# all database requests. 
# processname: postmaster 
# pidfile: /var/run/postmaster.pid 
# 
# Source function library. 
. /etc/rc.d/init.d/functions 
# Get config. 
. /etc/sysconfig/network 
# Check that networking is up. 
# Pretty much need it for postmaster. 
[ ${NETWORKING} = "no" ] && exit 0 
[ -f /usr/bin/postmaster ] || exit 0 
# This s cript is slightly unusual in that the name of the daemon (postmaster) 
# is not the same as the name of the subsystem (postgresql) 
# See how we were called. 
case "$1" in 
start) 
echo -n "Checking postgresql installation: " 
# Check for the PGDATA structure 
if [ -f /var/lib/pgsql/PG_VERSION ] && [ -d /var/lib/pgsql/base/template1 ] 
then 
# Check version of existing PGDATA 
if [ `cat /var/lib/pgsql/PG_VERSION` != 6.5 ] 
then 
echo "old version. Need to Upgrade." 
echo "See /usr/doc/postgresql-6.5.2/README.rpm for more information." 
exit 1 
else 
echo "looks good!" 
fi 
# No existing PGDATA! Initdb it. 
else 
echo "no database files found." 
if [ ! -d /var/lib/pgsql ] 
then 
mkdir -p /var/lib/pgsql 
chown postgres.postgres /var/lib/pgsql 
fi 
su -l postgres -c /usr/bin/initdb --pglib=/usr/lib/pgsql --pgdata=/var/lib/pgsql 
fi 
# Check for postmaster already running... 
pid=`pidof postmaster` 
if [ $pid ] 
then 
echo "Postmaster already running." 
else 
#all systems go -- remove any stale lock files 
rm -f /tmp/.s.PGSQL.* >
/dev/null echo -n "Starting postgresql service: " su -l postgres -c /usr/bin/postmaster -i -S -D/var/lib/pgsql sleep 1 pid=`pidof postmaster` if [ $pid ] then echo -n "postmaster [$pid]" touch /var/lock/subsys/postgresql echo $pid > /var/run/postmaster.pid echo else echo "failed." fi fi ;; stop) echo -n "Stopping postgresql service: " killproc postmaster sleep 2 rm -f /var/run/postmaster.pid rm -f /var/lock/subsys/postgresql echo ;; status) status postmaster ;; restart) $0 stop $0 start ;; *) echo "Usage: postgresql {start|stop|status|restart}" exit 1 esac exit 0 现在让脚本可执行并设置它的缺省权限: [root@Aid]# chmod 700 /etc/rc.d/init.d/postgresql 用下面命令创建“rc.d”目录下PostgresSQL的符号链接: [root@Aid]# chkconfig --add postgresql 系统会在启动时自动把Postgresql后台进程启动,也可以通过 /etc/rc.d/init.d/postgresql start|sto