0

Need help on creating a linux script that allows me to create a postgresql user with password based on the following variables:

PG_USER="username"
PG_PWD="password"

Usually I have to do it manually, but need a script based on the following code (include the flags on the script):

createuser --createdb --username postgres --no-createrole --no-superuser

Based on the above code, need a script that allows me to include the flags and also include the username and password variables.

1
  • 1
    Not sure that it is possible with createuser utility. Consider to use ~ $ PGPASSWORD=123 psql -U postgres -h localhost -c "create role $PG_USER ..." or something... Commented May 6, 2017 at 0:00

1 Answer 1

1
psql -c "CREATE USER $PG_USER WITH CREATEDB PASSWORD '$PG_PWD'"
Sign up to request clarification or add additional context in comments.

Comments

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.