Youcef LAIDANI
Youcef LAIDANI

Reputation: 59960

psql.exe postgresql create database via CMD

I search to create a database via CMD, i success to create it using this command:

C:\>"C:\Program Files\PostgreSQL\9.3\bin\psql.exe" -U postgres template1

So when i excute this command i can Create my database like this:

template1=# CREATE DATABASE d_base;

My objectif is to create this database with just one line:

like this:

 C:\>"C:\Program Files\PostgreSQL\9.3\bin\psql.exe" -U postgres template1 "CREATE DATABASE T;"

But this not work with me, it gave me this error:

enter image description here

i can solve this problem with creating a .bat Script but my objectif is to use just one line,

Is there any solution for that.

Thank you.

Upvotes: 0

Views: 5175

Answers (2)

Laurenz Albe
Laurenz Albe

Reputation: 246308

You get that error because template1 is not the last argument. You can use -d to specify the database.

Use the database postgres instead of template1.

Try this:

"C:\Program Files\PostgreSQL\9.3\bin\psql.exe" -U postgres -d postgres -c "CREATE DATABASE t"

Upvotes: 2

Boris Schegolev
Boris Schegolev

Reputation: 3701

https://www.postgresql.org/docs/9.3/static/app-psql.html

see --command=command section

Upvotes: 2

Related Questions