# Q: postgres access in Windows

**URL:** <https://rubytalk.org/t/q-postgres-access-in-windows/47973>\
**Category:** ruby-talk\
**Created:** [28 July 2008 12:14 UTC](https://rubytalk.org/t/q-postgres-access-in-windows/47973 "2008-07-28T12:14:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![G\_Ralph\_Kuntz\_MD](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@G\_Ralph\_Kuntz\_MD](https://rubytalk.org/u/G_Ralph_Kuntz_MD)\
**Post date:** [28 July 2008 12:14 UTC](https://rubytalk.org/t/q-postgres-access-in-windows/47973/1 "2008-07-28T12:14:40Z")

</div>

I spent a couple of hour this weekend trying to get Ruby to talk to  
PostgreSQL on a Windows Vista machine without success. I am working  
with both Cygwin Ruby and JRuby.

I installed the DBI gem, including dbd\_pg. I get the following error  
in both version of Ruby:

&nbsp;&nbsp;&nbsp;&nbsp;Could not load driver (no such file to load -- /usr/lib/ruby/  
site\_ruby/1.8/dbd/Pg)

I also tried jruby-postgres and pgconn but I could not figure out how  
to call the first one and got errors with the second. I could not  
find any documentation (even tried ri).

I tried Googling everything I could think of.

Has anyone gotten a DB connection to PostgreSQL working under Windows  
with any version of Ruby?

Thanks.

---

<div class="post-metadata">

**Author:** ![J-H\_Johansen](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@J-H\_Johansen](https://rubytalk.org/u/J-H_Johansen)\
**Post date:** [28 July 2008 12:47 UTC](https://rubytalk.org/t/q-postgres-access-in-windows/47973/2 "2008-07-28T12:47:44Z")

</div>

Hi,

My current use of postgres is done like this (but I think you can  
require 'dbi' instead of 'rubygems'):

require 'rubygems'  
require 'postgres'

$conn = PGconn.connect('hostname','port','','','db-name','username','password')

If you've installed rails you can also do the following in order to  
use ActiveRecord which is nice:

require 'rubygems'  
require 'active\_record'  
&nbsp;&nbsp;  
ActiveRecord::Base.pluralize\_table\_names = false  
ActiveRecord::Base.establish\_connection(  
&nbsp;&nbsp;:adapter =\> "postgresql",  
&nbsp;&nbsp;:host =\> "hostname",  
&nbsp;&nbsp;:database =\> "db-name",  
&nbsp;&nbsp;:username =\> "username",  
&nbsp;&nbsp;:password =\> "password"  
)

And then create objects of tables or views.  
Assuming you have a table or a view called gen\_table:

class GenTable \< ActiveRecord::Base; end  
gt = GenTable.find(:all)

for a in gt  
&nbsp;&nbsp;&nbsp;&nbsp;puts a.id  
end

> **···**
>
> On Mon, Jul 28, 2008 at 2:14 PM, G. Ralph Kuntz, MD, MS \<grk@usa.net\> wrote:
> 
> > I spent a couple of hour this weekend trying to get Ruby to talk to  
> > PostgreSQL on a Windows Vista machine without success. I am working  
> > with both Cygwin Ruby and JRuby.
> > 
> > I installed the DBI gem, including dbd\_pg. I get the following error  
> > in both version of Ruby:
> > 
> > &nbsp;&nbsp;&nbsp;Could not load driver (no such file to load -- /usr/lib/ruby/  
> > site\_ruby/1.8/dbd/Pg)
> > 
> > I also tried jruby-postgres and pgconn but I could not figure out how  
> > to call the first one and got errors with the second. I could not  
> > find any documentation (even tried ri).
> > 
> > I tried Googling everything I could think of.
> > 
> > Has anyone gotten a DB connection to PostgreSQL working under Windows  
> > with any version of Ruby?
> > 
> > Thanks.
> 
> --  
> J-H Johansen  
> --  
> There are 10 kinds of people in the world: Those who understand binary and  
> those who don't...

---

<div class="post-metadata">

**Author:** ![G\_Ralph\_Kuntz\_MD](https://avatars.discourse-cdn.com/v4/letter/g/f07891/32.png) [@G\_Ralph\_Kuntz\_MD](https://rubytalk.org/u/G_Ralph_Kuntz_MD)\
**Post date:** [28 July 2008 17:45 UTC](https://rubytalk.org/t/q-postgres-access-in-windows/47973/3 "2008-07-28T17:45:24Z")

</div>

That worked like a charm!

Is there any documentation on PGconn and the other classes in the  
postgres-pr module?

Thanks.
