【发布时间】:2012-12-05 22:15:48
【问题描述】:
我构建了这个部署脚本,它在部署我的 debian 6.0 服务器时运行。我之前在这里展示过(这是一个 linode 堆栈脚本,以防其他人想知道):
#!/bin/bash
#
# Install PostgreSQL
#
# Copyright (c) 2010 Filip Wasilewski <en@ig.ma>.
#
# My ref: http://www.linode.com/?r=aadfce9845055011e00f0c6c9a5c01158c452deb
function postgresql_install {
aptitude -y install postgresql postgresql-contrib postgresql-dev libpq-dev
}
function postgresql_create_user {
# postgresql_create_user(username, password)
if [ -z "$1" ]; then
echo "postgresql_create_user() requires username as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_user() requires a password as the second argument"
return 1;
fi
echo "CREATE ROLE $1 WITH LOGIN ENCRYPTED PASSWORD '$2';" | sudo -i -u postgres psql
}
function postgresql_create_database {
# postgresql_create_database(dbname, owner)
if [ -z "$1" ]; then
echo "postgresql_create_database() requires database name as the first argument"
return 1;
fi
if [ -z "$2" ]; then
echo "postgresql_create_database() requires an owner username as the second argument"
return 1;
fi
sudo -i -u postgres createdb --owner=$2 $1
}
postgresql_install
postgresql_create_user(username, password)
postgresql_create_database(dbname, username)
我使用这个脚本部署了我的服务器,该脚本是在 Filip 的版本之上构建的,但是当我尝试通过键入 pg_ctl 来查看 postgresql 是否正在运行时,它说找不到命令。
我在哪里做错了?由于它是在服务器运行时部署的,所以我无法看到它出错的地方。
【问题讨论】:
-
您确定您的
PATH中有psql和createdb吗?你真的应该在这种脚本中使用完整路径。 -
我实际上并不了解“路径”。指向我的 postgresql 安装的完整路径是什么?
-
我不确定它们会在哪里,请尝试在已正确安装且可访问的机器上说
which psql。 -
我在我的机器上输入了 which psql 但它什么也没说,我用 apt-get 安装了它,所以它应该在标准位置。
-
这表明您的
PATH中没有任何 PostgreSQL 内容。尝试locate psql或检查软件包以查看其安装位置。
标签: sql bash postgresql shell debian