Forum: Ruby on Rails rails with postgresql

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5b2b0852d464f20072e6c1961784a6c8?d=identicon&s=25 Rajinder Yadav (Guest)
on 2010-12-07 22:51
(Received via mailing list)
Hi this is my first time for a few things. I am trying to get rails
working with postgres-9.0.1, I have never used postgres before. I do
know the server is listening on localhost:5432 as I am able to connect
to it using pgadmin3 and see the 2 databases on it.

I have 'pg' gem installed
my database.yml looks like this

development:
  adapter: postgresql
  encoding: unicode
  database: test
  pool: 5
  username:
  password:

however i am getting the following migrate error

yadav@expression:$ rake db:migrate --trace
(in /home/yadav/dev/rails/tmp/testapp)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.
5432"?

--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1
2505b282d57c29be797dc35b245adb4c?d=identicon&s=25 Philip Hallstrom (Guest)
on 2010-12-07 23:00
(Received via mailing list)
On Dec 7, 2010, at 1:49 PM, Rajinder Yadav wrote:

>  encoding: unicode
> ** Invoke environment (first_time)
> ** Execute environment
> ** Execute db:migrate
> rake aborted!
> could not connect to server: No such file or directory
>        Is the server running locally and accepting
>        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.
> 5432"?

Is the server running locally and accepting connections on that unix
domain socket?  You don't say that it is...

Or if you don't want to tweak that, change your database.yml and add a
"host: localhost" entry.

-philip
6799ecb7745167d2590d85c4ed25d985?d=identicon&s=25 David Kahn (dkahn)
on 2010-12-07 23:01
(Received via mailing list)
On Tue, Dec 7, 2010 at 3:49 PM, Rajinder Yadav <devguy.ca@gmail.com>
wrote:

>  encoding: unicode
> ** Invoke environment (first_time)
> ** Execute environment
> ** Execute db:migrate
> rake aborted!
> could not connect to server: No such file or directory
>        Is the server running locally and accepting
>        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.
> 5432"?
>

It might help if you can post your database.yml.... also, have you
created
your databases (rake db:create:all)?
5b2b0852d464f20072e6c1961784a6c8?d=identicon&s=25 Rajinder Yadav (Guest)
on 2010-12-07 23:23
(Received via mailing list)
On Tue, Dec 7, 2010 at 4:59 PM, Philip Hallstrom <philip@pjkh.com>
wrote:
>> my database.yml looks like this
>>
>> 5432"?
>
> Is the server running locally and accepting connections on that unix domain
socket? You don't say that it is...
>
> Or if you don't want to tweak that, change your database.yml and add a "host:
localhost" entry.
>
> -philip
>
> --

Hi Philip,

that was it, not sure (yet) how to setup the server to listen on the
unix domain socket, but adding the host entry made the connection
possible.

I can now add and view records interactively from the rails console!

Thanks,

--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1
5b2b0852d464f20072e6c1961784a6c8?d=identicon&s=25 Rajinder Yadav (Guest)
on 2010-12-07 23:26
(Received via mailing list)
On Tue, Dec 7, 2010 at 4:59 PM, David Kahn <dk@structuralartistry.com>
wrote:
>> my database.yml looks like this
>>
>> 5432"?
>
> It might help if you can post your database.yml.... also, have you created
> your databases (rake db:create:all)?
>

Hi David,

thanks for the tip, I got it working, just had to add "host:
localhost" as Philip pointed out.

Kind Regards,
Rajinder Yadav
6799ecb7745167d2590d85c4ed25d985?d=identicon&s=25 David Kahn (dkahn)
on 2010-12-07 23:32
(Received via mailing list)
On Tue, Dec 7, 2010 at 4:25 PM, Rajinder Yadav <devguy.ca@gmail.com>
wrote:

> >> to it using pgadmin3 and see the 2 databases on it.
> >>  password:
> >> could not connect to server: No such file or directory
>
> thanks for the tip, I got it working, just had to add "host:
> localhost" as Philip pointed out.
>

Cool... hey if you have a chance let me know if you can connect to the
db
using: "rails dbconsole".... I have never been successful doing this and
I
just go to the postgresql command line but would be curious if it works
for
you.... I can connect no problem to the rails console, but for whatever
reason I get "Couldn't find database client: psql. Check your $PATH and
try
again." when I try rails dbconsole.
5b2b0852d464f20072e6c1961784a6c8?d=identicon&s=25 Rajinder Yadav (Guest)
on 2010-12-08 02:18
(Received via mailing list)
On 10-12-07 05:31 PM, David Kahn wrote:
>     <http://devguy.ca>@gmail.com <http://gmail.com>> wrote:
>      >> development:
>      >> (in /home/yadav/dev/rails/tmp/testapp)
>      >
>
> Cool... hey if you have a chance let me know if you can connect to the
> db using: "rails dbconsole".... I have never been successful doing this
> and I just go to the postgresql command line but would be curious if it
> works for you.... I can connect no problem to the rails console, but for
> whatever reason I get "Couldn't find database client: psql. Check your
> $PATH and try again." when I try rails dbconsole.

Hi David,

'rails dbconsole' works for me. Are you on Linux? if so what do you get
when you do a 'which psql', do you get the right path?

I built postgresql-9.0.1 from source, and the make install script puts
psql under /usr/local/pgsql/bin/psql

What I ended up doing instead of adding to the $PATH, was creating a
symbolic link under /usr/local/bin

lrwxrwxrwx 1 root root       25 2010-12-07 19:50 psql ->
/usr/local/pgsql/bin/psql

I am guessing, either you need to update your $PATH variable or use a
sym-link like me and things should work fine.


--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1
6799ecb7745167d2590d85c4ed25d985?d=identicon&s=25 David Kahn (dkahn)
on 2010-12-08 02:47
(Received via mailing list)
On Tue, Dec 7, 2010 at 7:17 PM, Rajinder Yadav <devguy.ca@gmail.com>
wrote:

>>     >
>>     >> I have 'pg' gem installed
>>     >> however i am getting the following migrate error
>>     >>        connections on Unix domain socket
>>    thanks for the tip, I got it working, just had to add "host:
>
> Hi David,
>
> 'rails dbconsole' works for me. Are you on Linux? if so what do you get
> when you do a 'which psql', do you get the right path?
>

Well, I am on a Mac, and interesting, when I ask for 'which psql' it
does
not return anything. And if I type psql into the terminal I get "command
not
found". So must be that I need to assign the path.... I have just been
lazy.
I just rebuilt my computer so I'll have a look at doing this.
98b3b41b2fa030c78579d8e693acf447?d=identicon&s=25 Mauro Cicio (maurocicio)
on 2011-02-01 09:01
:migrate
> rake aborted!
> could not connect to server: No such file or directory
>         Is the server running locally and accepting
>         connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.
> 5432"?

It is looking for the domain socket in
/var/run/postgresql/.s.PGSQL.5432.

Go in /var/run/postgresql/ and
ln -s wherever/your/domain/socket/is/.s.PGSQL.5432 .

You can find the socket with a global search, like

find / -name .s.PGSQL.\*

The above will fix the issue, but a more definitive solution would be to
point rails to the right location of the domain socket (I am just
looking how to do it myself!)
2c4f9f1047510374882567fd796c8ebc?d=identicon&s=25 Padmahasa B N (padmahas)
on 2016-04-03 06:38
Philip Hallstrom wrote in post #967046:
> On Dec 7, 2010, at 1:49 PM, Rajinder Yadav wrote:
>
>>  encoding: unicode
>> ** Invoke environment (first_time)
>> ** Execute environment
>> ** Execute db:migrate
>> rake aborted!
>> could not connect to server: No such file or directory
>>        Is the server running locally and accepting
>>        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.
>> 5432"?
>
> Is the server running locally and accepting connections on that unix
> domain socket?  You don't say that it is...
>
> Or if you don't want to tweak that, change your database.yml and add a
> "host: localhost" entry.
>
> -philip

Hey Phillip Hallstrom, How "host: localhost" resolves the problem. Of
course it resolved my problem without any new configuration. Please tell
me how does it worked.
0adf360e3807fd610c681e18232c44a2?d=identicon&s=25 Mike S. (mike_s97)
on 2016-04-10 12:54
(Received via mailing list)
By default PostgreSQL listens on a local domain socket for security
reasons, however, by adding the host: localhost line you are telling the
PostgreSQL driver that you want to use TCP networking, and so it
switches to TCP/IP connections on port 5432.

The fact that use use localhost to connect to the local machine is
irrelevant you can put any IP address there to connect to a PostgreSQL
instance anywhere on the Internet
This topic is locked and can not be replied to.