38

rake db:create showing error PG::InvalidParameterValue: ERROR: invalid value for parameter "client_min_messages": "panic" HINT: Available values: debug5, debug4, debug3, debug2, debug1, log, notice, warning, error.

After bundle install tried to run rake db:create commond. Created database.yml file inside the config folder please find below :

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
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'

Trying to install in macOS Catalina

5
  • Can you provide us with your config/database.yml?
    – Aurelien
    Nov 8, 2019 at 9:23
  • Aurelien added database.yml code please check Nov 8, 2019 at 9:42
  • I don't understand why your default min_messages is set to 'panic'. You can try to set min_messages: notice in development
    – Aurelien
    Nov 8, 2019 at 9:47
  • code did not work :( Nov 8, 2019 at 11:28
  • What is the error? Here is an example: github.com/rails/rails/blob/…
    – Aurelien
    Nov 9, 2019 at 17:31

10 Answers 10

77

To make it work with PostgreSQL version 12, I monkey patched PostgreSQLAdapter class to replace 'panic' with 'warning' message. Note, if you can upgrade activerecord gem to 4.2.6 or higher versions you don't need to have this monkey patch. I had to do this because my project depends on gem activerecord-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
5
  • 9
    @orberkov you need to create a new file. I named it as 'postgresql_adapter_monkeypatch.rb' and put it in the rails directory config/initializers/.
    – ruslan
    Dec 16, 2019 at 18:16
  • 2
    I am facing same issue while upgrading postgres 9.1 to 12(Rails 3). I tried using above patch in config/initializers, but i am getting error: "ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/connection_adapters/abstract/connection_specification.rb:133:in `establish_connection': database configuration specifies nonexistent postgresql adapter (ActiveRecord::AdapterNotFound)"
    – pooja
    Aug 13, 2020 at 10:27
  • @pooja it seems your activerecord gem is older version than what I described before. Try upgrading activerecord to v3.2.22.5 version and see if it helps.
    – ruslan
    Aug 14, 2020 at 8:32
  • 3
    @ruslan I've had the same database configuration specifies nonexistent postgresql adapter error on Heroku, so I also had to require 'active_record/base' before require 'active_record/connection_adapters/postgresql_adapter'.
    – lacrosse
    Dec 16, 2020 at 0:39
  • Totally awesome, thanks! I would upvote this answer +100 if I could! This just saved us from having to upgrade/update a legacy Rails app in production that is about to be retired but needs a few more months runway to migrate customers. Sending some real-life Karma your way! :) Mar 17, 2021 at 11:46
11

I had the exact same problem, and I finally figured out what it was. I grepped for the word "panic" inside of my gems folder, and got a hit in my ActiveRecord 4.2.2 gem, line 313. I monkey-patched the file, changing the value to "error", and I was then able to proceed with the db:create rake task. It seems likely that the ActiveRecord gem was changed, or the pg gem was changed, even though I'm using old, specific versions of both, because I was able to run db:create a few weeks ago, but now couldn't without this hack.

TL;DR:

gem info pg

cd to the folder where it's installed (for me, ~/.rvm/gems/ruby-2.3.0/gems)

grep -ri 'panic' .

Replace anything related to pg with 'error' or some other valid message.

2
  • 3
    In my case the file I made changes is ...gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb . Jan 16, 2020 at 6:53
  • If someone is lost like i am, this answer worked for me. I have searched the postgresql_adapter.rb in the /.rvm/gems/ folder, opened the file in editor and just replaced the "panic" in self.client_min_messages = client_min_messages, 'panic' with "warning". Feb 24, 2021 at 9:40
9

In PostgreSQL 12 they disallowed the PANIC value for client_min_messages, that Rails was setting since 2.3.14. That was fixed in Rails 4.2.5.

As such upgrading Rails resolves the issue. A link to a more detailed report, for what it's worth.

8

I ran into two problems with pg12 on old rails versions. This file fixes both problems with ruby 1.8 and activerecord 3.0.3. I put it in 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
2
  • Thank you very much, this saved me with a legacy app using active record 3.1.12. The extra column_definition patch seems to be required for versions that old.
    – bappelt
    Oct 8, 2021 at 15:09
  • Thank you so much.. Adding this I resolved the issue and now the app is connected to PostgreSQL 13.7 on Amazon Aurora..
    – Alvaro
    Oct 17, 2022 at 21:09
7

I needed to make the following modifications to the monkey patch from @ruslan to work with 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
1

I got this issue with Postgres 12.1 and I need to roll back to 9.4 and was solved.

1
  • I am using ruby 1.9.3 with rails v 3+, and based on your comment I realized that it is in fact correct these version of ruby on rails works perfectly on Postgres <= 9.4 @lucas Nov 4, 2020 at 1:31
1

In the .rvm/gems/ruby-2.3.3/gems/active_record-4.1.9/lib/active_record/connection_adapters/postgresql_adapter.rb file, Change the value of client_min_messages to anything other than panic. The valid values can be - debug5, debug4, debug3, debug2, debug1, log, notice, warning, error.

The issue is with the newer versions of Postgresql adapter in ActiveRecord where panic is the new and the default value and old Postgres versions do not support that.

0

I was also facing the same issue. I was using postgres 9.4.1 and upgraded to latest (12.1). Because of the version change, I got this issue. I reverted back to 9.4.1. Is that same with you as well?

2
  • I believe you should able to upgrade to at least 9.6 version.
    – ruslan
    Dec 17, 2019 at 16:49
  • This should have been a comment, not an "answer"
    – Caleb
    Dec 12, 2020 at 13:16
0

In the given log says:-

/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='

Go to the schema statements.rb file at line 274 and assign `client_min_messages=' with any of these below values.

debug5, debug4, debug3, debug2, debug1, log, notice, warning, error

0

No need to monkey patch or anything. login to your postgresql via command line and create database from there and grant the privileges from there.

use the below command for this.

#to login
psql
#to create database
CREATE DATABASE super_awesome_application;
#grant the permission to the database for that user
GRANT ALL PRIVILEGES ON DATABASE super_awesome_application TO patrick;
#if you have not that user in you database create one 
CREATE USER sam WITH PASSWORD 'password';
#alter the role permission 
ALTER ROLE sam WITH SUPERUSER;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.