【问题标题】:ruby&postgres Ruby connects to database error in macOS environmentruby&postgres Ruby 连接到 macOS 环境中的数据库错误
【发布时间】:2022-01-22 13:42:33
【问题描述】:

这是我的数据库.rb

#!/usr/bin/ruby
require 'postgres'

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

res  = conn.exec('select tablename, tableowner from pg_tables')

res.each do |row|
    row.each do |column|
        print column
        (20-column.length).times{print " "}
    end
    puts
end

可执行文件: ruby 数据库.rb

Traceback (most recent call last):
  11: from database.rb:4:in `<main>'
  10: from database.rb:4:in `new'
   9: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:28:in `initialize'
   8: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/postgres-compat.rb:28:in `new'
   7: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/connection.rb:58:in `initialize'
   6: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/connection.rb:58:in `loop'
   5: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/connection.rb:59:in `block in initialize'
   4: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/message.rb:58:in `read'
   3: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/message.rb:116:in `create'
   2: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/message.rb:137:in `parse'
   1: from /Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/message.rb:82:in `parse'
/Library/Ruby/Gems/2.6.0/gems/postgres-pr-0.7.0/lib/postgres-pr/message.rb:139:in `block in parse': undefined method `auth_type' for #<PostgresPR::UnknownAuthType:0x0000000133830f98> (NoMethodError)

接下来我该怎么做?

【问题讨论】:

    标签: ruby postgresql rubygems


    【解决方案1】:

    我认为 PGconn 不支持 ''(空字符串)作为选项和 tty 值。

    您是否尝试过将它们设置为 nil:

    PGconn.connect("localhost", 5432, nil, nil, "postgres", "postgres", "postgre")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      • 2015-08-14
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多