Now, In machine 1 when I run psql I get the prompt password but in machine 2 I keep getting the next error :
psql: 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"?
One important thing that I didnt mention, is that I installed in machine 2 package postgresql-libs.x86_64 0:8.4.20-8.el6_9 from the postgres repository (in order to upgrade it to 9.6).
The front end and the backend have compiled-in defaults for the socket directory. If you installed them from different sources, they may have different compiled-in defaults. Which means they may not be able to rendezvous using the default settings for both of them.
You can override the default using unix_socket_directory on the server (as you discovered). On the client you can override it by using -h (or PGHOST or host= or whatever mechanism), with an argument that looks like a directory, starting with a '/'.