PG::ConnectionBad: invalid connection option "fallback_application_name" against Postgres 9.3

Issue #181 invalid
Ben Batha
created an issue

I receive the above error when running against postgres9.3 running 0.17.0 and 0.17.1. I also tried a more recent version of sequel (4.7.0) and get the same error. I was ultimately forced to downgrade to 0.16.0 after inspecting the changelogs and seeing that the "fallback_application_name" was added for the 0.17.0 release.

Dump from the log

$APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/postgres.rb:216:in `initialize': PG::ConnectionBad: invalid connection option "fallback_application_name" (Sequel::DatabaseConnectionError)
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/postgres.rb:216:in `connect'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/postgres.rb:216:in `connect'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool.rb:96:in `make_new'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:158:in `make_new'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:137:in `available'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:127:in `acquire'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:194:in `sync'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:194:in `synchronize'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:194:in `sync'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:126:in `acquire'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/connection_pool/threaded.rb:94:in `hold'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/database/connecting.rb:229:in `synchronize'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/shared/postgres.rb:439:in `server_version'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/shared/postgres.rb:1462:in `server_version'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/shared/postgres.rb:1422:in `select_clause_methods'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/sql.rb:824:in `send'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/sql.rb:824:in `clause_sql'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/sql.rb:134:in `select_sql'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:143:in `each'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel_pg-1.6.8/lib/sequel_pg/sequel_pg.rb:58:in `each'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:391:in `map'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:391:in `map'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel_pg-1.6.8/lib/sequel_pg/sequel_pg.rb:24:in `map'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/adapters/shared/postgres.rb:997:in `schema_parse_table'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/database/query.rb:158:in `schema'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/model/base.rb:703:in `get_db_schema'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/model/base.rb:639:in `check_non_connection_error'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/model/base.rb:703:in `get_db_schema'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/model/base.rb:258:in `db_schema'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/plugins/auto_validations.rb:106:in `setup_auto_validations'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/plugins/auto_validations.rb:60:in `configure'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/plugins/auto_validations.rb:59:in `instance_eval'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/plugins/auto_validations.rb:59:in `configure'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/sequel-4.3.0/lib/sequel/model/base.rb:427:in `plugin'
        from ./models/major.rb:4
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from ./models/init.rb:27
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from ./app.rb:73
        from config.ru:4:in `require'
        from config.ru:4
        from $APPROOT/vendor/bundle/ruby/1.8/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
        from $APPROOT/vendor/bundle/ruby/1.8/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
        from config.ru:1:in `new'
        from config.ru:1

Comments (8)

  1. Michael Granger repo owner

    Hi Ben

    Thanks for the ticket, but are you sure you're connecting to a 9.0+ server? I use Sequel every day, all day, and have been using 4.7.0 with a 9.3 server since those versions were available. Here's what it looks like when I connect, both from PG itself and via Sequel:

    [1] pry(main)> PG::VERSION
    => "0.17.1"
    [2] pry(main)> Sequel::VERSION
    => "4.7.0"
    [3] pry(main)> conn = PG.connect( dbname: 'test', fallback_application_name: 'foo' )
    => #<PG::Connection:0x007f9c93f6ad60
     @notice_processor=nil,
     @notice_receiver=nil,
     @socket_io=nil>
    [4] pry(main)> conn.server_version
    => 90300
    [5] pry(main)> db = Sequel.postgres( database: 'test' )
    => #<Sequel::Postgres::Database: {:adapter=>:postgres, :database=>"test"}>
    [6] pry(main)> db.server_version
    => 90300
    

    Here's the docs for the connection parameter: http://www.postgresql.org/docs/9.3/static/libpq-connect.html#LIBPQ-CONNECT-FALLBACK-APPLICATION-NAME

    Please let me know what you find!

  2. Ben Batha reporter

    I am running against postgres 9.3.1

    Testing a different box and application against the same db:

    irb(main):017:0> PG::VERSION
    => "0.17.0"
    irb(main):018:0> Sequel::VERSION
    => "4.3.0"
    irb(main):019:0> conn = PG.connect( :dbname => 'dbname', :host => 'host', :fallback_application_name => 'foo', :user => 'user', :password => 'pass')
    => #<PG::Connection:0x7f4f68294140>
    irb(main):020:0> conn.server_version
    => 90301
    irb(main):021:0> db = Sequel.postgres(:database => 'dbname', :host => 'host', :user => 'user', :password => 'pass')
    => #<Sequel::Postgres::Database: {:database=>"dbname", :password=>"pass", :user=>"user", :adapter=>:postgres, :host=>"host"}>
    irb(main):022:0> conn.server_version
    => 90301
    

    Working library setup:

    irb(main):016:0* PG::VERSION
    => "0.16.0"
    irb(main):017:0> Sequel::VERSION
    => "4.7.0"
    irb(main):020:0> conn = PG.connect( :dbname => 'dbname', :host => 'host', :user => 'user', :password => 'password')
    => #<PG::Connection:0x7f42e9ca5480>
    irb(main):021:0> conn.server_version
    => 90301
    irb(main):022:0> db = Sequel.postgres(:database => 'dbname', :host => 'host', :user => 'user', :password => 'pass')
    => #<Sequel::Postgres::Database: {:database=>"dbname", :password=>"pass", :user=>"user", :host=>"host", :adapter=>:postgres}>
    irb(main):023:0> db.server_version
    => 90301
    

    Broken library setup:

    irb(main):004:0> PG::VERSION
    => "0.17.1"
    irb(main):005:0> Sequel::VERSION
    => "4.7.0"
    irb(main):006:0> conn = PG.connect( :dbname => 'dbname', :host => 'host',  :fallback_application_name => 'foo', :user => 'user', :password => 'pass')
    PG::ConnectionBad: invalid connection option "fallback_application_name"
    
            from $APPROOT/vendor/bundle/ruby/1.8/gems/pg-0.17.1/lib/pg.rb:40:in `initialize'
            from $APPROOT/vendor/bundle/ruby/1.8/gems/pg-0.17.1/lib/pg.rb:40:in `new'
            from $APPROOT/vendor/bundle/ruby/1.8/gems/pg-0.17.1/lib/pg.rb:40:in `connect'
            from (irb):6
            from :0
    irb(main):007:0> conn.server_version
    NoMethodError: undefined method `server_version' for nil:NilClass
            from (irb):7
            from :0
    irb(main):008:0> db = Sequel.postgres(:database => 'dbname', :host => 'host', :user => 'user', :password => 'pass')
    => #<Sequel::Postgres::Database: {:database=>"dbname", :password=>"pass", :user=>"user", :adapter=>:postgres, :host=>"host"}>
    irb(main):009:0> db.server_version
    => 90301
    irb(main):010:0>
    
  3. Michael Granger repo owner

    Thanks for spending the time to try all of that. We'll get it sorted.

    Can you tell me what the results of:

    [8] pry(main)> PG.library_version
    => 90300
    

    look like for you?

  4. Lars Kanis

    There is some version mismatch between the library used at build time and the library used at runtime. I get the same error if I build against postgresql-9.3 but force linking against libpq from postgresql-8.3.

    LD_LIBRARY_PATH=/usr/local/pgsql-8.3/lib/ irb -rpg
    2.1.0 :001 > PGconn.new host:'localhost'
    PG::ConnectionBad: invalid connection option "fallback_application_name"
    
            from (irb):1:in `initialize'
            from (irb):1:in `new'
            from (irb):1
            from /home/lars/.rvm/rubies/ruby-2.1.0/bin/irb:11:in `<main>'
    

    If PG.library_version isn't defined, the library at build time must be < 9.1. But your library has conn#escape_literal defined at build time, which was introduced in 9.0, so it seems that you build pg.gem against a 9.0 version of libpq.so. Since fallback_application_name isn't a valid option however, your libpq.so used at runtime must be < 9.0.

    It is always best to use the same library versions at build time, run time and as possible also on the server. Different build time and run time versions also don't work reasonable with psql and co.

  5. Log in to comment