Reputation: 12582
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)
Upvotes: 2
Views: 23853
Reputation: 3156
dropdb -h <ip> -p 5432 -U postgres --if-exists --echo <dbname>
Upvotes: 0
Reputation: 2762
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>
Upvotes: 2
Reputation: 1077
Are you missing the comma(;)? This command worked for me:
drop database <database_name>;
Upvotes: 4
Reputation: 324265
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.
Upvotes: 5
Reputation: 2473
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, ...
Upvotes: 6