【问题标题】:How do I set up a postgresql database on Dotcloud?如何在 Dotcloud 上设置 postgresql 数据库?
【发布时间】:2012-06-13 05:17:47
【问题描述】:

我正在尝试将 Rails 应用上传到 dotcloud。

我收到此错误:

PG::Error (could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
):
  activerecord (3.2.5) lib/active_record/connection_adapters/postgresql_adapter.rb:1206:in `initialize'

我猜是因为我还没有设置 postgres 数据库。我怎么做?文档似乎没有说。

我的 dotcloud.yml 文件如下所示:

www:
  type: ruby
  exclude_bundler_groups:
    - development
data:
  type: postgresql

我的 database.yml 看起来像这样:

production:
  adapter: postgresql
  database: my_app_production # have not set this up on dotcloud yet as I can't find any docs on how to do it
  username: root
  password: mypassword

我必须运行迁移吗?我该怎么做,文档又没有说。

是否有在 dotcloud 上设置 rails 应用程序的白痴指南?我从 Heroku 过来,你只需推送代码并运行迁移。我花了好几个小时在 dotcloud 文档上苦苦挣扎,但无法让这个应用程序运行。

【问题讨论】:

    标签: ruby-on-rails postgresql dotcloud


    【解决方案1】:

    使用该 yaml 文件创建应用程序后,例如“dotcloud push APPNAME app-on-dotcloud/”,您应该运行此行“dotcloud APPNAME.data info”并获得所有连接到数据库的信息,您可以添加到database.yml

    更新

    您已经获得了访问 postgresql 终端的所有信息:用户、密码、端口和主机。您需要运行“dotcloud ssh APPNAME.www”,因为您使用“psql -h myapp-myname.dotcloud.com -p 29876 -U root”连接到 postgresql,然后输入您的密码。最后,使用“CREATE DATABASE 'dbname';”创建您的数据库并更新您的 database.yml。

    【讨论】:

    • 谢谢,但运行 dotcloud APPNAME.data info 不会显示数据库的名称。我得到一个带有config: postgresql_password: xyz, ports: url: pgsql://root:mypassword@myapp-myname.dotcloud.com:29876, type: postgresql 之类的json 格式的哈希,但没有提到数据库名称。我错过了什么吗?
    • @stephenmurdoch 你需要自己创建数据库,你可以指定任何你想要的名字。来自 dotcloud info 命令的信息为您提供连接到数据库和创建数据库所需的信息。如果您按照此页面上的步骤操作,它将向您展示如何创建数据库。 docs.dotcloud.com/services/postgresql
    • 啊,谢谢,有道理,今晚我会解决这个问题,再次感谢。干杯
    • 如果您不想经历创建数据库的麻烦,您可以使用“template1”,但这仅适用于非常懒惰的人:-)