An error occurs when Capistrano deploys the Rails app to EC2.PG::ConnectionBad:FATAL:Peer authentication failed for user "postgres"

Asked 2 years ago, Updated 2 years ago, 95 views

AW I am a beginner at AWS.Until now, I have only used Heroku.

AWS Configuration
1 EC2 instance
PostgreSQL on RDS, one

I'd like to deploy the Rails app to EC2 via Capistrano.
The following Capistrano command (deployment) results in an error:
vagrant@vagrant-ubuntu-trusty:~/sample_app$bundle exec cap production deploy

error statement
PG::ConnectionBad:FATAL:Peer authentication failed for user "postgres"
Tasks: TOP=>db:migrate
(See full trace by running task with --trace)

After SSH login to EC2,
sudo service postgresql start
sudo su-postgres
psql
postgres=#
postgres=#\du
List of roles
Role name | Attributes | Member of
-------------------------------------------------------------------------------------------------------- ec2-user | Create role, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication | {}
root | Create role, Create DB | {}

postgres=#who ami
postgres-#\q
-bash-4.2$
can be run.

EC2 database
postgres=#\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------------------------------------------------------------------------------------------------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
sample_app_development | root | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
sample_app_test | root | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0|postgres|UTF8|en_US.UTF-8|en_US.UTF-8|=c/postgres+
| | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | = c/postgres +
| | | postgres=CTc/postgres

Local (vagrant) database
vagrant@vagrant-ubuntu-trusty:~/hoge_app/config$railsdb
psql(9.5.3)
Type "help" for help.

hoge_app_development=#\l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------------------------------------------------------------------------------------------------------------------
fuga_development | vagrant | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
fuga_test | vagrant | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
hoge_app_development | vagrant | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
hoge_app_test | vagrant | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0|postgres|UTF8|en_US.UTF-8|en_US.UTF-8|=c/postgres+
| | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | = c/postgres +
| | | postgres=CTc/postgres
(7 rows)

What would you like to know
1. I understand that creating PostgreSQL with RDS creates a database, and after logging in to EC2, I can run the "sudo service postgressql start" command. Do I need to install PostgreSQL on EC2 by logging in to EC2 such as "sudo yum install-y postgreresql"?
2. Is the config/database.yml setting appropriate?

database.yml
production:
<<:*default
adapter:postgresql
host:32.873.61.427
encoding:utf8
database —Instance identifier when creating RDS
username —ec2-user
password —The password you set when you created the RDS.
pool:5
timeout —5000

Thank you for your cooperation.

ruby-on-rails aws postgresql capistrano amazon-ec2

2022-09-30 19:31

1 Answers

The perception is completely wrong.If you have created an RDS, you do not need to install PostgreSQL on EC2, nor do you need to do a service start.RDS is the image of a server dedicated to the relational database.If you have created an RDS instance and it is running, you already have an environment that uses PostgreSQL.

It's probably quite wrong. host should be the endpoint of an RDS instance such as mydb.123456789012.ap-northeast-1.rds.amazonaws.com and database should specify the database name used by the application in PostgreSQL.And username should specify a user of PostgreSQL who can access that database.ec2-user appears to be the default user of the EC2 instance.

The direct cause is that a user named base failed to authenticate when trying to connect.Since it is Peer authentication, I am still trying to connect to the local PostgreSQL (installed in EC2) instead of RDS.


2022-09-30 19:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.