author avatar

satya

Fri Sep 22 2023

while connecting rails local server with the client , if you get this error as mentioned below

could not connect to server: Operation timed out
	Is the server running on host "10.220.0.15" and accepting
	TCP/IP connections on port 5432? 

this means your postgres server is not connected to the host at address 10.220.0.15 . In order to see if it is connected or not we need to check the pg_hba.conf file. So that file must be present inside your postgresql directory . In order to get the path we can do ps aux | grep postgres it will look like this

...
user 46455   0.0  0.0 409138608   1248   ??  Ss   13Sep23   0:00.82 postgres: checkpointer
user 46372   0.0  0.0 408998640   2192   ??  S    13Sep23   0:16.79 /opt/homebrew/opt/postgresql@13/bin/postgres -D /opt/homebrew/var/postgresql@13

So from here we need the path that is present after the -D flag. So in my case it my path is /opt/homebrew/var/postgresql@13 Now we can cd into the path. Once we do that we need to do ls and we can find the file called pg_hba.conf . Then we need to run nano pg_hba.conf it will open the file and if you see that there is no host present , we need to write the following lines and press Ctrl + O then click Enter and Ctrl +X

host  YOUR_DB_NAME  YOUR_USER_NAME  10.220.0.15/32  md5

then start your postgres server for the desired database and you will successfully connect local rails server with your client.