I have been struggling with this issue since last few days.
I find this stackoverflow post almost similar with no solution.
I have recently deployed my rails 6 app on elasticbean stalk (Amazon Linux 2). On deployment migrations are running successfully and I can see table/columns are created. I can connect to db from local and from ec2 instance as well using below command.
psql -U username -p 5432 -h examplehost.rds.amazonaws.com -d ebdb
However, when I run bundle exec rails console
or bundle exec rails db:migrate
after ssh, I keep getting:
activeRecord::ConnectionNotEstablished: 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"?
I have already added following env variables:
Also in my database.yml file I have the rds configured variables listed as such.
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
I also tried creating a new environment variable on the elastic beanstalk console.
ENV['DATABASE_URL'] = postgres://YourUserName:YourPassword@YourHostname:5432/YourDatabaseName
I made the necessary configurations, uploaded my .zip file and the connection to the database failed.
I can see all my ENV variables are set properly by this command:
sudo /opt/elasticbeanstalk/bin/get-config environment
I am really at my wits end, I've spent too much time trying to diagnose this and am running out of ideas. I don't know where to look too next for ideas on how to trouble shoot this. I've read so many stack overflow questions and blogs that my head is spinning. If anyone has any ideas on how to resolve this, I would greatly appreciate it.