# Postgres - how to connect?

**URL:** <https://www.ruby-forum.com/t/postgres-how-to-connect/120972>\
**Category:** Rails\
**Created:** [November 22, 2007, 10:05am UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972 "2007-11-22T10:05:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 10:05am UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/1 "2007-11-22T10:05:22Z")

</div>

I am trying to connect to postgres database from RoR. I have username  
and password in database.yml, but when trying to connect, I get the  
following error:

No such file or directory - /tmp/.s.PGSQL.5432

Why is it? I would also prefer to connect by TCP connection instead of  
UNIX socket, how can I configure this?

Thanks in advance  
PaweÅ‚ Stawicki

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 12:28pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/2 "2007-11-22T12:28:42Z")

</div>

On 22 Nov., 10:05, Pawel S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am trying to connect to postgres database from RoR. I have username  
> and password in database.yml, but when trying to connect, I get the  
> following error:
> 
> No such file or directory - /tmp/.s.PGSQL.5432
> 
> Why is it? I would also prefer to connect by TCP connection instead of  
> UNIX socket, how can I configure this?

I remember having the same problem, but I don’t remember  
the details anymore. Anyway, here’s my current database.yml:

production:  
adapter: postgresql  
database: foo\_production  
username: postgres  
password: secret  
host: localhost  
encoding: UTF8

Similar for test and development, _no_ other settings.  
(Especially, I think there was a “port” setting that needed to  
be removed.)

HTH,  
Stefan

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 3:25pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/3 "2007-11-22T15:25:42Z")

</div>

Pawel S. wrote:

> I am trying to connect to postgres database from RoR. I have username  
> and password in database.yml, but when trying to connect, I get the  
> following error:
> 
> No such file or directory - /tmp/.s.PGSQL.5432
> 
> Why is it? I would also prefer to connect by TCP connection instead of  
> UNIX socket, how can I configure this?

Check under ‘connections and authentication’ in data/postgresql.conf to  
see if you’re listening on the connect ip-adresses (or listening on ip  
at all).  
You might also need to adapt data/pg\_hba.conf to enable local access  
with the account you’re using.

My database.yml looks like the one Stefan L. posted.

Piet.

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 3:42pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/4 "2007-11-22T15:42:37Z")

</div>

> Check under ‘connections and authentication’ in data/postgresql.conf to  
> see if you’re listening on the connect ip-adresses (or listening on ip  
> at all).

I am. I can connect by phpphadmin (web php tool) with user and password  
without problems. But it seems to me that ruby tries to connect by  
socket, not by TCP/IP, and I don’t like this.

Regards  
Pawel S.

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 10:53pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/5 "2007-11-22T22:53:53Z")

</div>

Ok, it worked, but now I got next error. I have table “Article”, and I  
created model Article, but when I try to run test (just to test  
connection), I get “Exception: RuntimeError: ERROR C42P01 Mrelation  
“article” does not exist Fnamespace.c L221 RRangeVarGetRelid: DELETE  
FROM article”

My table has name beginning with capital letter, but I think I doesn’t  
matter, because when I had changed it, I still was getting the error.

Regards  
PaweÅ‚ Stawicki

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [November 22, 2007, 3:44pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/6 "2007-11-22T15:44:14Z")

</div>

Sorry, didn’t notice the first answer. I will try removing “port”.

Regards  
PaweÅ‚ Stawicki

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [April 7, 2009, 3:59pm UTC](https://www.ruby-forum.com/t/postgres-how-to-connect/120972/7 "2009-04-07T15:59:34Z")

</div>

Pawel S. wrote:

> My table has name beginning with capital letter, but I think I doesn’t  
> matter, because when I had changed it, I still was getting the error.

I know the parent post is from a long time ago, but it turns out that  
this is a bug in the rails postgresql adapter – it doesn’t support  
table names with capital letters. There’s a ticket and patch here:

> **[\#2418 PostgreSQL schema dumper does not support capitalized table names -...](https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2418)**

If anyone could verify this patch, it would be much appreciated.

Thanks,  
Scott
