The user abdellani is trying to set up Discourse with Postgres running in a Docker container. Despite having access to the Postgres database using psql, they are unable to create the database using rake or rails.
abdellani has tried updating the discourse.conf file and setting environment variables, but still encounters the error connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory.
phil22 suggests that the issue might be due to the Postgres container not being exposed correctly, but this is not the case as abdellani has exposed the port.
Falco points out that Discourse is trying to connect to Postgres via a filesystem socket, which does not exist. Adding a port: 5432 to the database.yml file does not work, but adding a url key with the Postgres connection details does resolve the issue.
Falco explains that the issue is due to the default socket taking priority over the port declaration, and that using the url key is one way to get around this.
I’m trying to set up discourse in my local development environment with only a small difference: I’m running Postgres in docker.
The database is accessible using psql from the OS, but when I tried to create the database using rake or rails, it doesn’t work. I followed these steps:
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Couldn't create 'discourse_development' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Tasks: TOP => db:create
(See full trace by running task with --trace)
I’m not certain, but I think the problem is probably that discourse is running inside a docker container, and so can’t by default access your separate postgres container.
Discourse is not running inside a docker container, it’s running in my OS. Postgres is running inside a container, and I exposed its port to the OS -p 5432:5432.
connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Couldn't create 'discourse_development' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Tasks: TOP => db:create
(See full trace by running task with --trace)
No it just means the the default socket takes priority of the port declaration. One way to get around that is using the url key, but you can check Rails code to see other ways.