5

I am trying to create two databases called spider and geo under postgresql via an automated shell script. This is the code so far.

apt-get install -y postgresql
echo "CREATE ROLE deploy LOGIN ENCRYPTED PASSWORD '$APP_DB_PASS';" | sudo -u postgres psql
su postgres -c "createdb spider --owner deploy"
su postgres -c "createdb geo --owner deploy"
/etc/init.d/postgresql reload

Can anyone please have a look and see if I am going about this the right way. Moreover, when I try to see if it works by running the following command I get an error:

root:~# psql -l                                                                               
psql: FATAL:  role "root" does not exist 

Where have I gone wrong, and is there any way to improve this script?

1
  • Shouldn't the "--owner deploy" be "--owner=deploy"? Commented Aug 20, 2013 at 21:19

1 Answer 1

4

Judging by the apt-get, your deployment platform is Ubuntu-(ish).

apt-get install -y postgresql
echo "CREATE ROLE deploy LOGIN ENCRYPTED PASSWORD '$APP_DB_PASS';" | sudo -u postgres psql
su postgres -c "createdb spider --owner deploy"
su postgres -c "createdb geo --owner deploy"
service postgresql reload

Then you should be able to log in by specifying a user on the command line:

psql -U root spider

or

psql -U deploy spider

Generally speaking, you're on the right track.

Sign up to request clarification or add additional context in comments.

1 Comment

I had better luck with this for the the command line: sudo -u postgres psql -c "create database spider --owner deploy"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.