以下脚本运行到:/etc/init.d/postgresql-9.1 initdb时出错,
提示如下:+ /etc/init.d/postgresql-9.1 initdb
Initializing database: mkdir: cannot create directory `/cache1/pgsql/9.1/data/pg_log': File exists初始化数据库始终不行,请问是什么原因,如何能正确的完全数据库初始化,急求,万分感谢!
#!/bin/bash
baserootdir=/var/lib
if [ -d /cache1 ];then
baserootdir=/cache1
elif [ -d /cache0 ];then
baserootdir=/cache0
fi
chattr -i /etc/passwd
chattr -i /etc/group
chattr -i /etc/shadow
chattr -i /etc/gshadow
yum clean all
rpm -Uvh pgdg-centos91-9.1-4.noarch.rpm
yum -y install postgresql91 postgresql91-server postgresql91-libs
rpm -qi postgresql91 > /dev/null
if [ $? -eq 0 ];then
chkconfig postgresql-9.1 on
[ -f /etc/profile ] && source /etc/profile
PGDATA=$baserootdir/pgsql/9.1/data
PGLOG=$baserootdir/pgsql/9.1/pgstartup.log
if [ ! -d $PGDATA ];then
mkdir -p $PGDATA
chown -R postgres:postgres $baserootdir/pgsql
fi
export PGDATA
PATH=$PATH:$HOME/bin:/usr/pgsql-9.1/bin
export PATH
sed -i "s:PGDATA=.*$:PGDATA=$PGDATA:g" /etc/init.d/postgresql-9.1
sed -i "s:PGLOG=.*$:PGLOG=$PGLOG:g" /etc/init.d/postgresql-9.1
echo "init..."
/etc/init.d/postgresql-9.1 initdb
/sbin/service postgresql-9.1 start
echo "create user and db..."
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"ALTER USER postgres WITH PASSWORD 'mypass'; \""
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"CREATE USER imusr WITH PASSWORD 'imusr' CREATEDB CREATEROLE; \""
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"CREATE DATABASE imusr OWNER imusr; \""
/bin/cp -rf pg_hba.conf $PGDATA
/bin/cp -rf postgresql.conf $PGDATA
echo "restart..."
/sbin/service postgresql-9.1 restart
else
echo "Install postgres failure. Please check the network."
exit 1
fi
提示如下:+ /etc/init.d/postgresql-9.1 initdb
Initializing database: mkdir: cannot create directory `/cache1/pgsql/9.1/data/pg_log': File exists初始化数据库始终不行,请问是什么原因,如何能正确的完全数据库初始化,急求,万分感谢!
#!/bin/bash
baserootdir=/var/lib
if [ -d /cache1 ];then
baserootdir=/cache1
elif [ -d /cache0 ];then
baserootdir=/cache0
fi
chattr -i /etc/passwd
chattr -i /etc/group
chattr -i /etc/shadow
chattr -i /etc/gshadow
yum clean all
rpm -Uvh pgdg-centos91-9.1-4.noarch.rpm
yum -y install postgresql91 postgresql91-server postgresql91-libs
rpm -qi postgresql91 > /dev/null
if [ $? -eq 0 ];then
chkconfig postgresql-9.1 on
[ -f /etc/profile ] && source /etc/profile
PGDATA=$baserootdir/pgsql/9.1/data
PGLOG=$baserootdir/pgsql/9.1/pgstartup.log
if [ ! -d $PGDATA ];then
mkdir -p $PGDATA
chown -R postgres:postgres $baserootdir/pgsql
fi
export PGDATA
PATH=$PATH:$HOME/bin:/usr/pgsql-9.1/bin
export PATH
sed -i "s:PGDATA=.*$:PGDATA=$PGDATA:g" /etc/init.d/postgresql-9.1
sed -i "s:PGLOG=.*$:PGLOG=$PGLOG:g" /etc/init.d/postgresql-9.1
echo "init..."
/etc/init.d/postgresql-9.1 initdb
/sbin/service postgresql-9.1 start
echo "create user and db..."
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"ALTER USER postgres WITH PASSWORD 'mypass'; \""
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"CREATE USER imusr WITH PASSWORD 'imusr' CREATEDB CREATEROLE; \""
/bin/su postgres -c "/usr/pgsql-9.1/bin/psql -U postgres -w -d postgres -c \"CREATE DATABASE imusr OWNER imusr; \""
/bin/cp -rf pg_hba.conf $PGDATA
/bin/cp -rf postgresql.conf $PGDATA
echo "restart..."
/sbin/service postgresql-9.1 restart
else
echo "Install postgres failure. Please check the network."
exit 1
fi
chown postgres.postgres /cache1/pgsql/9.1/data
/etc/init.d/postgresql-9.1 initdb
如果原来在/cache1/pgsql/9.1/data/已经初始化过,init就不会再初始化了哈,您可以重新建立一下目录
mv /cache1/pgsql/9.1/data /cache1/pgsql/9.1/data_old
mkdir /cache1/pgsql/9.1/data
chown postgres.postgres /cache1/pgsql/9.1/data
/etc/init.d/postgresql-9.1 initdb
chmod 644 /etc/passwd就可以了。还是谢谢你。