How to create a user for Postgres from the command line for bash automation

Tampa picture Tampa · Sep 10, 2013 · Viewed 83.8k times · Source

I am using Ubuntu 12.04 and Postgress 9.2.

I need to create this user with this password e.g.

postgres://admin:[email protected]:5432

How to do that from the command line? I need to automate with a bash script. I have a fresh install.

Answer

Tomas Greif picture Tomas Greif · Sep 10, 2013

This will create user admin with password test101 on localhost:

psql -c "CREATE USER admin WITH PASSWORD 'test101';"