(Ruby)带PG的ActiveRecord尝试与本地用户连接到远程服务器

(Ruby)带PG的ActiveRecord尝试与本地用户连接到远程服务器,ruby,postgresql,activerecord,pg,Ruby,Postgresql,Activerecord,Pg,我制作了一个简单的编码ruby程序,用于从远程服务器获取备份,并在postgresql中制作了一个db,用于保存信息和安排备份 与数据库的连接是使用ActiveRecord完成的,我配置为访问内部数据库(在其他服务器中),但当我尝试连接到远程数据库时,我收到以下消息: /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `initialize': FATAL: no existe el

我制作了一个简单的编码ruby程序,用于从远程服务器获取备份,并在postgresql中制作了一个db,用于保存信息和安排备份

与数据库的连接是使用ActiveRecord完成的,我配置为访问内部数据库(在其他服务器中),但当我尝试连接到远程数据库时,我收到以下消息:

/usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `initialize': FATAL:  no existe el rol <<mi_user_name>> (PGError)
    from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `connect'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:968:in `connect'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:223:in `send'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:184:in `loop'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
    from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
    from /usr/lib/ruby/1.8/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
    from /usr/lib/ruby/1.8/active_record/base.rb:3113:in `quoted_table_name'
    from /usr/lib/ruby/1.8/active_record/base.rb:1684:in `construct_finder_sql'
    from /usr/lib/ruby/1.8/active_record/base.rb:1548:in `find_every'
    from /usr/lib/ruby/1.8/active_record/base.rb:1505:in `find_initial'
    from /usr/lib/ruby/1.8/active_record/base.rb:613:in `find'
    from main.rb:84:in `main'
    from main.rb:126
我正在使用Ruby 1.8.7

你知道吗

谢谢你的阅读,帮帮我

格雷廷斯

编辑

我找到了解决办法:

我使用了:user,并且必须是:username。
真丢脸。

从错误消息中,Postgres似乎认为数据库中不存在您的用户

解决这个问题的一个好的第一步是尝试在不涉及Ruby的情况下进行连接。由于“psql”命令行客户端使用相同的底层库(假设您使用“pg”gem进行连接),一般来说,如果您可以使用它进行连接,那么您也可以从Ruby进行连接

试试这个:

psql -h xxx.xxx.x.101 -U pg_user -W -l
如果这显示了相同的错误(
no existe el-rol
),那么您需要确认您的用户存在,并创建它


如果它向您显示数据库列表,我们将不得不尝试其他操作。

从错误消息中,Postgres似乎认为数据库中不存在您的用户

解决这个问题的一个好的第一步是尝试在不涉及Ruby的情况下进行连接。由于“psql”命令行客户端使用相同的底层库(假设您使用“pg”gem进行连接),一般来说,如果您可以使用它进行连接,那么您也可以从Ruby进行连接

试试这个:

psql -h xxx.xxx.x.101 -U pg_user -W -l
如果这显示了相同的错误(
no existe el-rol
),那么您需要确认您的用户存在,并创建它


如果它向您显示数据库列表,我们将不得不尝试其他方法。

谢谢您的回复,但这将向我显示数据库列表:(感谢您的回复,但这会显示数据库列表:(
psql -h xxx.xxx.x.101 -U pg_user -W -l