Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Trying to set up rails environment with Postgres

This was working before. Now when I try rails s i get the error message: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (fe80::1) and accepting TCP/IP connections on port 5432?

I suspect this relates to $PATH (what is that anyway?) I have seen the question on SO, but have not found any solution that I understand how to implement. Can someone here help?

4 Answers

in the postgres.conf file I found:

------------------------------------------------------------------------------

CONNECTIONS AND AUTHENTICATION

------------------------------------------------------------------------------

- Connection Settings -

listen_addresses = 'localhost' # what IP address(es) to listen on;

                # comma-separated list of addresses;
                # defaults to 'localhost'; use '*' for all
                # (change requires restart)

port = 5432 # (change requires restart)

max_connections = 20 # (change requires restart)

Note: Increasing max_connections costs ~400 bytes of shared memory per

connection slot, plus lock space (see max_locks_per_transaction).

superuser_reserved_connections = 3 # (change requires restart)

unix_socket_directory = '' # (change requires restart)

unix_socket_group = '' # (change requires restart)

unix_socket_permissions = 0777 # begin with 0 to use octal notation

                # (change requires restart)

bonjour = off # advertise server via Bonjour

                # (change requires restart)

bonjour_name = '' # defaults to the computer name

                # (change requires restart)

I uncommented the line "port =5432 and will restart. Is there anything else I should do?

It shouldn't relate to the $PATH variable, because Rails is connecting to the database as a client, so it only needs the IP and port. Can you check your Postgres config to see what IP that Postgres is bound to?

Excuse the question, but where is that file?

in pg_hba.conf, I see:

TYPE DATABASE USER ADDRESS METHOD

"local" is for Unix domain socket connections only

local all all trust

IPv4 local connections:

host all all 127.0.0.1/32 trust

IPv6 local connections:

host all all ::1/128 trust

Allow replication connections from localhost, by a user with the

replication privilege.

local replication dariusgoore trust

host replication dariusgoore 127.0.0.1/32 trust

host replication dariusgoore ::1/128 trust

is this what I am looking for?

So that's basically saying any connection on localhost will be accepted. That means a Rails app on the same server SHOULD be able to connect. Perhaps you can also find the port you have Postgres running under? It should also be somewhere in that config.