Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drop db in postgres

Tags:

postgresql

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)

like image 539
dinesh707 Avatar asked Dec 17 '25 07:12

dinesh707


2 Answers

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, ...

like image 101
mys Avatar answered Dec 19 '25 23:12

mys


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.

like image 27
Craig Ringer Avatar answered Dec 20 '25 00:12

Craig Ringer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!