PG::InvalidParameterValue:错误:参数“client_min_messages”的无效值:“panic”

use*_*894 25 ruby postgresql activerecord rubygems ruby-on-rails

rake db:create 显示错误 PG::InvalidParameterValue: 错误:参数“client_min_messages”的无效值:“panic” 提示:可用值:debug5、debug4、debug3、debug2、debug1、log、notice、warning、error。

捆绑安装后尝试运行 rake db:create commond。在 config 文件夹中创建的 database.yml 文件请在下面找到:

development:
  adapter: postgresql
  encoding: utf8
  database: thor_development1
  username: postgres
  password:
  host: localhost

test:
  adapter: postgresql
  encoding: utf8
  database: thor_test1
  username: postgres
  password:
  host: localhost
Run Code Online (Sandbox Code Playgroud)
PG::InvalidParameterValue: ERROR:  invalid value for parameter "client_min_messages": "panic"
HINT:  Available values: debug5, debug4, debug3, debug2, debug1, log, notice, warning, error.
: SET client_min_messages TO 'panic'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `async_exec'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activesupport-4.1.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql/schema_statements.rb:274:in `client_min_messages='
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:634:in `set_standard_conforming_strings'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:914:in `configure_connection'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:895:in `connect'
/Users/galaxy/.rvm/gems/ruby-2.1.2@folderName/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
Run Code Online (Sandbox Code Playgroud)

尝试在 macOS Catalina 中安装

rus*_*lan 63

为了使其适用于 PostgreSQL 版本 12,我对 PostgreSQLAdapter 类进行了猴子修补,以将“恐慌”替换为“警告”消息。请注意,如果您可以将 activerecord gem 升级到 4.2.6 或更高版本,则不需要此猴子补丁。我必须这样做,因为我的项目依赖于 gemactiverecord-3.2.22.5

require 'active_record/connection_adapters/postgresql_adapter'

class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  def set_standard_conforming_strings
    old, self.client_min_messages = client_min_messages, 'warning'
    execute('SET standard_conforming_strings = on', 'SCHEMA') rescue nil
  ensure
    self.client_min_messages = old
  end
end
Run Code Online (Sandbox Code Playgroud)

  • @orberkov你需要创建一个新文件。我将其命名为“postgresql_adapter_monkeypatch.rb”并将其放在rails目录config/initializers/中。 (8认同)
  • @ruslan我在Heroku上也遇到了同样的“数据库配置指定不存在的postgresql适配器”错误,所以我还必须在“require 'active_record/connection_adapters/postgresql_adapter'”之前“require 'active_record/base'”。 (3认同)
  • 我在将 postgres 9.1 升级到 12(Rails 3) 时遇到同样的问题。我尝试在配置/初始值设定项中使用上述补丁,但出现错误:“ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specation.rb:133:in `built_connection':数据库配置指定不存在的 postgresql 适配器 (ActiveRecord::AdapterNotFound)" (2认同)

Mik*_*Mik 9

我遇到了完全相同的问题,我终于弄清楚了它是什么。我在我的 gems 文件夹中搜索了“panic”这个词,并在我的 ActiveRecord 4.2.2 gem 的第 313 行中找到了一个命中。我修补了文件,将值更改为“错误”,然后我就能够继续执行 db:create rake 任务。似乎 ActiveRecord gem 已更改,或者 pg gem 已更改,即使我使用的是两者的旧特定版本,因为几周前我能够运行 db:create,但现在不能没有这个黑客。

特尔;博士:

gem info pg
Run Code Online (Sandbox Code Playgroud)

cd 到它安装的文件夹(对我来说,~/.rvm/gems/ruby-2.3.0/gems)

grep -ri 'panic' .
Run Code Online (Sandbox Code Playgroud)

用“错误”或其他一些有效消息替换与 pg 相关的任何内容。

  • 就我而言,我所做更改的文件是 `...gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb` 。 (3认同)

x-y*_*uri 9

在 PostgreSQL 12 中,他们不允许PANIC使用Rails自 2.3.14 以来client_min_messages设置的。这是在Rails 4.2.5中修复的。

因此升级 Rails 可以解决这个问题。更详细报告的链接,了解其价值。


小智 8

我在旧的 Rails 版本上遇到了 pg12 的两个问题。该文件修复了 ruby​​ 1.8 和 activerecord 3.0.3 的两个问题。我把它放在 config/initializers/postgresql_adapter_pg12.rb 中

require 'active_record/connection_adapters/postgresql_adapter'

class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  def set_standard_conforming_strings
    old, self.client_min_messages = client_min_messages, 'warning'
    execute('SET standard_conforming_strings = on', 'SCHEMA') rescue nil
  ensure
    self.client_min_messages = old
  end

  def column_definitions(table_name) #:nodoc:
    query <<-end_sql
      SELECT a.attname, format_type(a.atttypid, a.atttypmod), pg_get_expr(d.adbin, d.adrelid), a.attnotnull
        FROM pg_attribute a LEFT JOIN pg_attrdef d
          ON a.attrelid = d.adrelid AND a.attnum = d.adnum
       WHERE a.attrelid = '#{quote_table_name(table_name)}'::regclass
         AND a.attnum > 0 AND NOT a.attisdropped
       ORDER BY a.attnum
    end_sql
  end
end
Run Code Online (Sandbox Code Playgroud)


Fre*_*ore 6

我需要对 @ruslan 的猴子补丁进行以下修改才能使用 Rails 4.2.4:

require 'active_record/connection_adapters/postgresql_adapter'

module ActiveRecord
  module ConnectionAdapters
    class PostgreSQLAdapter
      def set_standard_conforming_strings
        old, self.client_min_messages = client_min_messages, 'warning'
        execute('SET standard_conforming_strings = on', 'SCHEMA') rescue nil
      ensure
        self.client_min_messages = old
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)