# Postgres DBI question

**URL:** <https://rubytalk.org/t/postgres-dbi-question/21867>\
**Category:** ruby-talk\
**Created:** [25 October 2005 12:21 UTC](https://rubytalk.org/t/postgres-dbi-question/21867 "2005-10-25T12:21:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Newman](https://avatars.discourse-cdn.com/v4/letter/c/4da419/32.png) [@Chris\_Newman](https://rubytalk.org/u/Chris_Newman)\
**Post date:** [25 October 2005 12:21 UTC](https://rubytalk.org/t/postgres-dbi-question/21867/1 "2005-10-25T12:21:47Z")

</div>

Hi,

I'm trying to connect to a Postgresql database using the DBI and postgres  
packages. My OS is Solaris 2.8.

Here's my code snippet...

#!/usr/local/bin/ruby

require 'dbi'  
require 'postgres'

dbh = DBI.connect('dbi:Pg:dbname=somedbasename;host=/var/tmp', 'someuser',  
'somepasswd')

dbh.disconnect

However, when I run it I get...

/usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:490:in `load\_driver': is not a  
class/module (TypeError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:392:in  
`\_get\_full\_driver'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:372:in `connect'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./ptexec\_query.rb:9

I want to use DBI in case I want to change databases in the future. Any  
suggestions would be appreciated.

Thanks,

cn

---

<div class="post-metadata">

**Author:** ![Ernest\_Ellingson2](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@Ernest\_Ellingson2](https://rubytalk.org/u/Ernest_Ellingson2)\
**Post date:** [25 October 2005 13:52 UTC](https://rubytalk.org/t/postgres-dbi-question/21867/2 "2005-10-25T13:52:03Z")

</div>

Chris Newman wrote:

> Hi,
> 
> I'm trying to connect to a Postgresql database using the DBI and postgres  
> packages. My OS is Solaris 2.8.
> 
> Here's my code snippet...
> 
> #!/usr/local/bin/ruby
> 
> require 'dbi'  
> require 'postgres'
> 
> dbh = DBI.connect('dbi:Pg:dbname=somedbasename;host=/var/tmp', 'someuser',  
> 'somepasswd')
> 
> dbh.disconnect
> 
> However, when I run it I get...
> 
> /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:490:in `load\_driver': is not a  
> class/module (TypeError)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:392:in  
> `\_get\_full\_driver'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:372:in `connect'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./ptexec\_query.rb:9
> 
> I want to use DBI in case I want to change databases in the future. Any  
> suggestions would be appreciated.
> 
> Thanks,
> 
> cn

Here's a link to some documentation on the dbi.  
[http://www.kitebird.com/articles/ruby-dbi.html](http://www.kitebird.com/articles/ruby-dbi.html)  
Hope it helps

Ernie

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [25 October 2005 15:21 UTC](https://rubytalk.org/t/postgres-dbi-question/21867/3 "2005-10-25T15:21:52Z")

</div>

> Hi,
> 
> I'm trying to connect to a Postgresql database using the DBI and postgres  
> packages. My OS is Solaris 2.8.
> 
> Here's my code snippet...
> 
> #!/usr/local/bin/ruby
> 
> require 'dbi'  
> require 'postgres'

^^^^^^^^^^^^^^^^^^-- Don't need this line. DBI will find the right driver and  
load it itself.

> /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:490:in `load\_driver': is not  
> a class/module (TypeError)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:392:in  
> `\_get\_full\_driver'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/site\_ruby/1.8/dbi/dbi.rb:372:in `connect'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./ptexec\_query.rb:9

DBI is complaining that it can't find the DBD driver that you told it to use  
'Pg' here.

The problem, I bet, is that when you build DBI, you didn't build the DBD for  
Pg.

When dbi is built, make sure to tell it what DBD's you want, like this:

ruby setup.rb config --with=dbi,dbd\_pg,dbd\_mysql

If you look in your sitelib for your ruby installation, in the DBD directory  
(a path like /usr/local/lib/ruby/site\_ruby/1.8/DBD) you should see a Pg  
directory with a Pg.rb inside of it. If you don't, go back to the DBI  
source, and do this:

ruby setup.rb config --with=dbd\_pg  
ruby setup.rb setup  
ruby setup.rb install

And then try your snippet again.

Kirk Haines

> **···**
>
> On Tuesday 25 October 2005 6:21 am, Chris Newman wrote:
