# Connecting to PostgreSQL Database

**URL:** <https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011>\
**Category:** Ruby\
**Created:** [October 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011 "2007-10-01T17:02:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [October 1, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011/1 "2007-10-01T17:02:07Z")

</div>

Hello,

I am trying to move data from one postgres database to another using  
the Ruby postgres adapter. However, I keep getting a password  
authentication error whenever I try. My sysadmin keeps indicating that  
there is no password on that database and the Rails apps I use don’t  
indicate any password in database.yml and work fine. Am I being lied  
to or is there some other secret I don’t know? Thanks for any help or  
suggestions. Here’s the code I’m using (and line 184 DOES work):

184: db1 = PGconn.connect(‘[dbserver1.blah.com](http://dbserver1.blah.com)’, 5432, ‘’, ‘’,  
‘database1\_name’, ‘username’, ‘password’)  
185: db2 = PGconn.connect(‘[dbserver2.blah.com](http://dbserver2.blah.com)’, 5432, ‘’, ‘’,  
‘database2\_name’, ‘username’, ‘’)

And here’s the error:

c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/postgres-pr/  
connection.rb:55:in `initialize': FATAL C28000 MPassword authentication failed for user "username" Fauth.c L395 Rauth_failed (RuntimeError) from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/ postgres-pr/connection.rb:29:in `loop’  
from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/  
postgres-pr/connection.rb:29:in `initialize' from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/ postgres-pr/postgres-compat.rb:23:in `new’  
from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/  
postgres-pr/postgres-compat.rb:23:in `initialize' from DataFetcher.rb:185:in `connect’  
from DataFetcher.rb:185

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [October 1, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011/2 "2007-10-01T17:07:28Z")

</div>

On 10/1/07, Matt W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 184: db1 = PGconn.connect(‘[dbserver1.blah.com](http://dbserver1.blah.com)’, 5432, ‘’, ‘’,  
> from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/  
> postgres-pr/connection.rb:29:in `loop' from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/ postgres-pr/connection.rb:29:in `initialize’  
> from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/  
> postgres-pr/postgres-compat.rb:23:in `new' from c:/ruby/lib/ruby/gems/1.8/gems/postgres-pr-0.4.0/lib/ postgres-pr/postgres-compat.rb:23:in `initialize’  
> from DataFetcher.rb:185:in `connect’  
> from DataFetcher.rb:185

Have you tried giving it a nil for the password rather than an empty  
string?

V/r  
Anthony

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [October 1, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011/3 "2007-10-01T17:16:51Z")

</div>

> 184: db1 = PGconn.connect(‘[dbserver1.blah.com](http://dbserver1.blah.com)’, 5432, ‘’, ‘’,  
> ‘database1\_name’, ‘username’, ‘password’)  
> 185: db2 = PGconn.connect(‘[dbserver2.blah.com](http://dbserver2.blah.com)’, 5432, ‘’, ‘’,  
> ‘database2\_name’, ‘username’, ‘’)

Are you sure that the passwordless connection works okay from the  
machine you’re  
attempting from? You can configure postgres to only accept connections  
from certain  
ip addresses for certain users. A lot of times, the default is to allow  
passwordless login from localhost, but not from remote hosts.

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [October 1, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011/4 "2007-10-01T21:46:12Z")

</div>

Turns out I _was_ lied to. There is a password on there. Sorry to  
trouble you all.

---

<div class="post-metadata">

**Author:** ![mwalsh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/91b2a8/32.png) [@mwalsh](https://www.ruby-forum.com/u/mwalsh)\
**Post date:** [October 1, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/connecting-to-postgresql-database/116011/5 "2007-10-01T17:40:52Z")

</div>

On Oct 1, 9:15 am, “Caleb T.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 184: db1 = PGconn.connect(‘[dbserver1.blah.com](http://dbserver1.blah.com)’, 5432, ‘’, ‘’,  
> > ‘database1\_name’, ‘username’, ‘password’)  
> > 185: db2 = PGconn.connect(‘[dbserver2.blah.com](http://dbserver2.blah.com)’, 5432, ‘’, ‘’,  
> > ‘database2\_name’, ‘username’, ‘’)
> 
> Are you sure that the passwordless connection works okay from the machine you’re  
> attempting from? You can configure postgres to only accept connections from certain  
> ip addresses for certain users. A lot of times, the default is to allow  
> passwordless login from localhost, but not from remote hosts.

I tried using nil and got a ‘no password specified error’.

Looking at the pg\_hba.conf file I see the login I’m using allowed for  
both internet IP addresses we have, so it’s not just restricted to  
localhost. Any other ideas?
