0

I want simply drop some databases and after that create a new one.

Within postgresql version 9.1, running these commands first to create:

postgres=# createdb [dbname]

or

postgres=# CREATE DATABASE name

as described here Postgresql Documentation.

Now, to drop away some databases:

postgres=# DROP DATABASE name

as described here as well Postgresql Documentation.

They all didn't work. What am I missing?

Milen A. Radev
  • 60,241
  • 22
  • 105
  • 110
Nice Guy
  • 479
  • 2
  • 6
  • 12
  • I think you have to be a superuser – dardar.moh Jan 10 '14 at 22:10
  • When I log into postgre I log using sudo -u postgres pqsl, then enter my password. Do you mean that? – Nice Guy Jan 10 '14 at 22:12
  • @Randy, no Randy. When typing those commands nothing happens. No error messages, no warnings, no nothing. – Nice Guy Jan 10 '14 at 22:13
  • 2
    You need to terminate the commands with a `;` (and `createdb` is **not** a SQL statement, it's an operating system program) –  Jan 10 '14 at 22:20
  • @a_horse_with_no_name, Missing the colon omg!!! That worked! Incredible how we don't think in any possibilities before going out asking. Thanks mate. :) – Nice Guy Jan 10 '14 at 22:24

2 Answers2

4

You forgot the semicolons.

postgres=# DROP DATABASE name;

SQL commands may carry on over multiple lines, and are only sent to the server when you end them with a semicolon. That's why the prompt changes:

postgres=# DROP DATABASE name
postgres-# 

It might be a good idea to take a look through the tutorial.

Additionally createdb isn't an SQL command. It's a shell utility command that wraps CREATE DATABASE for convenience.

See also:

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
0

I think you have to be a superuser because accroding to the documentation :

for create a new database :

To create a database, you must be a superuser or have the special CREATEDB privilege. See CREATE USER.

for drop a database

DROP DATABASE drops a database. It removes the catalog entries for the database and deletes the directory containing the data. It can only be executed by the database owner.

Read this tutorial, it will help you.

dardar.moh
  • 5,987
  • 3
  • 24
  • 33