11

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 ?

4
  • What did you get as result of your CREATE DATABSE demo; ? You should have the message like : CREATE DATABASE and that's it ... so what said PostgreSQL ? Commented Oct 31, 2017 at 16:32
  • i got nothing...after i added quotes it created but i can't drop database now (just for testing) Commented Oct 31, 2017 at 16:38
  • You can't drop a database when you are connected to it ... but the command is simply DROP DATABASE demo; when you are corrected to postgres default database. Commented Oct 31, 2017 at 16:51
  • Sounds like you forgot the semicolon Commented Oct 31, 2017 at 16:53

3 Answers 3

14

sudo su - postgres to become postgres

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

Sign up to request clarification or add additional context in comments.

1 Comment

i added quotes it is worked but i can't drop database demo now :/ 5 (to test it)
4

first:

    sudo su postgres

and then enter your password then type:

     psql

and type this command:

    CREATE DATABASE dbname;

1 Comment

Or simply start psql -U postgres ...
2

simple type on bash

$ createdb -U postgres(db user) dbname

if set hba_config in pg for access to db in network type

$ createdb -h YOUR_IP -U postgres(db user) dbname

if you set password for db user pg ask your password to create database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.