I have created DB instance and gone through the config process of aws rds instance as per the documentation. created an instance of db successfully. also changed the connection params in database.yml accordingly. I ran the following commands in ngnix server installed on ubuntu 16.04 at aws and also rebooted the db instance several times.
RAILS_ENV=production rake db:create
and db created successfully and then ran
RAILS_ENV=production rake db:migrate
and database migrated successfully. an then ran the command sudo service nginx restart after all of the process when I am visiting my app its says
PG::ConnectionBad could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
here is my database.yml
development:
host: localhost
database: ups_developement_db
adapter: postgresql
encoding: unicode
port: 5432
username: postgres
password: postgres
production:
host: dbcustom.cjocvmnblsa4.us-east-2.rds.amazonaws.com
database: ups_db
adapter: postgresql
encoding: unicode
port: 5432
username: dbmasteruser
password: dbmasterPassword
I am open to provide any kind of information required. Thanks a lot for your time and solution in advance
It's almost certain that you have not configured the security groups on the RDS instance correctly.
Log into your EC2 and issue the command
telnet <rds hostname> 5432
You should see something like
Trying 10.1.1.2...
Connected to 10.1.1.2.
Escape character is '^]'.
which means that TCP can flow between your EC2 and your RDS.
If not, you need to permit your EC2 to connect to your RDS instance by adding the correct security group configuration.
You should create Environment variables in your AWS RDS instance you should use them in your rails app config file. Check here
database.yml should look like this
production:
adapter: mysql2
encoding: utf8
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.