Postgresql does not create db with "createdb" as root, but does not throw errors

I am working with a new postgresql installation, with the superuser postgres. Log in through:

sudo -u postgres psql postgres=# createdb database postgres-# \list List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres : postgres=CTc/postgres 

There are no errors, but the table is not created. Any ideas?

+84
postgresql psql
Nov 10
source share
2 answers

createdb is a command line utility that can be run from bash , not psql. To create a database from psql , use the create database statement as follows:

 create database [databasename]; 

Note. Be sure to always complete your SQL statements with ;

+168
Nov 10 '12 at 9:59
source share

Late side, but the accepted answer does not explain why the error is not displayed. And since this is something that Postgres newbies often stumble over, I would like to add this.




TL / TR: always end your SQL statements with ;




Since createdb database does not end with ; psql , it is believed that the statement is not completed and is waiting for more input. This is indicated by a prompt that changes from postgres=# to postgres-# . The extremely subtle change I want psql will be different (more "noticeable").

By entering the \list meta-command, the "current" SQL statement is "interrupted" without executing it.

If createdb done with ; The output would be:

  postgres => createdb foobar;
 ERROR: syntax error at or near "createdb"
 LINE 1: createdb foobar;
         ^
 postgres => 

Obviously, something is wrong.

+59
Dec 08 '15 at
source share



All Articles