1

i need to enter password two time for this command when it ask

createuser -h localhost -P -p 5432 -s -d -r -e postgres 

i tried

createuser -h localhost -P -p 5432 -s -d -r -e postgres < temp.txt

where temp.txt contains

password
password

it still asks for password

any suggestions?

asked May 5, 2011 at 5:27
1
  • Could the part that asks for a password be a separate process that is started by createuser? Commented May 5, 2011 at 5:33

1 Answer 1

3

The createuser program probably makes its own connection to the terminal rather than reading from its standard input, this is common behavior where passwords are concerned. You'll probably have better luck using the SQL CREATE ROLE rather than createuser:

echo "CREATE ROLE postgres CREATEROLE CREATEDB SUPERUSER PASSWORD 'password';" \ 
 | psql -h localhost -p 5432 databasename

Where "databasename" is the name of your database.

From the fine manual:

createuser is a wrapper around the SQL command CREATE ROLE. There is no effective difference between creating users via this utility and via other methods for accessing the server.

answered May 5, 2011 at 5:51
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, I left out the database name on psql, please see my update.
but first i want need to create user and on that user i will create database so at this stage database would not available

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.