Forum: Ruby on Rails Bus error in ./script/console with postgres (ext. library)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
646ce3f178af64df9b0bb9d73e31e3bc?d=identicon&s=25 Craig Hockenberry (Guest)
on 2006-04-21 22:46
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
9d7d8ef2179661d6b30e180fa588cd45?d=identicon&s=25 Calle Dybedahl (Guest)
on 2006-04-22 09:48
(Received via mailing list)
>>>>> "Craig" == Craig Hockenberry <craig.hockenberry@gmail.com> 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 Dybedahl <calle@cyberpomo.com>
		 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
807e34b31d5463a9ac05d41458a9e537?d=identicon&s=25 Al Evans (al-evans)
on 2006-04-22 14:11
Craig Hockenberry 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
646ce3f178af64df9b0bb9d73e31e3bc?d=identicon&s=25 Craig Hockenberry (Guest)
on 2006-04-24 18:16
Calle Dybedahl wrote:
>>>>>> "Craig" == Craig Hockenberry <craig.hockenberry@gmail.com> 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
646ce3f178af64df9b0bb9d73e31e3bc?d=identicon&s=25 Craig Hockenberry (Guest)
on 2006-04-26 19:27
> 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
This topic is locked and can not be replied to.