Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create database in postgresql with bash command

Im trying to create a database in postgresql using linux.
I connected to postgres with

sudo -u postgres psql postgres 
postgres=# then i tried **CREATE DATABASE demo** or **createdb demo**

but none of them worked when i checked with \l command.
Any help ?

like image 310
pinug Avatar asked Dec 14 '22 20:12

pinug


2 Answers

sudo su - postgres to become postgres

then psql -c "create database demo" to create it from shell

like image 116
Vao Tsun Avatar answered Dec 16 '22 11:12

Vao Tsun


first:

    sudo su postgres

and then enter your password then type:

     psql

and type this command:

    CREATE DATABASE dbname;
like image 33
omar ahmed Avatar answered Dec 16 '22 11:12

omar ahmed