Bus error in ./script/console with postgres (ext. library)

Is there some special magic that needs to be performed so that the
C-based postgres extension library works with the Rails console?

I have installed the postgres extension library (replacing the pure Ruby
version: postgres-pr) from http://ruby.scripting.ca/postgres/

Everything works great from WEBrick, but as soon as I fire up the
console and try to use it, I get a bus error:


% ./script/console
Loading development environment.

t = Content.new
/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0/postgres.bundle:
[BUG] Bus Error
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

Abort
% ./script/console
Loading development environment.

require ‘postgres’
/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0/postgres.bundle:
[BUG] Bus Error
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

Abort

If I remove the postgres.bundle that’s in
/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0, the connection
adapter falls back on postgres-pr and everything works fine.

Oddly, the extension library works fine through irb:


% irb
irb(main):001:0> require ‘postgres’
=> true
irb(main):002:0> conn = PGconn.connect(“localhost”, 8000, “”, “”,
“Site_development”, “postgres”)
=> #PGconn:0x5b0b8
irb(main):003:0> conn.db
=> “Site_development”
irb(main):004:0> res = conn.exec("select count() from content")
LOG: duration: 10.191 ms statement: select count(
) from content
=> #PGresult:0x556a4
irb(main):005:0> res.fields
=> [“count”]
irb(main):006:0> res.getvalue(0,0)
=> “560”

Obviously, the console isn’t doing something right… but I can’t figure
out what that is…

-ch

“Craig” == Craig H. [email protected] writes:

Is there some special magic that needs to be performed so that the
C-based postgres extension library works with the Rails console?

No.

/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0/postgres.bundle:
[BUG] Bus Error
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

This looks funny. The /opt/local looks like you’re using DarwinPorts,
but DarwinPorts’ Ruby is 1.8.4, not 1.8.2. The system’s Ruby, on the
other hand, is 1.8.2. If you’re running the server with one Ruby and
the console with another, that might explain why they behave
differently.

	     Calle D. <[email protected]>
	 http://www.livejournal.com/users/cdybedahl/
  "It's not much of a silver lining, but I'll take what I can get."
		  -- yasminm, on LiveJournal

Craig H. wrote:

Obviously, the console isn’t doing something right… but I can’t figure
out what that is…

It sounds like you’re getting ruby from two different paths. Type “echo
$PATH” from a term window – make sure it says something like:

/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin

If not, you need to edit your .profile or .bash_profile to add the
/opt/local stuff to the front (so you’ll get your DarwinPorts installs
by preference to whatever came on the system). Something like this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

You should also look inside your project folder at public/dispatch.*.
Make sure the hashbang lines say

#!/opt/local/bin/ruby

Else your Rails project isn’t really using the copy of ruby you think it
is.

–Al Evans

Calle D. wrote:

“Craig” == Craig H. [email protected] writes:

Is there some special magic that needs to be performed so that the
C-based postgres extension library works with the Rails console?

No.

/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.2.0/postgres.bundle:
[BUG] Bus Error
ruby 1.8.2 (2004-12-25) [powerpc-darwin8.2.0]

This looks funny. The /opt/local looks like you’re using DarwinPorts,
but DarwinPorts’ Ruby is 1.8.4, not 1.8.2. The system’s Ruby, on the
other hand, is 1.8.2. If you’re running the server with one Ruby and
the console with another, that might explain why they behave
differently.

Thanks Calle.

I just updated the Ruby port to 1.8.4 and everything seems to be working
fine now.

-ch

I just updated the Ruby port to 1.8.4 and everything seems to be working
fine now.

Actually, this doesn’t work in all cases (e.g. my production server!)

The real solution is to modify irb.rb as per the instructions in the
following Rails ticket:

http://dev.rubyonrails.org/ticket/1283

-ch