技术开发 频道

PostgreSql服务器的配置

  【IT168 技术文档】
      3.6、配置共享库:

    告诉你的系统如何找到共享库。如何实现这些因平台而异。看起来可以在任何地方生效的方法是设置环境变量。
LD_LIBRARY_PATH: # LD_LIBRARY_PATH=/usr/local/pgsql/lib # export LD_LIBRARY_PATH

    你可能把这些放到一个 shell 启动文件里,象 ~/.bash_profile。在一些系统里,下面的方法是最好的方法,但是你必须有 root 权限。编辑文件 /etc/ld.so.conf,增加一行。

/usr/local/pgsql/lib

    然后运行命令:

#/sbin/ldconfig

    3.7、用postgres数据库超级用户完成数据库的安装:

    你必须用 PostgreSQL 超级用户帐号登录执行这一步。以 root 是不能进行这一步的。

# mkdir /usr/local/pgsql/data # chown postgres /usr/local/pgsql/data #su postgres $ /usr/local/pgsql/initdb -D /usr/local/pgsql/data We are initializing the database system with username postgres (uid=40). 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_description

    -D 选项声明数据存储的位置。你可以使用任何你想用的路径,它不必在安装目录里。在运行 initdb 前只要确保数据库超级用户帐户可以写(或者创建)那个目录就行了。

    3.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 script for starting up the PostgreSQL # server # chkconfig: 345 85 15 # description: 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 script 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
0
相关文章