【问题标题】:FATAL: database "postgres" does not exist致命:数据库“postgres”不存在
【发布时间】:2012-06-07 06:51:17
【问题描述】:

奇怪的错误。所有帮助表示赞赏。

这是我的 database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: app_development
  pool: 5
  username: username
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: app_test
  pool: 5
  username: username
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: app_production
  pool: 5
  username: username
  password:

当我手动创建数据库并尝试使用它们时,例如 rake db:test:preare 我收到以下错误:

FATAL:  database "postgres" does not exist

当我尝试删除数据库时,出现以下错误:

Couldn't drop app_development : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_test : #<PG::Error: FATAL:  database "postgres" does not exist
>
Couldn't drop app_production : #<PG::Error: FATAL:  database "postgres" does not exist

如果我尝试使用 rake db:create:all 创建数据库,我会收到以下错误:

app_development already exists
app_test already exists
app_production already exists

看来我的 database.yml 没问题。但由于某种原因,它正在寻找一个名为 postgres 的数据库,而这不是我的 database.yml 中的内容。

任何帮助表示赞赏。

编辑:

这里有更多来自 rake 的痕迹:

无法为 {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"app_production", "pool"=>5, "username"=>" 创建数据库用户名", "密码"=>无}

【问题讨论】:

    标签: ruby-on-rails postgresql


    【解决方案1】:

    我使用的是 Mac OS X,我在使用 python 和 sqlalchemy 时遇到了同样的问题。 就像 Flavio 建议的那样,检查 postgresapp 并检查如何连接部分。

    from sqlalchemy import create_engine
    engine = create_engine('postgresql://localhost/[YOUR_DATABASE_NAME]')
    

    【讨论】:

      【解决方案2】:

      [Mac OS X] 我在使用 Linux 时从未遇到过 PostGreSQL 的任何问题。但是,我开始使用 MacBook 并遇到与您相同的错误。所以... 可能这不是您期望的解决方案,但这个应用程序解决了我所有的头痛问题。我只是想和你们分享。

      http://postgresapp.com/

      【讨论】:

        【解决方案3】:

        你还没有说你是否真的有一个 postgres 数据库,这是错误所抱怨的。

        大概不会,而且这个“rake”工具正在以用户 postgres 的身份连接到数据库 postgres,因此它可以创建新的数据库。显然,它需要以某人的身份进行连接才能做任何事情。

        请务必花时间浏览 PostgreSQL 手册并了解如何启用/控制日志记录。从长远来看,它将为您提供良好的服务。我猜也有 rake/rails 的调试/日志设置。

        【讨论】:

        • 您好,感谢您的回复。我确实有一个 postgres 数据库,并且在过去的 6 个月里一直将它用于 Rails 应用程序,没有任何戏剧性。如果我使用 postgres 尝试我的其他应用程序,一切都会很好。不确定这个。我会一直在查看 rake 跟踪但找不到任何东西
        • @user1432031:Richard 的意思不是“一个 postgres 数据库”,而是“一个 named postgres 数据库”——它通常是在安装数据库服务器时创建的。
        • 嘿,这似乎奏效了。我添加了一个数据库 postgres,现在乍一看,我的其他 Rails 数据库没有任何问题。在没有这个额外数据库的情况下,我的其他 Rails 数据库之前也可以使用。你们知道为什么会这样吗?
        • @user1432031:正如我所说:默认情况下,安装期间会创建一个 postgres 数据库。所以我猜你其他安装确实做到了,而新安装没有(无论出于何种原因)
        • postgres 服务数据库是 8.0 时代左右的一个相对较新的发明。如果 OP 使用的是非常旧的 pg 版本,它可能不会附带 postgres db。
        猜你喜欢
        • 1970-01-01
        • 2013-07-29
        • 1970-01-01
        • 2016-08-27
        • 2015-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多