snippetsqlModerate
How to prevent asking for password when creating new database in PostgreSQL 10?
Viewed 0 times
postgresqlpreventnewcreatingpassworddatabaseforhowaskingwhen
Problem
I use the following batch file to create a new database in PostgreSQL 10.
But it asks to enter the password. How to prevent asking for the password? I tried the
echo off
cd "C:\Program Files (x86)\PostgreSQL\10\bin"
createdb -h localhost -p 5432 -U postgres myDBBut it asks to enter the password. How to prevent asking for the password? I tried the
-w option explained in this link to not ask for password prompt. But this did not work. How to prevent asking for password?Solution
use the
or just use a connection string
PGPASSWORD environment variable, @SET PGPASSWORD=something_secret
psql -c "CREATE DATABASE mydb" -U postgres postgresor just use a connection string
psql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"Code Snippets
@SET PGPASSWORD=something_secret
psql -c "CREATE DATABASE mydb" -U postgres postgrespsql -c "CREATE DATABASE mydb" "user=postgres dbname=postgres password=something_secret"Context
StackExchange Database Administrators Q#209147, answer score: 11
Revisions (0)
No revisions yet.