【问题标题】:Running queries in my new PostgreSQL production database在我的新 PostgreSQL 生产数据库中运行查询
【发布时间】:2016-12-27 00:59:05
【问题描述】:

我刚刚将我在 Cloud9 中构建的 Rails 应用程序启动到 Heroku(哇哦!)。我的默认数据库是 sqlite3,所以在部署过程中,我在我的 gem 中添加了 PostgreSQL:

# Use postgresql as the database in production
group :production do
  gem 'pg'
end
# Use sqlite3 as the database in development
group :development do
  gem 'sqlite3'
end

我想将我的 sqlite3 数据库保持在开发中,并将 PostgreSQL 用于生产。我的问题是如何在我的生产 Heroku 站点中监控或运行对 PostgreSQL 数据的查询。

我习惯于在终端中运行“rails c”然后运行“User.all”来查看我的用户。现在,如果我运行它,它不会显示任何生产数据。我如何查看这些数据?我做了一些搜索,我想我应该使用“psql”命令。但是,例如,如果我运行“psql -l”,我会得到:

psql: could not connect to server: Connection refused
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

【问题讨论】:

    标签: ruby-on-rails postgresql heroku sqlite


    【解决方案1】:

    如果您只想在 Heroku 生产环境中运行一些 PostgreSQL 查询,请在终端中输入以下命令:

    heroku pg:psql (or heroku pg:psql -a your-heroku-app-name)
    

    在这里,您将能够运行诸如select * from users 之类的查询。退出终端输入\q

    您也可以使用

    调用 Heroku 生产控制台
    heroku run console (or heroku run console -a your-heroku-app-name)
    

    运行像User.all这样的查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多