在postgres中删除db [英] drop db in postgres

查看:85
本文介绍了在postgres中删除db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在外壳中使用 dropdb mydbname 。它没有给出任何错误。但是当我打电话给 \l 时,它仍然存在。



我使用 sudo -u postgres psql 登录到postgres服务器。



除了主要关注点之外,我还需要了解如何进入数据库,而不仅仅是呆在数据库之外。 (例如,如果我要列出表)

解决方案

为了删除数据库,可以使用SQL命令(但是我不明白为什么dropdb无法正常工作) DROP DATABASE mydbname

  sudo -u postgres psql -c DROP DATABASE mydbname 

最好检查数据库

  select * from pg_stat_activity其中datname ='mydbname'; 

sudo -u postgres psql 连接到postgres数据库。您需要指定数据库: sudo -u postgres psql mydbname ,然后可以使用诸如\d,\dt,\dv,...之类的metdata命令。 p>

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)

解决方案

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

这篇关于在postgres中删除db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆