# 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
#! /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. [ ${NETWORKI<SPAN title="常规词语,单击这里可以查看解释" style="BACKGROUND-IMAGE: url(C:PROGRA~1!SUNVDFKC3000 ormmark.gif); BACKGROUND-POSITION: left bottom; BACKGROUND-REPEAT: repeat-x; CURSOR: hand" )>NG</SPAN>} = "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
# su postgres $ createuser Enter name of user to add ---> admin Enter user's postgres ID or RETURN to use unix user ID: 500 -> Is user "admin" allowed to create databases (y/n) y Is user "admin" a superuser? (y/n) y createuser: admin was successfully added
用“destroyuser”命令在数据库中删除用户:
# su postgres $ destroyuser Enter name of user to delete ---> admin destroyuser: delete of user admin was successful.
用“createdb”命令创建新的数据库:
# su postgres $ createdb dbname
用“destorydb”命令删除数据库: # su postgres $ destorydb dbname
$psql databasename Welcome to the POSTGRESQL interactive sql monitor: Please read the file COPYRIGHT for copyright terms of POSTGRESQL [PostgreSQL 6.5.3 on i686-pc-linux-gnu, compiled by egcs ] type ? for help on slash commands type q to quit type g or terminate with semicolon to execute query You are currently connected to the database: databasename