How to connect to "/var/run/postgresql/.s.PGSQL.5432"

Hello,

I managed to get a postgres docker image to run and be available as specified:

$ docker run --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD="1234" --name pg postgis/postgis
...
...
...
2022-04-11 04:26:39.722 UTC [1] LOG:  starting PostgreSQL 13.5 (Debian 13.5-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-04-11 04:26:39.723 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2022-04-11 04:26:39.723 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2022-04-11 04:26:39.726 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

How can I connect to this via the database.yml file?

This is the result I get now with the config that worked with a postgres server installed via Homebrew:

> rails db:create
connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory

I’d really like to learn how to change database.yml for the postgres access change.

I am a noob. Any vocabulary suggestions are welcome too!

netstat info with and without names:

$ netstat -at -p TCP | grep LISTEN
tcp46      0      0  *.60266                *.*                    LISTEN     
tcp4       0      0  *.60265                *.*                    LISTEN     
tcp4       0      0  localhost.postgresql   *.*                    LISTEN     
tcp46      0      0  *.http                 *.*                    LISTEN
...
...


$ netstat -ant -p TCP | grep LISTEN
tcp46      0      0  *.60266                *.*                    LISTEN     
tcp4       0      0  *.60265                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.5432         *.*                    LISTEN     
tcp46      0      0  *.80                   *.*                    LISTEN
...
...

Thanks!

You need to convince postgres to listen on all IPs. This is done in postgreql.conf – listen_addresses = '*', but may also need to be set in Docker – not familiar with docker. Then, you’ll need to put the IP of your docker instance into config/database.yml and you will be good as gold. If you have further issues, feel free to reach out.

Thanks for the help! And yes, if there is a way to DM me then I’d be happy to get future assistance.

So far I see this in postgresql.conf:

...
...
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

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

It looks to be listening on all addresses.

You set me on the right path with your complete thoughts. :slight_smile:

after some further googling and copypasta I added some semblance of this to database.yml:

  host: <%= ENV['POSTGRES_IP'] %>
  user: <%= ENV['APP_USER_POSTGRES_USER'] %>
  password: <%= ENV['APP_USER_POSTGRES_PASSWORD'] %>

added the related exported bash vars, ran rails db:create and wow. just wow.

Thanks so much!

Def DM me if you have the bandwidth for paid help.

Cheers!

I do, indeed – hasan-dot-diwan-at-gmail-dot-com. – H