code-8
code-8

Reputation: 58642

Create a database on PostgreSQL via a command line

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.

Upvotes: 2

Views: 9333

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51446

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

Upvotes: 6

Related Questions