Search code examples
ruby-on-railspostgresqlubuntu

Rails trying to connect to postgresql on port 5432, but it's configured for 5433


I am attempting to get rails running in an ubuntu subsystem on Windows 10.

I have installed everything needed, but rails is unable to access postgres.

In both /etc/postgresql/9.5/main/postgresql.conf and the rails config/database.yml, I have port: 5433 instead of 5432. See [1] below for why I'm using 5433.

When trying to do a database operation through rails (e.g. rails db:setup), I get this:

PG::ConnectionBad: 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"?

database.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
development:
  <<: *default
  database: some_database
  username: 'postgres'
  password: 'postgres'

I cannot figure out how to make rails try to start postgres on port 5433... I'm also not sure if there is a better way to solve the issue here.

Thanks for your time.

Further details:

  • [1] I am using port 5433 simply because I've been unable to figure out a way to make it use 5432. I have removed all postgres libraries and made sure to reinstall one using a specified version number, but it defaults to port 5433. When changing the port to 5432 in the config, starting it yields the error that some other process is using it, but netstat, lsof, and ps aux disagree. Not sure what else to do there.

Solution

  • For me, I believe this issue was somehow caused by something being cached by spring or some other service. After doing the following, the problem was resolved, though I'm not sure what all was required.

    • Killing all spring processes
    • restarting the machine
    • deleting and re-creating database.yml
    • changes the port from 5433 to 9854 (basically just anything else)
    • changing database user and name