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

**URL:** <https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466>\
**Category:** Rails\
**Created:** [April 21, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466 "2006-04-21T22:46:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcraig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@craigcraig](https://www.ruby-forum.com/u/craigcraig)\
**Post date:** [April 21, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466/1 "2006-04-21T22:46:15Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![craigcraig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@craigcraig](https://www.ruby-forum.com/u/craigcraig)\
**Post date:** [April 22, 2006, 9:48am UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466/2 "2006-04-22T09:48:21Z")

</div>

> > > > > “Craig” == Craig H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. <removed_email_address@domain.invalid>
	 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

```

---

<div class="post-metadata">

**Author:** ![craigcraig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@craigcraig](https://www.ruby-forum.com/u/craigcraig)\
**Post date:** [April 22, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466/3 "2006-04-22T14:11:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![craigcraig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@craigcraig](https://www.ruby-forum.com/u/craigcraig)\
**Post date:** [April 24, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466/4 "2006-04-24T18:16:26Z")

</div>

Calle D. wrote:

> > > > > > “Craig” == Craig H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![craigcraig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/96bed5/32.png) [@craigcraig](https://www.ruby-forum.com/u/craigcraig)\
**Post date:** [April 26, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/bus-error-in-script-console-with-postgres-ext-library/58466/5 "2006-04-26T19:27:25Z")

</div>

> 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](http://dev.rubyonrails.org/ticket/1283)

-ch
