2

I'm trying to create database in psql via CLI.

psql  -U postgres createdb portal

I kept getting

psql: warning: extra command-line argument "portal" ignored
psql: FATAL:  database "createdb" does not exist

What did I do wrong ?


Note

I'm not trying to queries any data.

8
  • Spend 5 minutes reading the man page, please. Commented Jun 21, 2016 at 15:21
  • I'm not trying to query from a command line, I'm trying to create a database. That answer is NOT what I am looking for. Please kindly unmark it. Commented Jun 21, 2016 at 15:23
  • Please try psql -U postgres -c "CREATE DATABASE portal;" Commented Jun 21, 2016 at 15:32
  • Finally, someone know what I am trying to do. Thanks @code_onkel Commented Jun 21, 2016 at 15:33
  • @code_onkel : Your suggestions works perfectly. Please answer it, you deserve it. :) Commented Jun 21, 2016 at 15:34

1 Answer 1

6

here I connect as user vao to database postgres (which always is there) and create database db1 in CLI... The first argument without key is database name, so in your example createdb is interpreted as dbname to connect to...

please look at documentation of psql

Vaos-MacBook-Air:tts vao$ bash -c "psql -U vao postgres -c 'create database db1;'"
CREATE DATABASE
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.