简体   繁体   English

db:migrate(PostgreSQL)在使用Capistrano进行Rails部署时失败

[英]db:migrate (PostgreSQL) fails on Rails deployment with Capistrano

I'm a complete noob to deploying Rails and even more new to PostgreSQL. 对于部署Rails以及对PostgreSQL来说更多,我是一个完全的菜鸟。 I'm running a CentOS 6.6 server and my deployment tasks keep failing with the following db:migrate errors: 我正在运行CentOS 6.6服务器,并且部署任务始终失败,并出现以下db:migrate错误:

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
SSHKit::Command::Failed: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/command.rb:95:in `exit_status='
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:179:in `block in _execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:16:in `block (5 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:85:in `with'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:15:in `block (4 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/abstract.rb:77:in `within'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/capistrano-rails-1.1.3/lib/capistrano/tasks/migrations.rake:14:in `block (3 levels) in <top (required)>'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/home/me/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => deploy:migrate
The deploy has failed with an error: Exception while executing as deploy@xxx.xxx.xxx.xxx: rake exit status: 1
rake stdout: /var/www/rally_app/shared/bundle/ruby/2.2.0/gems/fog-1.23.0/lib/fog/rackspace/mock_data.rb:42: warning: duplicated key at line 80 ignored: "name"
rake aborted!
PG::ConnectionBad: FATAL:  no pg_hba.conf entry for host "::1", user "me", database "pg_sampleapp", SSL off
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:436:in `new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:446:in `checkout_new_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:565:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:87:in `connection'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:913:in `initialize'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `new'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:820:in `up'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/migration.rb:798:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/var/www/rally_app/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
rake stderr: Nothing written
** Invoke deploy:failed (first_time)
** Execute deploy:failed
[me@localhost rally_app]$ 

Thanks for any help. 谢谢你的帮助。

Alexis 亚历克西斯

Your user "me" does not have permissions to connect to your database. 您的用户“我”没有连接到数据库的权限。 Permissions are defined in Postgres' pg_hba.conf . 权限在Postgres的pg_hba.conf中定义。 I haven't used CentOS, but from what I can gather, you should be able to find that file at /var/lib/pgsql/<your Postgres version>/data . 我没有使用过CentOS,但从我的收集中,您应该能够在/var/lib/pgsql/<your Postgres version>/data找到该文件。

Open the config file in your text editor (you might need to run it with sudo in order to have permission to edit it), then scroll to the end. 在文本编辑器中打开配置文件(您可能需要使用sudo运行它才能获得编辑权限),然后滚动到末尾。

Adding this line: 添加此行:

host    pg_sampleapp             me             ::1/128                 password

gives your user me the permission to access the database pg_sampleapp after providing the correct password — but only from localhost, meaning from within your server itself and not when connecting to it from the outside. 在提供正确密码后,向me授予用户访问数据库pg_sampleapp的权限-但只能从本地主机访问,这意味着从服务器内部进行访问,而不是从外部连接至服务器。

You can make the permissions more broad by replacing pg_sampleapp and me with all , meaning that locally all Postgres users can connect to all databases. 您可以通过更换权限更加广阔pg_sampleappmeall ,这意味着当地所有的Postgres用户可以连接到所有数据库。 If you want extra convenience and are not worried about security, you can also replace password with trust , meaning you can connect directly without providing any password: 如果您想要额外的便利并且不担心安全性,还可以用trust替换password ,这意味着您可以直接连接而无需提供任何密码:

host    all             all             ::1/128                 trust

After adding the permissions, you need to reload Postgres via service postgresql-9.4 restart (if you have Postgres 9.4 installed, otherwise change the version accordingly). 添加权限后,您需要通过service postgresql-9.4 restart加载Postgres(如果已安装Postgres 9.4,否则请相应地更改版本)。

You can test whether it works correctly by trying to log into the database with psql pg_sampleapp me . 您可以通过尝试使用psql pg_sampleapp me登录数据库来测试其是否正常工作。 If it does, quit psql with CTRL+D. 如果是这样,请使用CTRL + D退出psql。

See the Postgres documentation on pg_hba.conf for more information — it's quite readable and very detailed. 有关更多信息,请参见pg_hba.conf上Postgres文档 -它非常易读且非常详细。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM