I am creating a batch file to create a new database in PostgreSQL 10. I used the following code,
echo off
cd "C:\Program Files (x86)\PostgreSQL\10\bin"
psql "dbname=myDB host=localhost user=postgres password=postgres port=5432"
pause
But I get this error,
psql: FATAL: database "myDB" does not exist
I understand this is not the command to create a new database. I also tried the following code,
echo off
cd "C:\Program Files (x86)\PostgreSQL\10\bin"
psql "createdb myDB passfile %APPDATA%\postgresql\pgpass.conf"
pause
This is based on the information in this link. The "pgpass.conf" file has the follwoing text,
localhost:5432:myDB:postgres:postgres
But it asks to enter password. I entered the default password "postgres". But this was the output,
psql: FATAL: password authentication failed for user "User1"
The objective here is to create new database from the batch file without asking for password. How to achieve this?
createdb
is also available on Windows? postgresql.org/docs/current/static/app-createdb.htmlcreatedb
is a command line program, not a SQL statement.psql
is used to run SQL statements, not to execute a command line program. You need to decide if you want to run a SQL statement or a command line program to do that.passfile
is wrong: postgresql.org/docs/current/static/… Also, you will need-U postgres
(oruser=postgres
, depending on which form of connection parameters you are using) in yourcreatedb
command. I'd suggest taking one step at a time, carefully reading some introductory material and the error messages. In this case you could notice that User1 is not the username you want.