Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails-在服务器上创建postgres数据库时抛出错误“;无法连接到服务器:连接被拒绝;_Ruby On Rails_Postgresql - Fatal编程技术网

Ruby on rails Rails-在服务器上创建postgres数据库时抛出错误“;无法连接到服务器:连接被拒绝;

Ruby on rails Rails-在服务器上创建postgres数据库时抛出错误“;无法连接到服务器:连接被拒绝;,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我已经试着让我的应用程序运行了几天了,之前的所有问题都通过搜索得到了答案,但是我找不到解决这个问题的方法 因此,我成功地按照以下指南将我的应用程序部署到一个网络主机上: 现在,我进入了需要执行以下操作的步骤: RAILS_ENV=production bundle exec rake db:create 我这样做是为了部署@[server IP]并进入当前文件夹,但它会引发以下错误: could not connect to server: Connection refused Is

我已经试着让我的应用程序运行了几天了,之前的所有问题都通过搜索得到了答案,但是我找不到解决这个问题的方法

因此,我成功地按照以下指南将我的应用程序部署到一个网络主机上:

现在,我进入了需要执行以下操作的步骤:

RAILS_ENV=production bundle exec rake db:create
我这样做是为了部署@[server IP]并进入当前文件夹,但它会引发以下错误:

could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/connection_handling.rb:53:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:73:in `create'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:87:in `block in create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:183:in `block in each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:182:in `each_current_configuration'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/tasks/database_tasks.rb:86:in `create_current'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.1/lib/active_record/railties/databases.rake:20:in `block (2 levels) in <top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `call'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `block in execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `execute'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/deploy/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/task.rb:165:in `invoke'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:150:in `invoke_task'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/gems/rake-10.3.1/bin/rake:33:in `<top (required)>'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `load'
/home/deploy/musicBlog/shared/bundle/ruby/2.1.0/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"dbblog", "pool"=>5, "username"=>"postgres", "password"=>"[removed]", "host"=>"localhost"}
我使用与指南作者相同的主持人,并遵循相同的步骤,因此我不知道我做错了什么


我希望有人能帮助我,并提前表示感谢

首先要检查的是您的本地Postgres实例是否正在运行:

ps -ef | grep postgres
如果是的话,它在哪个端口上运行
5432是默认值,因此,如果您在配置方面没有做任何特殊的操作,那么它应该在那里运行


另外:您正在执行
rake
的服务器是否与运行
Postgres
的服务器相同?

您是否在
Gemfile
中添加了
gem'pg'
?是的,我想如果我没有,我在运行
cap production deploy
时可能会出错。我在服务器和本地都使用了该命令,两者都提供了这种输出:
deploy12251067011:03 pts/0 00:00:00 grep--color=auto postgres
(只有本地有七行或八行)我不知道如何检查它运行的端口,但我没有配置任何东西,所以这应该很好(localhost不是自动端口
5432
)这就是全部输出?应该有一系列与postgres相关的进程,包括
postmaster守护进程
进程,该进程可能以
bin\postgres
结尾,并且应该包括数据目录的路径,在那里可以查看端口配置为什么(只是为了仔细检查)。还应该有其他过程,例如
walwriter
。最后一个就是grep本身,所以它总是会出现。是的,就是它。如果我在本地运行它,它会输出更多的内容,还有
walwriter
进程,但不是postmaster守护进程(但是,这是本地的,问题出在服务器上)。我的服务器的
bin
中也没有postgres文件夹。如果在服务器上这是唯一的输出,那么postgres似乎没有在那里运行,这就是为什么你会收到那个错误信息。您在服务器上安装了
Postgres
,如您链接的Rails指南所述?如果是这样,你应该能够启动它。Postgres通常不会位于
bin
中。
/etc/init.d
中是否有以
postgresql
开头的文件?好的,非常感谢!多亏了你的帮助和一些谷歌搜索,我成功地启动了数据库,现在每当我运行
RAILS\u ENV=production bundle exec rake db:create
I get:
FATAL:user“postgres”的密码验证失败
我尝试使用
sudo-u postgres psql
更改密码,然后
ALTER USER postgres password'newPassword'(我将密码设置为与database.yml中相同的密码,我非常确定这一点),但仍然会出现密码验证错误。
ps -ef | grep postgres