2

I have changed the port of my PostgreSQL server, hence the socket it creates is no longer named ".s.PGSQL.5432".

Is there a way to update/force Rails/the pg gem to change the socket name it looks for? I have tried uninstalling/reinstalling the pg gem in line with recommendations but it still tries to look for a socket named .s.PGSQL.5432, not the .s.PGSQL.50000 that it should and as per the database.yml comments, the 'socket' config line does not apply for PostgreSQL.

  • I can obviously create a symlink, but I was hoping there was a more elegant way around this.
1
  • what's the port in database.yml? Commented Mar 8, 2013 at 17:20

1 Answer 1

2

Change the port in your database.yml

PostgreSQL supports two kinds of connections as you are aware: tcp/ip and unix domain sockets. Both can use host and port but use them in different ways.

When working with TCP/IP, host and port have the standard meanings with regard to networs running TCP/IP.

When working with Unix domain sockets, host provides the directory, and port provides the numeric portion of the socket name. Paths should be absolute. The same should hold true for any libpq-based connection (including through the pg gem), so consider this:

 psql -h /tmp -p 5000 

This gives an error message of:

$ psql -h /tmp -p 5000 
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5000"?

Similarly:

$ psql -h /foo -p 50000 
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/foo/.s.PGSQL.50000"?
Sign up to request clarification or add additional context in comments.

1 Comment

host provides the directory, and port provides the numeric portion of the socket name At least I can confirm that about the host part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.