6

I have create a new user in pgsql with no password. But when i try to create a database for this user it prompts for a password

>createuser -d -S -R -U postgres test1
Password:
>createdb -U test1 db1
Password:

i have tried the superuser password but it gives me the error :

createdb: could not connect to database template1: FATAL:  password authentication failed for user "test1"

Please help, Thank you

0

2 Answers 2

2

There is an alternative way to create user by prompting password. You can give -P option while creating user. Like:

createuser -d -S -R -U postgres test1

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

2 Comments

Could you please edit your answer ? Your example does not show the actual -P option...
The -P option is actually a shortcut for --pwprompt, which is the opposite of what OP wants, it asks for the password using a prompt. From the documentation[1]: "If given, createuser will issue a prompt for the password of the new user. This is not necessary if you do not plan on using password authentication." [1] postgresql.org/docs/9.6/app-createuser.html
0

This may work for you,

psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"

You need to run this from command-prompt. Go to the PostgreSQL folder where you can find the program psql and try this command. mydb would be the database name.

Reference: How to prevent asking for password when creating new database in PostgreSQL 10?

Thanks to: Jasen and Mladen Uzelac

1 Comment

The point is to prevent the command from being stored in the terminal history. This fails that

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.