Giter VIP home page Giter VIP logo

ruby-pg's Introduction

pg

Join the chat at https://gitter.im/ged/ruby-pg

Description

Pg is the Ruby interface to the PostgreSQL RDBMS. It works with PostgreSQL 9.3 and later.

A small example usage:

  #!/usr/bin/env ruby

  require 'pg'

  # Output a table of current connections to the DB
  conn = PG.connect( dbname: 'sales' )
  conn.exec( "SELECT * FROM pg_stat_activity" ) do |result|
    puts "     PID | User             | Query"
    result.each do |row|
      puts " %7d | %-16s | %s " %
        row.values_at('pid', 'usename', 'query')
    end
  end

Build Status

Build Status Github Actions Binary gems Build Status Appveyor

Requirements

  • Ruby 2.5 or newer
  • PostgreSQL 9.3.x or later (with headers, -dev packages, etc).

It usually works with earlier versions of Ruby/PostgreSQL as well, but those are not regularly tested.

Versioning

We tag and release gems according to the Semantic Versioning principle.

As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.

For example:

  spec.add_dependency 'pg', '~> 1.0'

How To Install

Install via RubyGems:

gem install pg

You may need to specify the path to the 'pg_config' program installed with Postgres:

gem install pg -- --with-pg-config=<path to pg_config>

If you're installing via Bundler, you can provide compile hints like so:

bundle config build.pg --with-pg-config=<path to pg_config>

See README-OS_X.rdoc for more information about installing under MacOS X, and README-Windows.rdoc for Windows build/installation instructions.

There's also a Google+ group and a mailing list if you get stuck, or just want to chat about something.

If you want to install as a signed gem, the public certs of the gem signers can be found in the certs directory of the repository.

Type Casts

Pg can optionally type cast result values and query parameters in Ruby or native C code. This can speed up data transfers to and from the database, because String allocations are reduced and conversions in (slower) Ruby code can be omitted.

Very basic type casting can be enabled by:

    conn.type_map_for_results = PG::BasicTypeMapForResults.new conn
    # ... this works for result value mapping:
    conn.exec("select 1, now(), '{2,3}'::int[]").values
        # => [[1, 2014-09-21 20:51:56 +0200, [2, 3]]]

    conn.type_map_for_queries = PG::BasicTypeMapForQueries.new conn
    # ... and this for param value mapping:
    conn.exec_params("SELECT $1::text, $2::text, $3::text", [1, 1.23, [2,3]]).values
        # => [["1", "1.2300000000000000E+00", "{2,3}"]]

But Pg's type casting is highly customizable. That's why it's divided into 2 layers:

Encoders / Decoders (ext/pg_*coder.c, lib/pg/*coder.rb)

This is the lower layer, containing encoding classes that convert Ruby objects for transmission to the DBMS and decoding classes to convert received data back to Ruby objects. The classes are namespaced according to their format and direction in PG::TextEncoder, PG::TextDecoder, PG::BinaryEncoder and PG::BinaryDecoder.

It is possible to assign a type OID, format code (text or binary) and optionally a name to an encoder or decoder object. It's also possible to build composite types by assigning an element encoder/decoder. PG::Coder objects can be used to set up a PG::TypeMap or alternatively to convert single values to/from their string representation.

The following PostgreSQL column types are supported by ruby-pg (TE = Text Encoder, TD = Text Decoder, BE = Binary Encoder, BD = Binary Decoder):

  • Integer: TE, TD, BD πŸ’‘ No links? Switch to here πŸ’‘
    • BE: Int2, Int4, Int8
  • Float: TE, TD, BD
    • BE: Float4, Float8
  • Numeric: TE, TD
  • Boolean: TE, TD, BE, BD
  • String: TE, TD, BE, BD
  • Bytea: TE, TD, BE, BD
  • Base64: TE, TD, BE, BD
  • Timestamp:
    • TE: local, UTC, with-TZ
    • TD: local, UTC, UTC-to-local
    • BE: local, UTC
    • BD: local, UTC, UTC-to-local
  • Date: TE, TD, BE, BD
  • JSON and JSONB: TE, TD
  • Inet: TE, TD
  • Array: TE, TD
  • Composite Type (also called "Row" or "Record"): TE, TD

The following text and binary formats can also be encoded although they are not used as column type:

  • COPY input and output data: TE, TD, BE, BD
  • Literal for insertion into SQL string: TE
  • SQL-Identifier: TE, TD

PG::TypeMap and derivations (ext/pg_type_map*.c, lib/pg/type_map*.rb)

A TypeMap defines which value will be converted by which encoder/decoder. There are different type map strategies, implemented by several derivations of this class. They can be chosen and configured according to the particular needs for type casting. The default type map is PG::TypeMapAllStrings.

A type map can be assigned per connection or per query respectively per result set. Type maps can also be used for COPY in and out data streaming. See PG::Connection#copy_data .

The following base type maps are available:

  • PG::TypeMapAllStrings - encodes and decodes all values to and from strings (default)
  • PG::TypeMapByClass - selects encoder based on the class of the value to be sent
  • PG::TypeMapByColumn - selects encoder and decoder by column order
  • PG::TypeMapByOid - selects decoder by PostgreSQL type OID
  • PG::TypeMapInRuby - define a custom type map in ruby

The following type maps are prefilled with type mappings from the PG::BasicTypeRegistry :

  • PG::BasicTypeMapForResults - a PG::TypeMapByOid prefilled with decoders for common PostgreSQL column types
  • PG::BasicTypeMapBasedOnResult - a PG::TypeMapByOid prefilled with encoders for common PostgreSQL column types
  • PG::BasicTypeMapForQueries - a PG::TypeMapByClass prefilled with encoders for common Ruby value classes

Thread support

PG is thread safe in such a way that different threads can use different PG::Connection objects concurrently. However it is not safe to access any Pg objects simultaneously from more than one thread. So make sure to open a new database server connection for every new thread or use a wrapper library like ActiveRecord that manages connections in a thread safe way.

If messages like the following are printed to stderr, you're probably using one connection from several threads:

message type 0x31 arrived from server while idle
message type 0x32 arrived from server while idle
message type 0x54 arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle

Fiber IO scheduler support

Pg is fully compatible with Fiber.scheduler introduced in Ruby-3.0 since pg-1.3.0. On Windows support for Fiber.scheduler is available on Ruby-3.1 or newer. All possibly blocking IO operations are routed through the Fiber.scheduler if one is registered for the running thread. That is why pg internally uses the asynchronous libpq interface even for synchronous/blocking method calls. It also uses Ruby's DNS resolution instead of libpq's builtin functions.

Internally Pg always uses the nonblocking connection mode of libpq. It then behaves like running in blocking mode but ensures, that all blocking IO is handled in Ruby through a possibly registered Fiber.scheduler. When PG::Connection.setnonblocking(true) is called then the nonblocking state stays enabled, but the additional handling of blocking states is disabled, so that the calling program has to handle blocking states on its own.

An exception to this rule are the methods for large objects like PG::Connection#lo_create and authentication methods using external libraries (like GSSAPI authentication). They are not compatible with Fiber.scheduler, so that blocking states are not passed to the registered IO scheduler. That means the operation will work properly, but IO waiting states can not be used to switch to another Fiber doing IO.

Ractor support

Pg is fully compatible with Ractor introduced in Ruby-3.0 since pg-1.5.0. All type en/decoders and type maps are shareable between ractors if they are made frozen by Ractor.make_shareable. Also frozen PG::Result and PG::Tuple objects can be shared. All frozen objects (except PG::Connection) can still be used to do communication with the PostgreSQL server or to read retrieved data.

PG::Connection is not shareable and must be created within each Ractor to establish a dedicated connection.

Contributing

To report bugs, suggest features, or check out the source with Git, check out the project page.

After checking out the source, install all dependencies:

$ bundle install

Cleanup extension files, packaging files, test databases. Run this to change between PostgreSQL versions:

$ rake clean

Compile extension:

$ rake compile

Run tests/specs on the PostgreSQL version that pg_config --bindir points to:

$ rake test

Or run a specific test per file and line number on a specific PostgreSQL version:

$ PATH=/usr/lib/postgresql/14/bin:$PATH rspec -Ilib -fd spec/pg/connection_spec.rb:455

Generate the API documentation:

$ rake docs

Make sure, that all bugs and new features are verified by tests.

The current maintainers are Michael Granger [email protected] and Lars Kanis [email protected].

Copying

Copyright (c) 1997-2022 by the authors.

You may redistribute this software under the same terms as Ruby itself; see https://www.ruby-lang.org/en/about/license.txt or the BSDL file in the source for details.

Portions of the code are from the PostgreSQL project, and are distributed under the terms of the PostgreSQL license, included in the file POSTGRES.

Portions copyright LAIKA, Inc.

Acknowledgments

See Contributors.rdoc for the many additional fine people that have contributed to this library over the years.

We are thankful to the people at the ruby-list and ruby-dev mailing lists. And to the people who developed PostgreSQL.

ruby-pg's People

Contributors

aardvark179 avatar akito19 avatar alyssais avatar amarshall avatar bdunne avatar cbandy avatar ccutrer avatar cfis avatar ejoubaud avatar eregon avatar fatkodima avatar ged avatar gemmaro avatar ghazel avatar ioquatix avatar jackc avatar jackorp avatar jasoncodes avatar jcalvert avatar jeff-davis-aster avatar jeremyevans avatar junaruga avatar kamipo avatar kianmeng avatar larskanis avatar mahlonsmith avatar remy-cassia-tech avatar stevewoodcock avatar tenderlove avatar wata727 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-pg's Issues

pg requires Ruby 1.8.7, incompatable with Google SketchUp

Original report by John Poole (Bitbucket: jlpoole, GitHub: jlpoole).


I'm experimenting with getting PostgreSQL functionality working from within Google SketchUp. Google SketchUp's current version of Ruby is:

Version: 1.8.6 build: 287

I've installed Ruby 1.8.6 build 398 and have been trying to install DBI and DBD-Pg. DBI installed without a problem.

C:\Ruby>gem install pg
ERROR:  Error installing pg:
        pg requires Ruby version >= 1.8.7.

C:\Ruby>

I downloaded the tip and found in the rakefile:

gem.required_ruby_version = '>=1.8.7'

I'm new to Ruby and Gems and wonder 1) why the limitation on 1.8.7, and 2) if there is no reason for the limitation, can I build a version of pg that will accommodate 1.8.6? There may be a large SketchUp community that might utilize pg that runs within Ruby 1.8.6, so I want to make sure what I do can be shared and deployed without conflicting with this project's current product.

What are anybody's recommendations on how best to proceed?

Mingw Compilation Broken

Original report by Anonymous.


Version 0.11 no longer compiles on Windows using mingw32 + mysy. Trace back is below. The issue is that the linking line is not including the correct libraries. It is possible to work around by doing this:

export CROSS_COMPILING=true

$ gem update pg --platform=ruby

Fix is easy, in the extconf.rb file check for CROSS_COMPILING or mingw or mswin.

Thanks,

Charlie


$ gem update pg --platform=ruby
Updating installed gems
Updating pg
Fetching: pg-0.11.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

        c:/MinGW/local/ruby/bin/ruby.exe extconf.rb
checking for pg_config... yes
Using config values from c:\MinGW\local\bin/pg_config.exe
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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 PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for PQsetClientEncoding()... yes
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
creating extconf.h
creating Makefile

make
gcc -I. -I. -Ic:/MinGW/local/ruby/lib/ruby/1.8/i386-mingw32 -I. -DRUBY_EXTCONF_H=\"extconf.h\"    -Ic:/MinGW/local/include -g -O2    -c compat.c
gcc -I. -I. -Ic:/MinGW/local/ruby/lib/ruby/1.8/i386-mingw32 -I. -DRUBY_EXTCONF_H=\"extconf.h\"    -Ic:/MinGW/local/include -g -O2    -c pg.c
gcc -shared -s -o pg_ext.so compat.o pg.o -L. -Lc:/MinGW/local/ruby/lib -L.  -Lc:/MinGW/local/lib -Wl,--enable-auto-image-base,--enable-auto-import,--export-all   -lmsvcrt-ruby18 -lpq  -lshell32 -lwsock32
pg.o: In function `create_crt_fd':
c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/pg.c:2031: undefined reference to `WSADuplicateSocketA@12'
c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/pg.c:2032: undefined reference to `WSASocketA@24'
collect2: ld returned 1 exit status
make: *** [pg_ext.so] Error 1


Gem files will remain installed in c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0 for inspection.
Results logged to c:/MinGW/local/ruby/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/gem_make.out
Nothing to update

Large object sample script is out of date

Original report by fredericp (Bitbucket: fredericp, GitHub: fredericp).


The documentation says:
lo_create([mode]): Return the PGlarge instance on success. On failure, it raises PGError exception.

At the moment, the function returns a FIXNUM, not an instance of PGlarge. Looking at the source in ext/pg.c, PGlarge is nowhere to be found. Even the example at sample/losample.rb doesn't work:
(losample.rb:10: undefined method `oid' for 2677586:Fixnum (NoMethodError).

At the moment the only way to import/export large objects to/from the database is to use lo_import/lo_export. This generates much IO-load and slows an otherwise simple script that cuts large images into small pieces extremely down.

ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]

Yours,
Frederic Pollmann

Licensing

Original report by VΓ­t Ondruch (Bitbucket: vo_x, ).


Hello, Your README states that part of the project is BSD licensed, but it is actually PostgreSQL license [1] according to the BSD file content. Could you please clarify the licensing?

[1] http://www.opensource.org/licenses/postgresql

Also (via #92):

The README file for ruby-pg says: You may redistribute this software under the terms of the Ruby license, included in the file "LICENSE". The Ruby license also allows distribution under the terms of the GPL, included in the file "GPL".

This is no longer the case, as of Ruby 1.9.3, which is dual-licensed with the 2-clause Simplified BSD License rather than the GPL. The README and LICENSE files should be altered to reflect this change.

pointer being freed was not allocated on osx lion

Original report by kelly felkins (Bitbucket: kellyfelkins, GitHub: kellyfelkins).


When I run the specs of a rails project I get:

#!shell

ruby(1870) malloc: *** error for object 0x11: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

I attempted to narrow this down by running with valgrind (which is unsupported on lion). Be aware, I've never run valgrind before. I got:

#!shell

<snip>
--1486-- /Users/kelly/.rvm/gems/ruby-1.8.7-p352@jmn/gems/pg-0.11.0/lib/pg_ext.bundle:
--1486-- dSYM directory is missing; consider using --dsymutil=yes
vex amd64->IR: unhandled instruction bytes: 0xC8 0x88 0x0 0x0 0x66 0xF
==1486== valgrind: Unrecognised instruction at address 0x19cef9.
==1486== Your program just tried to execute an instruction that Valgrind
==1486== did not recognise.  There are two possible reasons for this.
==1486== 1. Your program has a bug and erroneously jumped to a non-code
==1486==    location.  If you are running Memcheck and you just saw a
==1486==    warning about a bad jump, it's probably your program's fault.
==1486== 2. The instruction is legitimate but Valgrind doesn't handle it,
==1486==    i.e. it's Valgrind's fault.  If you think this is the case or
==1486==    you are not sure, please let us know and we'll try to fix it.
==1486== Either way, Valgrind will now raise a SIGILL signal which will
==1486== probably kill your program.
==1486== 
==1486== Process terminating with default action of signal 4 (SIGILL)
==1486==  Illegal opcode at address 0x19CEF9
==1486==    at 0x19CEF9: objc_msgSend (in /usr/lib/libobjc.A.dylib)
==1486==    by 0x3C2CDA5: _NSInitializePlatform (in /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation)
==1486==    by 0x19C7B6: call_load_methods (in /usr/lib/libobjc.A.dylib)
==1486==    by 0x19C36A: load_images (in /usr/lib/libobjc.A.dylib)
<snip>

Full gist at:
https://raw.github.com/gist/1288411/40d9a880ec9a5d4abf4cba29da11b8c5edc713e6/gistfile1.txt

Add support for the libpq event system

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


libpq has an [[http://www.postgresql.org/docs/9.0/static/libpq-events.html | event system ]] that makes it possible "to notify registered event handlers about interesting libpq events, such as the creation or destruction of PGconn and PGresult objects". This might be useful for logging, connection pool management, etc.

trying to install pg gem on snow leopard

Original report by Anonymous.


Hi

I am trying to install the pg gem on my MacBook Air, Snow Leopard 10.6.5 but when the driver is being loaded I get the following error:

/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle, 9): no suitable image found.  Did find: (LoadError)
	/Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle: mach-o, but wrong architecture - /Library/Ruby/Gems/1.8/gems/pg-0.10.0/lib/pg_ext.bundle
	from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'

The driver compiles fine on my system. MacBook Airs 2010 still seem to be i386 not x86_64.

Any feedback is welcome.

Best
Zeno

bytea escape type 'hex' not being recognized

Original report by Don Park (Bitbucket: donpdonp, GitHub: donpdonp).


#!ruby
puts conn.exec("select * from open_id_associations limit 1")[0]["secret"]
\x65958bdb611a6bce10efbd6ddddd8c1c82e8ff36

Then from psql:

select secret from open_id_associations limit 1;
                   secret                   
--------------------------------------------
 \x65958bdb611a6bce10efbd6ddddd8c1c82e8ff36
(1 row)

The output of psql I would expect to show the escaped version, but I expect the ruby call to return a binary string. Is that a correct assumption?

rake db:create with PG (Win 7 x64 / PostgreSQL 9.0)

Original report by Blackpyb (Bitbucket: Blackpyb, ).


When I tried to "rake db:create" it got an error below:

//C:\projetos\florarails>rake db:create
(in C:/projetos/florarails)
PGError: ERROR:  permissΟ€o negada ao criar banco de dados
: CREATE DATABASE "florarails_test" ENCODING = 'utf8'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connect
ion_adapters/abstract_adapter.rb:202:in `rescue in log'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connect
ion_adapters/abstract_adapter.rb:194:in `log'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connect
ion_adapters/postgresql_adapter.rb:496:in `execute'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/connect
ion_adapters/postgresql_adapter.rb:575:in `create_database'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/railtie
s/databases.rake:92:in `rescue in create_database'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/railtie
s/databases.rake:39:in `create_database'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.0/lib/active_record/railtie
s/databases.rake:33:in `block (2 levels) in <top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:634:in `call'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:634:in `block in execute'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:629:in `each'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:629:in `execute'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:595:in `block in invoke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:588:in `invoke_with_call_chain'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:581:in `invoke'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2041:in `invoke_task'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `each'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1992:in `run'
c:/Ruby192/bin/rake:31:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"UTF-8", "dat
abase"=>"florarails_test", "pool"=>5, "username"=>"exercicio_livro", "password"=
>"rails"}//

And this occurs to other 2 databases (dev and production).

Catch up to libpq features from 9.0

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


There are a few new features in the 9.0 libpq that should be reflected in the API:

  • PGconn#escape_literal (PQescapeLiteral )
  • PGconn#escape_identifier (PQescapeIdentifier)
  • Support for keepalive* connection parameters (probably just need specs for them).

gem install pg fails to compile for OSX 10.6.6

Original report by Anonymous.


pg gem version 0.10.1 doesn't install.
pg gem version 0.10.0 does install.

===== Details:
=====sudo gem install
gives

#!python

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /opt/local/var/macports/software/postgresql84/8.4.4_1/opt/local/lib/postgresql84/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Mac Snow Leopard Install Problem (MacPorts, PostgreSQL 8.4, & RVM)

Original report by chaostheory (Bitbucket: chaostheory, GitHub: chaostheory).


Stats

OS: 10.6.4
Ruby: 1.9.2 on RVM
PostgreSQL: 8.4 (base, server, & libpqxx 3.0.2) using MacPorts

console

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

/Users/hello/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for pg_config... no
MacOS X build: fixing architecture flags:
  using the value in ARCHFLAGS environment variable ("-arch x86_64").
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. 

log

"gcc -o conftest -I/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/i386-darwin10.4.0 -I/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/backward -I/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE    -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe -arch x86_64 conftest.c  -L. -L/Users/hello/.rvm/rubies/ruby-1.9.2-p0/lib -L.  -arch x86_64     -lruby.1.9.1-static  -lpthread -ldl -lobjc "
In file included from /Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby.h:32,
                 from conftest.c:1:
/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/ruby.h:108: error: size of array β€˜ruby_check_sizeof_long’ is negative
/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/ruby.h:112: error: size of array β€˜ruby_check_sizeof_voidp’ is negative
In file included from /Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/intern.h:29,
                 from /Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from /Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby.h:32,
                 from conftest.c:1:
/Users/hello/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby/st.h:69: error: size of array β€˜st_check_for_sizeof_st_index_t’ is negative
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main() {return 0;}
/* end */

Create a Manual

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


I've been considering starting a manual for the 'pg' library, but haven't had the time or motivation to do so up to now.

Ticket <<issue 78>>, while a poor example of issue-reporting, had a kernel of truth within the rude hyperbole: there really isn't any good resource (that I know of) on how to start using the 'pg' library, especially the more-advanced features. I usually just refer to the C API docs, which are excellent, because 'pg' maps to the libpq API pretty much one-to-one. But that's not intuitive, and translating the C into idiomatic Ruby isn't really straighforward.

After converting the build system to use Hoe, I'm going to add the 'hoe-manualgen' plugin, and start working on a cookbook-style manual like [[http://deveiate.org/code/Treequel/|the one I did for Treequel]].

I'll start with an outline, split it into pages, and once I have the initial section done, perhaps solicit people's help in finishing up the rest.

Hang in PGconn#block while waiting for PGconn#async_exec

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


[via harryv in the #ruby-lang irc channel]

Sometimes a call to PGconn#async_exec will hang for a long period of time, and eventually die with:

select(4, [3], NULL, NULL, NULL) = -1 EBADF (Bad file descriptor)

This might be related to <<issue 66>>, and might also be the cause of [[https://groups.google.com/d/topic/sequel-talk/hGyN1Ix-TmE/discussion|an issue]] reported on the Sequel-talk mailing list.

Test helper doesn't correctly drop the database (?)

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


[Via email]

you need to quote the drop database command

Γ„nderung:        209:89348c8bb6d1
Datum:           Mon Dec 06 12:00:11 2010 -0800



#!diff
/media/87ce4eeb-6589-4edc-a13a-ac286d780634/experiments/diaspora/ruby-pg$ hg diff
diff -r 89348c8bb6d1 spec/lib/helpers.rb
--- a/spec/lib/helpers.rb    Mon Dec 06 12:00:11 2010 -0800
+++ b/spec/lib/helpers.rb    Tue Dec 28 17:28:25 2010 +0100
@@ -209,7 +209,7 @@
             sleep 2
 
             $stderr.puts "Creating the test DB"
-            log_and_run @logfile, 'psql', '-e', '-c', 'DROP DATABASE IF EXISTS test', 'postgres'
+            log_and_run @logfile, 'psql', '-e', '-c', "\'DROP DATABASE IF EXISTS test\'", 'postgres'
             log_and_run @logfile, 'createdb', '-e', 'test'
 
         rescue => err



SourcePackage: postgresql-8.4
Package: postgresql (not installed)
Tags:  ubuntu-unr
ProblemType: Bug
ProcEnviron:
  SHELL=/bin/bash
  LANG=de_DE.UTF-8
Uname: Linux 2.6.31-22-generic i686
ProcVersionSignature: Ubuntu 2.6.31-22.63-generic
InstallationMedia: Ubuntu-Netbook-Remix 9.10 "Karmic Koala" - Release i386 (20091028.4)
Architecture: i386
Date: Tue Dec 28 17:33:59 2010

--
James Michael DuPont
Member of Free Libre Open Source Software Kosova and Albania flossk.org flossal.org

pg-0.10.0 fails to compile on OS X Snow Leopard

Original report by Markus Wein (Bitbucket: nuclearsquid, ).


Using the following command to install pg:

gem install pg -- --ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby --with-pg-config=`which pg_config` --with-pgsql-lib=`pg_config --libdir` --with-pgsql-include=`pg_config --includedir`

I get the following output:

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
	ERROR: Failed to build gem native extension.

/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby extconf.rb --ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby --with-pg-config=/usr/local/pgsql/bin/pg_config --with-pgsql-lib=/usr/local/pgsql-9.0/lib --with-pgsql-include=/usr/local/pgsql-9.0/include
checking for /usr/local/pgsql/bin/pg_config... yes
Ruby cflags: "-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64 -fno-common -pipe"
MacOS X build: fixing architecture flags:
  finding flags common to both Ruby and PostgreSQL...
  testing for architecture: "i386"
  testing for architecture: "x86_64"
  common arch flags: -arch x86_64
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby
	--with-pg
	--without-pg
	--with-pg-config
	--with-pg-dir
	--without-pg-dir
	--with-pg-include
	--without-pg-include=${pg-dir}/include
	--with-pg-lib
	--without-pg-lib=${pg-dir}/lib
	--with-pqlib
	--without-pqlib
	--with-libpqlib
	--without-libpqlib
	--with-ms/libpqlib
	--without-ms/libpqlib


Gem files will remain installed in /Users/cypher/.rvm/gems/ruby-1.9.2-head/gems/pg-0.10.0 for inspection.
Results logged to /Users/cypher/.rvm/gems/ruby-1.9.2-head/gems/pg-0.10.0/ext/gem_make.out

If you'll take a look at the attached mkmf.log-gem, it complains about too few arguments to PQconnectdb, not that it doesn't exist.

I've installed PostgreSQL 9.0 using the package provided here: http://www.kyngchaos.com/software/postgres

I also tried building using the latest version from BitBucket (89348c8bb6d1) to try the new minimal extconf.rb, and got the following:

$ rake compile -- --with-pg-config=`which pg_config` --with-pgsql-lib=`pg_config --libdir` --with-pgsql-include=`pg_config --includedir`
(in /Users/cypher/Projects/ruby-pg)
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
rake-compiler must be configured first to enable cross-compilation
cd tmp/x86_64-darwin10.4.0/pg_ext/1.9.2
/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby -I. ../../../../ext/extconf.rb --with-pg-config=/usr/local/pgsql/bin/pg_config --with-pgsql-lib=/usr/local/pgsql-9.0/lib --with-pgsql-include=/usr/local/pgsql-9.0/include
Using config values from /usr/local/pgsql/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** ../../../../ext/extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=../../../../ext
	--curdir
	--ruby=/Users/cypher/.rvm/rubies/ruby-1.9.2-head/bin/ruby
	--with-pg
	--without-pg
	--with-pg-dir
	--without-pg-dir
	--with-pg-include
	--without-pg-include=${pg-dir}/include
	--with-pg-lib
	--without-pg-lib=${pg-dir}/lib
	--with-pg-config
	--with-pqlib
	--without-pqlib
	--with-libpqlib
	--without-libpqlib
	--with-ms/libpqlib
	--without-ms/libpqlib
rake aborted!
Command failed with status (1): [/Users/cypher/.rvm/rubies/ruby-1.9.2-head/...]

(See full trace by running task with --trace)

mkmf.log-tip is attached.

Ruby License Terms

Original report by Chad Perrin (Bitbucket: apotheon, GitHub: apotheon).


The README file for ruby-pg says: You may redistribute this software under the terms of the Ruby license, included in the file "LICENSE". The Ruby license also allows distribution under the terms of the GPL, included in the file "GPL".

This is no longer the case, as of Ruby 1.9.3, which is dual-licensed with the 2-clause Simplified BSD License rather than the GPL. The README and LICENSE files should be altered to reflect this change.

PGconn::connect segfaults with certain arguments

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


There's a problem with the way PGconn parses connection arguments, reported via 'omarqureshi' on the [[irc://irc.freenode.net/#ruby-lang|#ruby-lang IRC channel]].

He posted a backtrace in [[https://gist.github.com/ed348fd1757c22164a58|a gist on Github]]:

ruby-1.9.2-p180 :001 > require 'pg'
 => true
ruby-1.9.2-p180 :002 > PGconn.connect
(irb):2: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]

-- control frame ----------
c:0025 p:---- s:0087 b:0087 l:000086 d:000086 CFUNC :initialize
c:0024 p:---- s:0085 b:0085 l:000084 d:000084 CFUNC :new
c:0023 p:0015 s:0082 b:0082 l:002118 d:000081 EVAL (irb):2
c:0022 p:---- s:0080 b:0080 l:000079 d:000079 FINISH
c:0021 p:---- s:0078 b:0078 l:000077 d:000077 CFUNC :eval
c:0020 p:0028 s:0071 b:0071 l:000070 d:000070 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80
c:0019 p:0033 s:0064 b:0063 l:000062 d:000062 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/context.rb:254
c:0018 p:0031 s:0058 b:0058 l:0009f8 d:000057 BLOCK [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:159
c:0017 p:0042 s:0050 b:0050 l:000049 d:000049 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273
c:0016 p:0011 s:0045 b:0045 l:0009f8 d:000044 BLOCK [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156
c:0015 p:0144 s:0041 b:0041 l:000024 d:000040 BLOCK [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243
c:0014 p:---- s:0038 b:0038 l:000037 d:000037 FINISH
c:0013 p:---- s:0036 b:0036 l:000035 d:000035 CFUNC :loop
c:0012 p:0009 s:0033 b:0033 l:000024 d:000032 BLOCK [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229
c:0011 p:---- s:0031 b:0031 l:000030 d:000030 FINISH
c:0010 p:---- s:0029 b:0029 l:000028 d:000028 CFUNC :catch
c:0009 p:0023 s:0025 b:0025 l:000024 d:000024 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228
c:0008 p:0046 s:0022 b:0022 l:0009f8 d:0009f8 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155
c:0007 p:0011 s:0019 b:0019 l:000e28 d:000018 BLOCK [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70
c:0006 p:---- s:0017 b:0017 l:000016 d:000016 FINISH
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :catch
c:0004 p:0183 s:0011 b:0011 l:000e28 d:000e28 METHOD [..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69
c:0003 p:0142 s:0006 b:0006 l:0014e8 d:000f08 EVAL [..]ruby-1.9.2-p180/bin/irb:16
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0014e8 d:0014e8 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
[..]ruby-1.9.2-p180/bin/irb:16:in `<main>'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in `start'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in `catch'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70:in `block in start'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:159:in `block (2 levels) in eval_input'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/context.rb:254:in `evaluate'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in `evaluate'
[..]ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:80:in `eval'
(irb):2:in `irb_binding'
(irb):2:in `new'
(irb):2:in `initialize'

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

zsh: abort irb

Native extension fails to compile with Postgresql 9.0.5

Original report by Sven Schwyn (Bitbucket: svoop, GitHub: svoop).


I'm trying to install the pg gem on a Gentoo box with postgresql-9.0.5. Here's what make has to say:

Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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 PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for PQsetClientEncoding()... yes
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
creating extconf.h
creating Makefile

make
compiling compat.c
compiling pg.c
pg.c: In function β€˜pgconn_wait_for_notify’:
pg.c:2105:3: warning: β€˜rb_thread_select’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379)
pg.c: In function β€˜pgconn_block’:
pg.c:2589:3: warning: β€˜rb_thread_select’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379)
linking shared-object pg_ext.so
pg.o: In function `find_or_create_johab':
pg.c:(.text+0x4e): undefined reference to `rb_enc_alias'
pg.c:(.text+0x61): undefined reference to `rb_enc_alias'
collect2: ld returned 1 exit status
make: *** [pg_ext.so] Error 1

Any idea what could be the problem?

Thanks a bunch, -sven

Native compile on windows triggers load errors

Original report by Luis Lavena (Bitbucket: luislavena, GitHub: luislavena).


Hello,

I noticed version 0.10.0 lack Windows binaries, so I went ahead and use RubyInstaller + DevKit to install and compile:

gem install pg -- --with-pg-dir=X:

(X: was my subst drive from PostgreSQL 8.3)

Now, everything compiled fine, but when attempt to load the gem:

#!ruby

require 'rubygems'
require 'pg'

Received the following output:

LoadError: no such file to load -- 1.8/pg_ext
        from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/pg-0.10.0/lib/pg.rb:10
        from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
        from C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
        from (irb):2

I think the pg library should attempt to find the extension in the normal place before, as we do for sqlite3-ruby:

https://github.com/luislavena/sqlite3-ruby/blob/master/lib/sqlite3.rb#L1-7

Cheers.

Unable to load pg (require 'pg' failed)

Original report by eljumbo (Bitbucket: eljumbo, ).


Hi,

I work on :

Windows XP SP3

PostgreSQL 9.1

ruby 1.9.3p0 (2011-10-30) [i386-mingw32]

pg (0.11.0)

I have installed all the stuff without problems, but when I want to launch a script to test the database connection I expect this problem :

P:>ruby C:\myscript.rb
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require': cannot load such file -- 1.9/pg_ext (Loa dError) from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/pg-0.11.0/lib/pg.rb:10:in rescue in <top (required)>' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/pg-0.11.0/lib/pg.rb:3:in <top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in require' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in rescue in require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in require' from C:/myscript.rb:3:in

'

Also a dialog box appears telling me that the LIBPQ.DLL can't be found...

I can't found any solution to that ... Hope you can help me !

Romain G.

0.10.0 build failed on mac os

Original report by sl_bug (Bitbucket: sl_bug, ).


log:

ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

/Users/user/.rvm/rubies/ruby-head/bin/ruby extconf.rb
checking for pg_config... yes
Ruby cflags: " -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long  -fno-common -pipe"
MacOS X build: fixing architecture flags:
  finding flags common to both Ruby and PostgreSQL...

*** Your PostgreSQL installation doesn't seem to have an architecture in common with the running ruby interpreter (["ppc", "i386", "x86_64"] vs. [])
I'll continue anyway, but if it fails, try setting ARCHFLAGS.
  testing for architecture: "ppc"
  testing for architecture: "i386"
  testing for architecture: "x86_64"
checking for libpq-fe.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/Users/user/.rvm/rubies/ruby-head/bin/ruby
        --with-pg
        --without-pg
        --with-pg-config
        --without-pg-config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
/Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:367:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:480:in `try_cpp'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:944:in `block in find_header'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:764:in `block in checking_for'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:279:in `block (2 levels) in postpone'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:253:in `open'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:279:in `block in postpone'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:253:in `open'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:275:in `postpone'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:763:in `checking_for'
        from /Users/user/.rvm/rubies/ruby-head/lib/ruby/1.9.1/mkmf.rb:943:in `find_header'
        from extconf.rb:123:in `<main>'

everything was ok in 0.9.0 pg gem.

Statically build and link libpq in PG gem where applicable

Original report by pvh (Bitbucket: pvh, GitHub: pvh).


Getting binary libraries installed on platforms like Heroku is very difficult, particularly when there are multiple versions of Postgres out there to support. Instead of campaigning to get binaries installed it would be great if there were a way to build and statically link libpq into the pg gem directly.

Segfault when attempting any HTTP acces with pg gem installed

Original report by jeromewilson (Bitbucket: jeromewilson, GitHub: jeromewilson).


There's some suggestion that the pg gem is interacting with the Ruby HTTP code such that is causes a segfault. It always appears to happen when HTTP access is attempted on a given machine, although it's obviously not happening on all installations.

See: https://gist.github.com/863523/f367dcad815fad8b77e3ff594bc377dff396ab1f

Also: http://www.google.com/search?q=http.rb+678+pg

Sorry to be the bearer of bad news. Your work is greatly appreciated :)

pg 0.10.0 fails to compile on OpenSolaris

Original report by Don Morrison (Bitbucket: elskwid, GitHub: elskwid).


Hello pg team,

Recently ran into a problem compiling 0.10.0 on our OpenSolaris server. Server version: OpenSolaris 2008.11 snv_101b_rc2 X86


The error when bundler attempts the install:

Installing pg (0.10.0) with native extensions /usr/local/rubies/ruby-1.8.7-p302/lib/ruby/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/usr/local/rubies/ruby-1.8.7-p302/bin/ruby extconf.rb 
checking for pg_config... yes
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/rubies/ruby-1.8.7-p302/bin/ruby
        --with-pg
        --without-pg
        --with-pg-config
        --without-pg-config
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
        --with-pqlib
        --without-pqlib
        --with-libpqlib
        --without-libpqlib
        --with-ms/libpqlib
        --without-ms/libpqlib

The contents of mkmf.log

psex@worms:~/psexchange/current$ cat ../shared/bundle/ruby/1.8/gems/pg-0.10.0/ext/mkmf.log 
find_executable: checking for pg_config... -------------------- yes

--------------------

find_header: checking for libpq-fe.h... -------------------- yes

"gcc -E -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC  conftest.c -o conftest.i"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
gcc: conftest.c: linker input file unused because linking not done
checked program was:
/* begin */
1: #include <libpq-fe.h>
/* end */

--------------------

find_header: checking for libpq/libpq-fs.h... -------------------- yes

"gcc -E -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC  conftest.c -o conftest.i"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
gcc: conftest.c: linker input file unused because linking not done
checked program was:
/* begin */
1: #include <libpq/libpq-fs.h>
/* end */

--------------------

have_library: checking for PQconnectdb() in -lpq... -------------------- no

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -lpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -lpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */

--------------------

have_library: checking for PQconnectdb() in -llibpq... -------------------- no

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -llibpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -llibpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */

--------------------

have_library: checking for PQconnectdb() in -lms/libpq... -------------------- no

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -lms/libpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { void ((*volatile p)()); p = (void ((*)()))PQconnectdb; return 0; }
/* end */

"gcc -o conftest -I. -I/usr/local/rubies/ruby-1.8.7-p302/lib/ruby/1.8/i386-solaris2.11 -I.  -D_FILE_OFFSET_BITS=64  -I/usr/postgres/8.3/include -g -O2   -xO3 -xarch=386 -xchip=pentium -xspace -Xa  -xildoff -xc99=all  -xc99=none -xCC conftest.c  -L. -L/usr/local/rubies/ruby-1.8.7-p302/lib -Wl,-R/usr/local/rubies/ruby-1.8.7-p302/lib -L.  -L/usr/postgres/8.3/lib     -lruby-static -lms/libpq  -lpthread -lrt -ldl -lcrypt -lm   -lc"
gcc: unrecognized option `-Xa'
gcc: language CC not recognized
ld: fatal: file conftest.c: unknown file type
ld: fatal: File processing errors. No output written to conftest
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include <libpq-fe.h>
2: 
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */

--------------------

I did do some investigation/verification before filing the ticket:

  • verified my path configuration was correct, pg_config is available

  • the files that are reported as missing are actually on the server

  • since I deploy from cap, I made sure that the same failure is experienced when logged in to the server

  • checked rbconfig.rb for common erroneous compiler settings - they all looked good to me - and I had just recently compiled a new version of ruby 1.8.7 so I know the toolchain was working a short time ago. (I have attached a copy to this issue)

This same server is able to compile pg 0.9.0 no problem.

Please let me know if there is anything else I can do or information I can provide to help solve this problem.

Thank you!

pg should not crash when limit passed to text or binary columns

Original report by Anonymous.


I have a Rails project I'm converting from mysql to postgre and I found that my existing schema.rb file caused problems when a text or binary column had a limit parameter. Since postgre does not care about that parameter the way mysql does it is bessed to simply ignore those parameters and create the columns without raising an error:

PGError: ERROR: type modifier is not allowed for type "text"

A small issue in postgresql_adapter.rb (quote_column_name)

Original report by crazycrv (Bitbucket: crazycrv, ).


This is regarding a small issue I observed in postgresql adapter for rails. I am using postgre 9.0 as database with rails 2.3.8 and pg adapter 0.9.0 x86-mswin32.

I have roles and users models in my application and they both are associated with each other through a bridge table roles_users.

In roles_user.rb I have specified composite primary key as "set_primary_keys :user_id, :role_id" ( I am using composite_primary_keys (2.3.2) gem )

Now when I call "self.roles.push(Role.find(:first, :conditions => {:name => 'user'}))" it gives me following error

Column "user_id,role_id" does not exist.
INSERT INTO "roles_users" ("updated_at", "created_at", "user_id", "role_id") VALUES (NULL, NULL, 16, 5) RETURNING "user_id,role_id"

After looking into it I found that the error is because of following method of postgrsql_adapter.rb

#!ruby

def quote_column_name(name) #:nodoc:
       PGconn.quote_ident(name.to_s)
end

On executing the roles.push query this method is being passed following input by insert method in the same file

Input: [:user_id, :role_id]

The method calls quote_indent and generates following output which causes PG Error mentioned above.

Output: ""user_id,role_id""

To solve this I have changed the method as given below and it worked fine.

#!ruby

def quote_column_name(name) #:nodoc:

        if name.is_a(Array)

          quoted_columns = []

          for column_name in name

            quoted_columns << PGconn.quote_ident(column_name.to_s)

          end

          quoted_columns.join(',')

        else

          PGconn.quote_ident(name.to_s)

        end
end

With this new code the output generated for the same input is ""user_id","role_id""

I am not sure whether its a bug in the postgresql_adapter.rb file or I am doing some silly mistake.

returned type inconsistency: COUNT(a) returns a string

Original report by Anonymous.


I've had this code, that worked as expected on localhost with sqlite3 but not on Heroku.

This query creates a recordset of how many records were created per day:

#!ruby

votes = Game.find(13).user_votes.select("user_votes.created_at, COUNT(user_votes.id) as count").order("user_votes.created_at ASC").group("user_votes.created_at")

Now if you check

#!ruby

votes[0].count.is_a?(Integer)
votes[0].count.as_a?(String)

with sqlite3 you will get true, false. But with PG, it'll be false, true.

Count with Distinct is not working?

Original report by Anonymous.


Hi, I am using PostgreSQL 9.0.3 on x86_64-apple-darwin, compiled by GCC i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664), 64-bit (from select version()).

I'm having some trouble with a very simple query and wanted to know if there is something I am doing wrong because it appears that the gem is not working correctly or doing something my version of Postgres does not support:

ruby-1.9.2-p180 :016 > Requirement.count(:select => 'requirements.*', :distinct => true)
ActiveRecord::StatementInvalid: PGError: ERROR:  syntax error at or near "*"
LINE 1: SELECT COUNT(DISTINCT *) FROM "requirements"
                              ^
: SELECT COUNT(DISTINCT *) FROM "requirements"

The :select in the .count scope is not getting set correctly for whatever reason. The only workaround I have available to me is this, but its ugly:

Requirement.connection.execute("select count(distinct requirements.*) from requirements")[0]["count"]

Thoughts?

gem install pg on windows 7 fails

Original report by Anonymous.


When I run "bundle install", I get this error:

checking for pg_config... yes
Using config values from c:\PostgreSQL\9.0\bin/pg_config.exe
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

There might be hidden GC problem in ext/pg.c

Original report by Anonymous.


In totally different project (rocaml) I tracked down and identified (and fixed) this GC bug relating to rb_ary_new2. Then I went looking similar issues in the net and found this http://redmine.ruby-lang.org/issues/show/3174 which relates to pg and segfault.

This is kind of bug, which only happens when GC is triggered while code is executing in C code. And rb_ary_new2 has already created. And initialization of it is not complete yet! And code is using rb_newobj (maybe thru some non-visible way; like rb_tainted_str_new or rb_tainted_str_new2 and ending up in str_alloc/NEWOBJ).

So, in normal "toy" examples, you cannot reproduce it, because GC is not hit in trivial, short toy examples. You need memory shortage and big return array (created in foreign code side, not Ruby side; that means long row in ruby-pg case) to trigger this one.

I have identified two possible places where this could happen in pg.c. Search for rb_ary_new2 there. Ignore ones with rb_ary_new2(0) calls. You should find make_column_result_array and pgresult_fields methods (lines 3593 and 3652). In those methods, array is created and code starts to fill it. Problem is, code uses method which end up calling NEWOBJ macro in Ruby code, which might GC. And in that case, GC will find uninitialized memory pointer, tries to follow it and then it segfaults. Oops.

How to fix it? Simply initializing all those array fields before calling any rb__new methods. Qnil is enough. Something like following code (adjust to match your coding standards):

  ary = rb_ary_new2(n);
  for(i = 0; i < n; i++) {
      RARRAY(ary)->ptr[i] = Qnil;
  }

At least this worked with rocaml project and stopped it segfaulting while passing large arrays from OCaml to Ruby via rocaml generated C code.

Use your own judgement to decide if this actually affects ruby-pg code. And please note, I'm not expect on Ruby GC. This report might be total bs.

JMP

PostgreSQL 9.0 Load Error

Original report by Jeremiah Peschka (Bitbucket: peschkaj, GitHub: peschkaj).


When I install pg through gem, I am unable to load the library. I receive the following error:

>> require 'pg'
LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib
  Referenced from: /Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle
  Reason: image not found - /Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle
	from /Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg_ext.bundle
	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
	from /Library/Ruby/Gems/1.8/gems/pg-0.9.0/lib/pg.rb:9
	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
	from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
	from (irb):1

This is on OS X 10.6.4, using Ruby 1.8.7 (ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]) and PostgreSQL 9.0 (PostgreSQL 9.0.0 on x86_64-apple-darwin, compiled by GCC i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664), 64-bit)

pg-0.11.0 does not build native extension against ruby-1.9.3rc1

Original report by Sven Schwyn (Bitbucket: svoop, GitHub: svoop).


I'm trying to install the pg gem on a Gentoo box with postgresql-9.0.5 and ruby-1.9.3rc1. Here's what make has to say:

Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.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 PQgetCancel()... yes
checking for lo_create()... yes
checking for pg_encoding_to_char()... yes
checking for PQsetClientEncoding()... yes
checking for struct pgNotify.extra in libpq-fe.h... yes
checking for unistd.h... yes
creating extconf.h
creating Makefile

make
compiling compat.c
compiling pg.c
pg.c: In function β€˜pgconn_wait_for_notify’:
pg.c:2105:3: warning: β€˜rb_thread_select’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379)
pg.c: In function β€˜pgconn_block’:
pg.c:2589:3: warning: β€˜rb_thread_select’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/intern.h:379)
linking shared-object pg_ext.so
pg.o: In function `find_or_create_johab':
pg.c:(.text+0x4e): undefined reference to `rb_enc_alias'
pg.c:(.text+0x61): undefined reference to `rb_enc_alias'
collect2: ld returned 1 exit status
make: *** [pg_ext.so] Error 1

Any chance there might be an easy fix for this?

Thanks a bunch, -sven

There might be hidden GC problem in ext/pg.c

Original report by Anonymous.


In totally different project (rocaml) I tracked down and identified (and fixed) this GC bug relating to rb_ary_new2. Then I went looking similar issues in the net and found this http://redmine.ruby-lang.org/issues/show/3174 which relates to pg and segfault.

This is kind of bug, which only happens when GC is triggered while code is executing in C code. And rb_ary_new2 has already created. And initialization of it is not complete yet! And code is using rb_newobj (maybe thru some non-visible way; like rb_tainted_str_new or rb_tainted_str_new2 and ending up in str_alloc/NEWOBJ).

So, in normal "toy" examples, you cannot reproduce it, because GC is not hit in trivial, short toy examples. You need memory shortage and big return array (created in foreign code side, not Ruby side; that means long row in ruby-pg case) to trigger this one.

I have identified two possible places where this could happen in pg.c. Search for rb_ary_new2 there. Ignore ones with rb_ary_new2(0) calls. You should find make_column_result_array and pgresult_fields methods (lines 3593 and 3652). In those methods, array is created and code starts to fill it. Problem is, code uses method which end up calling NEWOBJ macro in Ruby code, which might GC. And in that case, GC will find uninitialized memory pointer, tries to follow it and then it segfaults. Oops.

How to fix it? Simply initializing all those array fields before calling any rb__new methods. Qnil is enough. Something like following code (adjust to match your coding standards):

  ary = rb_ary_new2(n);
  for(i = 0; i < n; i++) {
      RARRAY(ary)->ptr[i] = Qnil;
  }

At least this worked with rocaml project and stopped it segfaulting while passing large arrays from OCaml to Ruby via rocaml generated C code.

Use your own judgement to decide if this actually affects ruby-pg code. And please note, I'm not expect on Ruby GC. This report might be total bs.

JMP

HELP!! gem install pg failed on opensuse 10.3

Original report by syliang (Bitbucket: syliang, GitHub: syliang).


Hi,

This is my first time install pg gem on linux box and it is failed. The only error I saw is the libpq-fe.h not found. Below is the command I use and the output of the command:

>  /export/home/invantest/tools/ruby/current/bin/gem install pg -- --with-pg-config=/export/home/invantest/tools/pgsql/8.3.3/bin/pg_config

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
        ERROR: Failed to build gem native extension.

        /export/home/invantest/tools/ruby/1.8.7/bin/ruby extconf.rb --with-pg-config=/export/home/invantest/tools/pgsql/8.3.3/bin/pg_config
Using config values from /export/home/invantest/tools/pgsql/8.3.3/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/export/home/invantest/tools/ruby/1.8.7/bin/ruby
        --with-pg
        --without-pg
        --with-pg-dir
        --without-pg-dir
        --with-pg-include
        --without-pg-include=${pg-dir}/include
        --with-pg-lib
        --without-pg-lib=${pg-dir}/lib
        --with-pg-config


Gem files will remain installed in /export/home/invantest/tools/ruby/1.8.7/lib/ruby/gems/1.8/gems/pg-0.11.0 for inspection.
Results logged to /export/home/invantest/tools/ruby/1.8.7/lib/ruby/gems/1.8/gems/pg-0.11.0/ext/gem_make.out

When I do a ls on the include path, it show that the file is really exist:

> ls /export/home/invantest/tools/pgsql/8.3.3/include/libpq-fe.h
/export/home/invantest/tools/pgsql/8.3.3/include/libpq-fe.h

I have no idea what else missing.

  • Ruby version is 1.8.7
  • Postgresql version is 8.3.3

I also included the mkmf.log for your reference. I am very appreciate for your help.

Added PGresult#values to return an array of arrays

Original report by yanowitz (Bitbucket: yanowitz, GitHub: yanowitz).


I just pushed https://bitbucket.org/yanowitz/ruby-pg/changeset/59679aee98ee which adds PGresult#values method. I wrote this to speed up ActiveRecord, which internally converts the Hash ruby-pg returns into an array (there are other optimizations to ActiveRecord that I'll be submitting to Rails independently, but this one may be generally useful for folks).

This is how the old postgres ruby gem used to work (PGresult.to_a would give you an array of arrays).

After discussing with Michael Granger, I've arrived at this approach.

Cheers,
Jason

cmd should be quoted

Original report by Anonymous.


in extconf.rb at 13 and 14 lines:

#!ruby

$CPPFLAGS << " -I%s" % [ `"#{pgconfig}" --includedir`.chomp ]
$LDFLAGS << " -L%s" % [ `"#{pgconfig}" --libdir`.chomp ]

Attempt to install pg following instructions fails

Original report by John Poole (Bitbucket: jlpoole, GitHub: jlpoole).


=== Goal: I want to connect to PostgreSQL from Ruby. ===

I installed Ruby and tried to install within the fresh installation. Here are my notes:

ran rubyinstaller-1.9.2-p180.exe

Selected path: C:\Ruby\192 (note: default was Ruby192, I isolated the 192)

  • Added Ruby to the Path

  • Associated rb with this installation

Confirmed install: opened DOS console:

C:\Documents and Settings\jlpoole>ruby -v
ruby 1.9.2p180 (2011-02-18) [i386-mingw32]
C:\Documents and Settings\jlpoole>

Using instructions at https://bitbucket.org/ged/ruby-pg/wiki/Home

C:\Documents and Settings\jlpoole>gem install pg
Fetching: pg-0.10.1.gem (100%)
ERROR:  Error installing pg:
		The 'pg' native gem requires installed build tools.

Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

C:\Documents and Settings\jlpoole>

The current instructions at https://bitbucket.org/ged/ruby-pg/wiki/Home provide:

	ruby-pg: Ruby interface to PostgreSQL RDBMS

	This is the extension library to access a PostgreSQL database from Ruby. This library works with PostgreSQL 7.4 and later.
	Requirements

		Ruby 1.8.6 or later.
		PostgreSQL 7.3 or later installed. 

	It may work with earlier versions as well, but those are not regularly tested.
	How To Install

	Install via RubyGems:

	gem install pg

	Or install from source:

	rake install

	You may need to specify the path to the 'pg_config' program installed with Postgres:

	rake -- --with-pg-config=<path to pg_config>

	For example, on a Mac with PostgreSQL installed via MacPorts (port install postgresql84):

	rake install -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config

	See MacOS X Instructions for more information about installing under MacOS X, and Win32 Instructions for Windows build/installation instructions.

My operating system is:

  • From the DOS console: Microsoft Windows XP [Version 5.1.2600]
  • From the System Properties: Microsoft Windows XP Profession Version 2002 Service Pack 3

I have PostgreSQL installed at: C:\Program Files\PostgreSQL\8.4

It appears I need to have a development kit installed? Shouldn't the instructions indicate that? I've tried to install the development kit and have had problems and am pursuing that with the appropriate group.

Create a mirror of this repo on GitHub

Original report by Anonymous.


Hello,

since GitHub has the most active community of ruby developers, I suggest to make a git mirror of this repo on GitHub (I don't suggest to move it to GitHub because I'm sure you already evaluated GitHub/git and you have your reasons for using BitBucket/hg).

A GitHub mirror would give more visibility to this project, and for an open source project more visibility = more development, more bug reportings, less issues, and generally it would improve the project quality.

Thank you for your work!

Add new libpq features from 9.1.

Original report by Michael Granger (Bitbucket: ged, GitHub: ged).


There are a few new libpq features that should be reflected in the API:

  • Use the client_encoding connection option to set the encoding to Encoding.default_internal for async connections, too.
  • PGconn::library_version (PQlibVersion)
  • PGconn::ping (PQpingParams)

segfault on ruby 1.8 and ruby 1.9 using activerecord with pg 0.11.0

Original report by Anonymous.


I don't know if it's an activerecord bug or pg gem bug but as it's a segfault, I would think it's more likely a gem using C extension.
Using ruby 1.8.7 or 1.9.2p180 and Rails 2.3.10 or Rails 3.1.rc4 with libpq-dev 9.0.4-1+b1 (debian), I got everytime a segfault when trying to access the database.

/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:987: [BUG] Segmentation fault
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]

-- control frame ----------
c:0074 p:---- s:0285 b:0285 l:000284 d:000284 CFUNC  :initialize
c:0073 p:---- s:0283 b:0283 l:000282 d:000282 CFUNC  :new
c:0072 p:0020 s:0273 b:0273 l:000272 d:000272 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:98
c:0071 p:0055 s:0270 b:0270 l:000269 d:000269 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:26
c:0070 p:---- s:0263 b:0263 l:000262 d:000262 FINISH
c:0069 p:---- s:0261 b:0261 l:000260 d:000260 CFUNC  :new
c:0068 p:0174 s:0254 b:0254 l:000253 d:000253 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:27
c:0067 p:0045 s:0245 b:0245 l:000244 d:000244 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0066 p:0033 s:0242 b:0242 l:000241 d:000241 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0065 p:0048 s:0238 b:0238 l:000224 d:000237 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0064 p:---- s:0235 b:0235 l:000234 d:000234 FINISH
c:0063 p:---- s:0233 b:0233 l:000232 d:000232 CFUNC  :loop
c:0062 p:0009 s:0230 b:0230 l:000224 d:000229 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0061 p:0019 s:0228 b:0228 l:000227 d:000227 METHOD /home/eppo/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201
c:0060 p:0013 s:0225 b:0225 l:000224 d:000224 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0059 p:0030 s:0222 b:0219 l:000218 d:000218 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0058 p:0033 s:0216 b:0216 l:000215 d:000215 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool
c:0057 p:0018 s:0211 b:0211 l:000210 d:000210 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_spec
c:0056 p:0011 s:0208 b:0208 l:000207 d:000207 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_spec
c:0055 p:0155 s:0205 b:0205 l:000204 d:000204 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/has_and_belongs_to_many
c:0054 p:0023 s:0201 b:0201 l:000200 d:000200 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/has_and_belongs_to_many
c:0053 p:0025 s:0197 b:0197 l:000196 d:000196 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/collection_association.
c:0052 p:0030 s:0190 b:0190 l:000189 d:000189 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations.rb:1574
c:0051 p:0057 s:0184 b:0184 l:000183 d:000183 CLASS  /home/eppo/git/mono-ror/app/models/user.rb:4
c:0050 p:0017 s:0182 b:0182 l:000181 d:000181 TOP    /home/eppo/git/mono-ror/app/models/user.rb:1
c:0049 p:---- s:0180 b:0180 l:000179 d:000179 FINISH
c:0048 p:---- s:0178 b:0178 l:000177 d:000177 CFUNC  :load
c:0047 p:0018 s:0174 b:0174 l:000165 d:000173 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:452
c:0046 p:0045 s:0172 b:0172 l:000171 d:000171 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639
c:0045 p:0086 s:0166 b:0166 l:000165 d:000165 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:451
c:0044 p:0194 s:0158 b:0158 l:000157 d:000157 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:338
c:0043 p:0277 s:0150 b:0150 l:000149 d:000149 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:489
c:0042 p:0036 s:0137 b:0137 l:000127 d:000136 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:181
c:0041 p:---- s:0133 b:0133 l:000132 d:000132 FINISH
c:0040 p:---- s:0131 b:0131 l:000130 d:000130 CFUNC  :each
c:0039 p:0074 s:0128 b:0128 l:000127 d:000127 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:179
c:0038 p:---- s:0121 b:0121 l:000120 d:000120 FINISH
c:0037 p:0007 s:0119 b:0119 l:000118 d:000118 TOP    /home/eppo/git/mono-ror/config/initializers/rolify.rb:1
c:0036 p:---- s:0117 b:0117 l:000116 d:000116 FINISH
c:0035 p:---- s:0115 b:0115 l:000114 d:000114 CFUNC  :load
c:0034 p:0012 s:0111 b:0111 l:000095 d:000110 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:233
c:0033 p:0005 s:0109 b:0109 l:000100 d:000108 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223
c:0032 p:0045 s:0107 b:0107 l:000106 d:000106 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639
c:0031 p:0041 s:0101 b:0101 l:000100 d:000100 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223
c:0030 p:0013 s:0096 b:0096 l:000095 d:000095 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:233
c:0029 p:0012 s:0091 b:0091 l:00215c d:000090 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/engine.rb:544
c:0028 p:---- s:0088 b:0088 l:000087 d:000087 FINISH
c:0027 p:---- s:0086 b:0086 l:000085 d:000085 CFUNC  :each
c:0026 p:0037 s:0083 b:0083 l:00215c d:000082 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/engine.rb:543
c:0025 p:---- s:0081 b:0081 l:000080 d:000080 FINISH
c:0024 p:---- s:0079 b:0079 l:000078 d:000078 CFUNC  :instance_exec
c:0023 p:0022 s:0075 b:0075 l:000074 d:000074 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:25
c:0022 p:0014 s:0071 b:0071 l:000062 d:000070 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:50
c:0021 p:---- s:0068 b:0068 l:000067 d:000067 FINISH
c:0020 p:---- s:0066 b:0066 l:000065 d:000065 CFUNC  :each
c:0019 p:0042 s:0063 b:0063 l:000062 d:000062 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:49
c:0018 p:0029 s:0059 b:0059 l:000058 d:000058 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/application.rb:96
c:0017 p:0021 s:0056 b:0056 l:000055 d:000055 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/railtie/configurable.rb:30
c:0016 p:---- s:0051 b:0051 l:000050 d:000050 FINISH
c:0015 p:0044 s:0049 b:0049 l:000048 d:000048 TOP    /home/eppo/git/mono-ror/config/environment.rb:5
c:0014 p:---- s:0047 b:0047 l:000046 d:000046 FINISH
c:0013 p:---- s:0045 b:0045 l:000044 d:000044 CFUNC  :require
c:0012 p:0012 s:0041 b:0041 l:000025 d:000040 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237
c:0011 p:0005 s:0039 b:0039 l:000030 d:000038 BLOCK  /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223
c:0010 p:0045 s:0037 b:0037 l:000036 d:000036 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639
c:0009 p:0041 s:0031 b:0031 l:000030 d:000030 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223
c:0008 p:0013 s:0026 b:0026 l:000025 d:000025 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237
c:0007 p:0046 s:0021 b:0021 l:000020 d:000020 METHOD /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/application.rb:78
c:0006 p:0399 s:0017 b:0017 l:000016 d:000016 TOP    /home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands.rb:22
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :require
c:0003 p:0061 s:0006 b:0006 l:001bdc d:001abc EVAL   script/rails:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:001bdc d:001bdc TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
script/rails:6:in `<main>'
script/rails:6:in `require'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/commands.rb:22:in `<top (required)>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/application.rb:78:in `require_environment!'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `load_dependency'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `block in require'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:237:in `require'
/home/eppo/git/mono-ror/config/environment.rb:5:in `<top (required)>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/application.rb:96:in `initialize!'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:49:in `run_initializers'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:49:in `each'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:50:in `block in run_initializers'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:25:in `run'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/initializable.rb:25:in `instance_exec'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/engine.rb:543:in `block in <class:Engine>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/engine.rb:543:in `each'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.0.rc4/lib/rails/engine.rb:544:in `block (2 levels) in <class:Engine>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:233:in `load'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `load_dependency'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:223:in `block in load_dependency'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:233:in `block in load'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:233:in `load'
/home/eppo/git/mono-ror/config/initializers/rolify.rb:1:in `<top (required)>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:179:in `const_missing'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:179:in `each'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:181:in `block in const_missing'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:489:in `load_missing_constant'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:338:in `require_or_load'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:451:in `load_file'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:639:in `new_constants_in'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:452:in `block in load_file'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc4/lib/active_support/dependencies.rb:452:in `load'
/home/eppo/git/mono-ror/app/models/user.rb:1:in `<top (required)>'
/home/eppo/git/mono-ror/app/models/user.rb:4:in `<class:User>'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations.rb:1574:in `has_and_belongs_to_many'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/collection_association.rb:13:in `build'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/has_and_belongs_to_many.rb:9:in `build'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/associations/builder/has_and_belongs_to_many.rb:43:in `check_validity'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:388:in `retrieve_connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:151:in `connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:249:in `checkout'
/home/eppo/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:250:in `block in checkout'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:250:in `loop'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:254:in `block (2 levels) in checkout'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:302:in `checkout_new_connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `new_connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `postgresql_connection'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `new'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:260:in `initialize'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:987:in `connect'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:987:in `new'
/home/eppo/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:987:in `initialize'

it's my own app but trying with redmine or new rails app from scratch does the same. is there any incompatibility between this gem and postgresql version on debian ?

JRuby + Windows compilation does not works

Original report by evgenymyasishchev (Bitbucket: evgenymyasishchev, ).


Not sure, but perhaps the issue is related to <<issue 71>>

Summary: Trying to compile pg gem under windows platform and JRuby fails. I have also checked JRuby + pg under Mac OSX and it has compiled successfully.

Compiler used: devkit (https://github.com/oneclick/rubyinstaller/wiki/development-kit).

I have also checked the same compiler under Windows and normal Ruby 1.8.7. Compiled and installed successfully (gem install pg --platform=ruby)

The error is (see attached gem_make.out for more details):

pg.c: In function 'create_crt_fd':
pg.c:2029:3: error: 'WSAPROTOCOL_INFO' undeclared (first use in this function)
pg.c:2029:3: note: each undeclared identifier is reported only once for each function it appears in
pg.c:2029:20: error: expected ';' before 'wsa_pi'
pg.c:2031:75: error: 'wsa_pi' undeclared (first use in this function)
make: *** [pg.o] Error 1 

gem env:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.5.1
  - RUBY VERSION: 1.8.7 (2011-08-23 patchlevel 330) [java]
  - INSTALLATION DIRECTORY: c:/ruby/jruby-1.6.4-gems
  - RUBY EXECUTABLE: c:/ruby/jruby-1.6.4/bin/jruby.exe
  - EXECUTABLE DIRECTORY: c:/ruby/jruby-1.6.4-gems/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-java-1.6
  - GEM PATHS:
     - c:/ruby/jruby-1.6.4-gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri --env-shebang"
     - "update" => "--no-rdoc --no-ri --env-shebang"
  - REMOTE SOURCES:
     - http://rubygems.org/ 

Win32 asynchronous queries hang on connection error

Original report by RafaΕ‚ Bigaj (Bitbucket: rafalbigaj, GitHub: rafalbigaj).


I encountered the following problems on win32 system with all version of pg (0.9.0, 0.9.1, 0.10.0, 0.10.1 and 0.11.0) on Ruby 1.9:

During asynchronous queries the CPU usage is 100% - rb_w32_thread_select does not wait any time on foreign socket (not created with ruby socket API). The only way I found to workaround the problem is simple waiting 1ms before each select if the PG is busy.

PQConsumeInput result is not interpreted in pgconn_block what makes the waiting loop infinite (PQisBusy returns always TRUE) if connection error occurs

pgconn_async_exec can block the interpreter for a long time on initial pgconn_get_last_result (pgconn_block is not called before)

I have committed the fixes for above problems to my fork at:
https://bitbucket.org/rafalbigaj/ruby-pg/changeset/17a6a01c1725

There's no documentation

Original report by Anonymous.


There's no online documentation for the pg gem. Googling and running gem server show no docs on how to use it.

Online tools (maybe rdoc?) are too cumbersome; documentation should just be online and should be available for all versions of the pg gem.

Is the rake-compiler gem needed for runtime?

Original report by eolamey (Bitbucket: eolamey, GitHub: eolamey).


Hi,

I am packaging pg as a RPM for RHEL (and derivatives) and I wanted to add the latest 0.12.0 release. I can see that rake-compiler has been added as a runtime dependency. Is this really needed, or should it only be a development one?
If rake-compiler is really needed at runtime, does it mean that a C compiler is also needed?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.