1. Michael Granger
  2. ruby-pg
  3. Issues


Issue #182 invalid

pg Gem error under ruby 2.1.0 in Rails-4.1

Anonymous created an issue

It appears that rails pg gem is not compatible with ruby-2.1.0. This is the error I get when starting local server and loading home page with ruby version set to 2.1.0 in my rvm .ruby-version file (see below). Please not the error goes away if I switch to 2.0.0 ruby.

[dmoore (master)]$ rails s
=> Booting WEBrick
=> Rails 4.1.0.rc2 application starting in development on
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces ( Consider using (--binding option)
=> Ctrl-C to shutdown server
[2014-03-26 10:23:08] INFO  WEBrick 1.3.1
[2014-03-26 10:23:08] INFO  ruby 2.1.0 (2013-12-25) [x86_64-darwin12.0]
[2014-03-26 10:23:08] INFO  WEBrick::HTTPServer#start: pid=5350 port=3000

Started GET "/" for at 2014-03-26 10:23:09 -0700
dyld: lazy symbol binding failed: Symbol not found: _rb_funcall2
  Referenced from: /Users/dmoore/.rvm/gems/ruby-2.1.0@hotilinet-api/gems/pg-0.17.1/lib/pg_ext.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_funcall2
  Referenced from: /Users/dmoore/.rvm/gems/ruby-2.1.0@hotilinet-api/gems/pg-0.17.1/lib/pg_ext.bundle
  Expected in: flat namespace

Trace/BPT trap: 5

Comments (18)

  1. Michael Granger repo owner

    The 'pg' gem does work under 2.1.0p0:

    $ ruby -vS rspec -cfp spec
    ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
    /Users/ged/.rvm/gems/ruby-2.1.0@pg/gems/rspec-core-2.99.0.beta2/lib/rspec/core/configuration.rb:231: warning: method redefined; discarding old treat_symbols_as_metadata_keys_with_true_values=
    /Users/ged/.rvm/gems/ruby-2.1.0@pg/gems/rspec-core-2.99.0.beta2/lib/rspec/core/ruby_project.rb:27: warning: File.exists? is a deprecated name, use File.exist? instead
    Run options: exclude {:windows=>true}
    Setting up test database for PG::Connection
    Running initdb
    Creating the test DB
    ................................................*........................NOTICE:  there is no transaction in progress
    .NOTICE:  there is no transaction in progress
    .WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    .WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    .WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    .WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    ..WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    *......WARNING:  there is already a transaction in progress
    NOTICE:  there is no transaction in progress
    ....Tearing down test database
    No pidfile (#<Pathname:/Users/ged/source/ruby/pg/tmp_test_specs/data/postmaster.pid>)
    Setting up test database for PG_Result
    Creating the test DB
    ..................................Tearing down test database
      PG::Connection discards previous results (if any) before waiting on an #async_exec
        # Not yet implemented
        # ./spec/pg/connection_spec.rb:692
      PG::Connection multinationalization support rubyforge #22925: m17n support works around the unsupported JOHAB encoding by returning stuff in 'ASCII_8BIT'
        # figuring out how to create a string in the JOHAB encoding
        # ./spec/pg/connection_spec.rb:1034
    Finished in 30.98 seconds
    128 examples, 0 failures, 2 pending

    I'll update my 2.1.x to the latest and confirm that it works with that as well, but the problem in the poster's error appears to be something more serious, as rb_funcall2 is a function in the Ruby C API which is as far as I know still valid.

    If the anonymous poster reads this, I'd suggest rebuilding your gemset and ensuring that the Ruby you're running with is the same that you built the extension with.

  2. Lars Kanis

    PG is already compatible with Ruby 2.1 and Rails 4.1. This is tested for each and every commit to rails on travis-ci: https://travis-ci.org/rails/rails

    The binary gem for windows is compatible with Ruby 1.8.7 to 2.0.0, because RubyInstaller 2.1 is still not released. We will update the binary gem for 2.1 as soon as RubyInstaller 2.1 is available.

  3. cgs

    Delete your vendor/bundle folder and bundle install. You are using a version of the PG gem compiled with a different version of Ruby.

  4. Francesco Loreti

    dear Lars Kanis, after six months I tried again to use ruby 2.1.2 + rails 4.1 on windows but still can not use the library pg. I understand that rubyinstaller is not officially released but this package as documentation on the website, you freely compile with a rake and all libraries, except PG, they work. If you can't release officially library, can I compile it for me as I do for the ruby windows?

  5. pzagor2

    Ruby installer for 2.1.3 is out. But I'm not able to get pg running on it.

    C:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:10:in `require': cannot load such file -- 2.1/pg_ext (LoadError)
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:10:in `rescue in <top (required)>'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.17.1-x86-mingw32/lib/pg.rb:3:in `<top (required)>'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:76:in `require'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:72:in `each'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:72:in `block in require'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:61:in `each'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler/runtime.rb:61:in `require'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.3/lib/bundler.rb:133:in `require'
            from C:/Work/Dyno/dyno-production/config/application.rb:7:in `<top (required)>'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `require'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:79:in `block in server'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `tap'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:76:in `server'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
            from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
            from bin/rails:8:in `require'
            from bin/rails:8:in `<main>'

    ruby -v is ruby 2.1.3p242 (2014-09-19 revision 47630) [i386-mingw32]

    gem list shows pg (0.17.1 x86-mingw32)

    What could be the problem?

  6. Lars Kanis

    The current windows binary gem is not compatible with Ruby-2.1. This will be solved in the next ruby-pg release.

    You can however install ruby-pg from source. Install the DevKit and PostgreSQL into a directory without spaces. Add PostgreSQL's bin directory to your PATH environment variable and install ruby-pg with something like: gem inst pg --platform ruby

  7. pzagor2

    Tnx for your help.

    I tried install it with the command you provided but I'm getting this error.

    C:\Users\Primoz\Downloads\devkit32>gem inst pg --platform ruby -- --with-pg-dir=c:\PostgreSQL32\9.3\
    Temporarily enhancing PATH to include DevKit...
    Building native extensions with: '--with-pg-dir=c:\PostgreSQL32\9.3\'
    This could take a while...
    ERROR:  Error installing pg:
            ERROR: Failed to build gem native extension.
        C:/Ruby21/bin/ruby.exe extconf.rb --with-pg-dir=c:\PostgreSQL32\9.3\
    checking for pg_config... yes
    Using config values from C:\PostgreSQL\9.3\bin/pg_config.exe
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for pg_config_manual.h... yes
    checking for PQconnectdb() in -lpq... yes
    checking for PQconnectionUsedPassword()... yes
    checking for PQisthreadsafe()... yes
    checking for PQprepare()... yes
    checking for PQexecParams()... yes
    checking for PQescapeString()... yes
    checking for PQescapeStringConn()... yes
    checking for PQescapeLiteral()... yes
    checking for PQescapeIdentifier()... yes
    checking for PQgetCancel()... yes
    checking for lo_create()... yes
    checking for pg_encoding_to_char()... yes
    checking for pg_char_to_encoding()... yes
    checking for PQsetClientEncoding()... yes
    checking for PQlibVersion()... yes
    checking for PQping()... yes
    checking for PQsetSingleRowMode()... yes
    checking for rb_encdb_alias()... yes
    checking for rb_enc_alias()... yes
    checking for rb_thread_call_without_gvl()... yes
    checking for rb_thread_call_with_gvl()... yes
    checking for rb_thread_fd_select()... yes
    checking for rb_w32_wrap_io_handle()... yes
    checking for PGRES_COPY_BOTH in libpq-fe.h... yes
    checking for PGRES_SINGLE_TUPLE in libpq-fe.h... yes
    checking for PG_DIAG_TABLE_NAME in libpq-fe.h... yes
    checking for struct pgNotify.extra in libpq-fe.h... yes
    checking for unistd.h... yes
    checking for ruby/st.h... yes
    creating extconf.h
    creating Makefile
    make "DESTDIR=" clean
    make "DESTDIR="
    generating pg_ext-i386-mingw32.def
    compiling gvl_wrappers.c
    In file included from gvl_wrappers.c:6:0:
    pg.h:101:1: warning: 'dllexport' attribute ignored [-Wattributes]
    compiling pg.c
    In file included from pg.c:48:0:
    pg.h:101:1: warning: 'dllexport' attribute ignored [-Wattributes]
    compiling pg_connection.c
    In file included from pg_connection.c:7:0:
    pg.h:101:1: warning: 'dllexport' attribute ignored [-Wattributes]
    compiling pg_errors.c
    In file included from pg_errors.c:6:0:
    pg.h:101:1: warning: 'dllexport' attribute ignored [-Wattributes]
    compiling pg_result.c
    In file included from pg_result.c:7:0:
    pg.h:101:1: warning: 'dllexport' attribute ignored [-Wattributes]
    linking shared-object pg_ext.so
    c:/users/primoz/downloads/devkit32/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lpq
    collect2.exe: error: ld returned 1 exit status
    make: *** [pg_ext.so] Error 1
    make failed, exit code 2
    Gem files will remain installed in C:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.17.1 for inspection.
    Results logged to C:/Ruby21/lib/ruby/gems/2.1.0/extensions/x86-mingw32/2.1.0/pg-0.17.1/gem_make.out

    I successfully installed json with DevKit so that is working (gem install json --platform=ruby).

    Any suggestions?

  8. Michael McDonald

    I just tried it and it installed but when I run Rails on Ruby 2.1 I get:

    E:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:248:in `require': 127: The specified procedure could not be found.   -
     E:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.18.0.pre20141017160319-x86-mingw32/lib/2.1/pg_ext.so (LoadError)                                                       
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:248:in `block in require'                                
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:233:in `load_dependency'                                 
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:248:in `require'                                         
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.18.0.pre20141017160319-x86-mingw32/lib/pg.rb:14:in `rescue in <top (required)>'                            
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/pg-0.18.0.pre20141017160319-x86-mingw32/lib/pg.rb:3:in `<top (required)>'                                       
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require'                                                            
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require'                                        
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `each'                                                               
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:72:in `block in require'                                                   
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `each'                                                               
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:61:in `require'                                                            
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler.rb:133:in `require'                                                                   
            from C:/Workspace/api.goodcity/config/application.rb:14:in `<top (required)>'                                                                           
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:79:in `require'                                             
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:79:in `block in server'                                     
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:76:in `tap'                                                 
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:76:in `server'                                              
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands/commands_tasks.rb:40:in `run_command!'                                        
            from E:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.1.6/lib/rails/commands.rb:17:in `<top (required)>'                                                   
            from bin/rails:8:in `require'                                                                                                                           
            from bin/rails:8:in `<main>'                                                                                                                            

    I get this with pg 0.18.0.pre on Ruby 2.0 as well, but pg 0.17.1 on Ruby 2.0 works.

  9. Michael McDonald

    Thanks, changing the load order worked. I just typed libpq.dll in dos and it tried to load the one under C:\Program Files (x86)\IIS Express\PHP\v5.4. My ruby version is ruby 2.1.3p242 (2014-09-19 revision 47630) [i386-mingw32].

  10. Adam Messinger

    I had these problems with the RailsInstaller package for Ruby 2.1.5, even after upgrading to PG 0.18.1. It was fixed by removing RailsInstaller and using their Ruby 2.0.0 package instead.

  11. Log in to comment