【问题标题】:Can't connect to postgres with 'pg' gem?无法使用 'pg' gem 连接到 postgres?
【发布时间】:2017-10-06 11:25:21
【问题描述】:

我有以下代码尝试测试与 postgres 的连接:

require 'pg'

conn = PGconn.connect("localhost", 5432, '', '', "puppetdb", "puppetdb", "puppetbdb")
res  = conn.exec('select tablename, tableowner from pg_tables')

我得到了错误:

test.rb:3:in initialize': FATAL: password authentication failed for user "puppetdb" (PG::ConnectionBad) from test.rb:3:innew' 来自 test.rb:3:in `'

但我有一个具有相同凭据的 python 脚本,似乎可以完美运行:

import psycopg2

try:
    conn = psycopg2.connect("dbname='puppetdb' user='puppetdb' host='localhost' port='5432' password='puppetdb'")

鉴于 python 脚本,我想知道我是否输入了错误的凭据?

【问题讨论】:

  • localhost172.17.0.1 不一样
  • 是的@C-Otto 我正在更新 python 脚本以读取本地主机。我刚刚在本地进行了测试,python 脚本适用于两个 URL。由于 Docker 网络正在共享到我的本地主机。

标签: ruby postgresql pg


【解决方案1】:

您的密码有误(puppetbdb):

conn = PGconn.connect("localhost", 5432, '', '', "puppetdb", "puppetdb", "puppetdb")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-12
    • 2013-11-15
    • 1970-01-01
    • 2019-12-25
    • 2021-09-04
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    相关资源
    最近更新 更多