2

I try dropdb mydbname in shell. It do not give any error. But still when I call \l it is still there.

I logged into the postgres server using sudo -u postgres psql.

Other than my main concern I need to know how to go into the database other than just staying outside of it. (as a example if I want to list the tables)

4
  • Can you please rephrase the question. I am not able to understand what you are trying to do Commented Nov 16, 2012 at 15:13
  • 1
    Could you please show your terminal output for dropdb mydbname and psql's \l meta-command? Commented Nov 16, 2012 at 15:19
  • 1
    Are you sure you are connecting to the correct Postgres server? Commented Nov 16, 2012 at 15:30
  • -1 no version shown, no command-line output copied, low effort question. You've been around long enough I'd expect better. Commented Nov 16, 2012 at 23:53

5 Answers 5

6

In order to drop database you can use SQL command (but I do not understand why dropdb didn't work) DROP DATABASE mydbname:

sudo -u postgres psql -c "DROP DATABASE mydbname"

It would be good to check if database is not used:

select * from pg_stat_activity where datname = 'mydbname';

The sudo -u postgres psql connects to postgres database. You need to specify database: sudo -u postgres psql mydbname and then you can use metdata commands like \d, \dt, \dv, ...

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

2 Comments

dropdb should do just the same thing
99% of the tasks to administrate a PostgreSQL database does not require su or sudo to the 'postgres' system user.
5

When you say "shell" ... do you mean the psql shell, not the unix command line shell?

I'd say you're running into this issue:

Postgresql not creating db with “createdb” as superuser, yet not outputting errors

ie you're trying to use dropdb as a psql command, when it's a unix shell command. You're not getting an error because of this:

In psql, why do some commands have no effect?

You didn't terminate the command with a semicolon.

Comments

4

Are you missing the comma(;)? This command worked for me:

drop database <database_name>;

1 Comment

Thank you. This was my problem. I have used postgres mainly through my code. The command line does not throw errors when you miss the semi-colon ;
2

Server should be running, then:

dropdb <database name>

If server is not running, first try:

pg_ctl start -D <mylocal_db_path> -l <mylogfile.log>

Comments

0
dropdb -h <ip> -p 5432 -U postgres --if-exists --echo <dbname>

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.