Question

I'm trying to get my rails app to Heroku, but I've ran into an problem while trying to install pg gem. I was told to replace the line "gem 'sqlite3'" in my Gemfile with the following:

group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
  gem 'rails_stdout_logging' 
end

and then execute bundle install. I get this error message:

...
Using coffee-rails (3.2.2) 
Using jquery-rails (3.0.4) 
Installing pg (0.17.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
    /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb 
checking for pg_config... yes
Using config values from /usr/bin/pg_config
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()... no
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()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
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
compiling gvl_wrappers.c
compiling pg.c
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/pg-0.17.1/ext/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

So, I try to execute gem install pg -v '0.17.1'. I get this error message:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
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()... no
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()... no
checking for PGRES_COPY_BOTH in libpq-fe.h... no
checking for PGRES_SINGLE_TUPLE in libpq-fe.h... no
checking for PG_DIAG_TABLE_NAME in libpq-fe.h... no
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
compiling gvl_wrappers.c
compiling pg.c
pg.c: In function ‘Init_pg_ext’:
pg.c:375: error: ‘PQPING_OK’ undeclared (first use in this function)
pg.c:375: error: (Each undeclared identifier is reported only once
pg.c:375: error: for each function it appears in.)
pg.c:377: error: ‘PQPING_REJECT’ undeclared (first use in this function)
pg.c:379: error: ‘PQPING_NO_RESPONSE’ undeclared (first use in this function)
pg.c:381: error: ‘PQPING_NO_ATTEMPT’ undeclared (first use in this function)
make: *** [pg.o] Error 1

I've read these posts and tried the solutions given there but none of them works:

I'm using Mac OS X 10.8.5, if you're wondering

Was it helpful?

Solution 2

I guess you don't have postgres installed in your system. You could either install postgresql via homebrew/macports or disable the installation of production gems with:

bundle install --without production

OTHER TIPS

run following command on console...

sudo apt-get install libpq-dev


gem install pg

happy coding...

The problem is with the PostgreSQL-client missing on your system.
Run these commands on terminal

sudo apt-get install postgresql-client libpq5 libpq-dev

Now add this gem to your Gemfile

gem 'pg'

and run this

bundle install
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top