1

リモートサーバーからバックアップを取得するための単純なコーディング Ruby プログラムを作成し、情報を保存してバックアップをスケジュールするために postgresql でデータベースを作成しました。

DB との接続は ActiveRecord で行われました。内部 DB (他のサーバー内) にアクセスするように構成しましたが、リモート DB に接続しようとすると、次のメッセージが表示されます。

/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

PG はローカル ユーザーでリモート db に接続しようとします。ActiveRecord の宣言で、次のパラメーターを設定します。

require 'active_record'

    ActiveRecord::Base.establish_connection(
        :adapter  => "postgresql",
        :host     => "xxx.xxx.x.101",
        :port     => 5432,
        :database => "VB_DB",
        :user     => "pg_user",
        :password => "blahblah"
    )

私はRuby 1.8.7で作業しています。

これについて何か考えはありますか?

読んでくれてありがとう、そして私を助けてください。

ご挨拶。

編集

私は解決策を見つけました:

    ActiveRecord::Base.establish_connection(
        :adapter  => "postgresql",
        :host     => "xxx.xxx.x.101",
        :port     => 5432,
        :database => "VB_DB",
        :username => "pg_user",
        :password => "blahblah"
    )

:user を使用しましたが、:username である必要があります。私を恥じてください。

4

1 に答える 1

1

エラー メッセージから、Postgres はユーザーがデータベースに存在するとは認識していないようです。

これをトラブルシューティングするための適切な最初のステップは、Ruby をまったく使用せずに接続を試みることです。'psql' コマンドライン クライアントは同じ基本ライブラリを使用するため (接続に 'pg' gem を使用していると仮定します)、通常、それを使用して接続できる場合は、Ruby からも接続できます。

これを試して:

psql -h xxx.xxx.x.101 -U pg_user -W -l

これで同じエラー ( no existe el rol <<mi_user_name>>) が表示される場合は、ユーザーが存在することを確認して作成する必要があります。

データベースのリストが表示される場合は、別のことを試す必要があります。

于 2011-08-22T22:32:37.033 に答える