docker-compose rails rake db:reset 失败,“无法删除当前打开的数据库" [英] docker-compose rails rake db:reset fails, "cannot drop the currently open database"

查看:19
本文介绍了docker-compose rails rake db:reset 失败,“无法删除当前打开的数据库"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法在使用 docker compose 时重置我的数据库.我试过杀死服务器,只杀死数据库,然后重新启动机器.

I can't seem to reset my database while using docker compose. I've tried killing the server, killing just the database, and restarting the machine.

有人知道清除开发数据库的最佳方法吗?

Anyone know the best way to clear out the development database?

这是我尝试过的:

docker-compose run web rake db:reset

我收到此错误:

PG::ObjectInUse: 错误:无法删除当前打开的数据库:如果存在postgres",则删除数据库无法删除数据库postgres"耙子中止!

PG::ObjectInUse: ERROR: cannot drop the currently open database : DROP DATABASE IF EXISTS "postgres" Couldn't drop database 'postgres' rake aborted!

我使用的设置完全按照 docker-compose 快速入门中的描述:https://docs.docker.com/compose/rails/

I'm using the setup exactly as described by the docker-compose quickstart: https://docs.docker.com/compose/rails/

我有一个 rails 容器和一个 postgres 容器

I have a rails container and a postgres container

推荐答案

您使用了错误的数据库.

You are using the wrong database.

数据库postgres 通常不用于用户数据,而是用于管理目的.例如,如果要删除数据库,则必须连接到 PostgreSQL 数据库集群中的其他数据库才能发出 SQL 语句 DROP DATABASE.通常,数据库 postgres 用于此目的,我毫不怀疑 Docker 在尝试删除数据库时确实会这样做.

The database postgres is normally not used for user data, but for administrative purposes. For example, if you want to drop a database, you have to be connected to a different database in the PostgreSQL database cluster to issue the SQL statement DROP DATABASE. Normally, the database postgres is used for that purpose, and I have no doubt that Docker does exactly that when it tries to drop a database.

如果你真的想删除数据库postgres,你必须连接到集群中的其他数据库.然而,正确的解决方案是将您的数据保存在不同的数据库中.那么问题应该会自行消失.

If you really want to drop the database postgres, you'd have to connect to some other database in the cluster. The correct solution, however, is to keep your data in a different database. Then the problem should go away by itself.

这篇关于docker-compose rails rake db:reset 失败,“无法删除当前打开的数据库"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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