为Postgresql自由数据库的启动做准备: 首先 # vi /etc/services ## 增加一行: postgresql 5432/tcp # Postgres SQL Connect-Port 然后重新启动机器,以使SHMMAX核心参数及5432/tcp端口生效,系统引导后以postgres用户登录(这个用户是安装PostgreSQL Data Base Management System时,由安装脚本创建的) 查看该用户的.profile文件,关注环境变量MANPATH、PGLIB、PGDATA、USER,如果都设置正确,就可以创建数据库集群了,方法如下: initdb -D /usr/local/pgsql/data ***请注意你必须以 Postgres 用户的身份来执行这条命令。
技巧: 作为 -D选项的替代品,你还可以使用环境变量 PGDATA 系统提示如下:
$ initdb The files belonging to this database system will be owned by user "postgres". This user must also own the server process.
Fixing permissions on existing directory /usr/local/pgsql/data... ok creating directory /usr/local/pgsql/data/base... ok creating directory /usr/local/pgsql/data/global... ok creating directory /usr/local/pgsql/data/pg_xlog... ok creating directory /usr/local/pgsql/data/pg_clog... ok creating template1 database in /usr/local/pgsql/data/base/1... ok creating configuration files... ok initializing pg_shadow... ok enabling unlimited row size for system tables... ok creating system views... ok loading pg_description... ok vacuuming database template1... ok copying template1 to template0... ok
Success. You can now start the database server using:
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data or /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
启动数据库: $ pg_ctl -l $HOME/data/server.log start postmaster successfully started $ cat data/server.log DEBUG: database system was shut down at 2003-10-31 19:22:27 CST DEBUG: checkpoint record is at 0/109664 DEBUG: redo record is at 0/109664; undo record is at 0/0; shutdown TRUE DEBUG: next transaction id: 89; next oid: 16556 DEBUG: database system is ready $ pg_ctl stop waiting for postmaster to shut down......done postmaster successfully shut down $ pg_ctl -l $PGDATA/server.log start postmaster successfully started 致此,PGSQL自由数据库已经正常工作啦。 :)
/*************************************************** 如果要在系统每次启动时都启动PGSQL 在/etc/rc2.d/目录下创建S99pgsql文件 # cat /etc/rc2.d/S99pgsql # # Start/Stop PGSQL # # PGDATA='/usr/local/pgsql/data' case "$1" in start) su - postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/server.log start' ;;