Phoenix fails to connect to Heroku's PostgreSQL server - postgresql

This is the error I'm seeing on a virginal Phoenix app I've set up to mess around:
[error] Postgrex.Protocol (#PID<0.362.0>) failed to connect: **
(Postgrex.Error) FATAL 28000 (invalid_authorization_specification): no
pg_hba.conf entry for host "24.25.201.68", user "koilqmnaakvfjg",
database "dc245o0vlbprf7", SSL off
Here is my config/dev.exs:
# Configure your database
config :hello, Hello.Repo,
adapter: Ecto.Adapters.Postgres,
username: "koilqmnaakvfjg",
password: "somepass",
database: "dc245o0vlbprf7",
hostname: "ec2-54-243-54-6.compute-1.amazonaws.com",
pool_size: 10
Something simple I'm missing?
Edit:
My pg_hba.conf file looks like this:
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust

You need to set the ssl parameter to true, and if the issue persists modify the pg_hba.conf file.
Solution:
# Configure your database
config :hello, Hello.Repo,
adapter: Ecto.Adapters.Postgres,
username: "koilqmnaakvfjg",
password: "somepass",
database: "dc245o0vlbprf7",
hostname: "ec2-54-243-54-6.compute-1.amazonaws.com",
pool_size: 10,
ssl: true
Hope it helps :D
Update me on how it goes;
Good Luck;

Related

FATAL: no pg_hba.conf entry for host "****", user "xyz", database "***", SSL off

I am trying to connect to postgresql but keep getting this error "FATAL: no pg_hba.conf entry for host "****", user "xyz", database "***", SSL off". I tried adding the host all all 0.0.0.0/0 md5 in pg_hba file and restarting the service. But it didn't help. I tried checking the port and opening it. But still facing the same issue.
Below is my config.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 0.0.0.0/0 md5
host all all 10.52.16.6/0 trust
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all 0.0.0.0/0 md5
host all all 10.52.16.6/0 trust
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
host all all 0.0.0.0/0 md5
host all all 10.52.16.6/0 trust
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
Any help would be appriciated.
SHOW hba_file;
run the command in psql, makesure you are editing the correct conf file

what do I have to change in my pg_hba.conf to get rid of peer authentication error?

I have postgres running on a raspberry pi, and I was getting the old
psycopg2.OperationalError: FATAL: Peer authentication failed for user "george"
The user george is a user I made that can create and access databases, but can't create users. What do I have to change in my pg_hba.conf file so that george can connect to a dabatabse using a password. This is what my file looks like:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
This is what my connection line looks like in my python test program:
conn = psycopg2.connect(database="homebot", user="george", password="xxxxxx", port=5432)
This is what I do on the commandline to get into psql
psql george -h 127.0.0.1 -d homebase
Which works, so....what do I have to change / do to get that connection line to not throw an error and connect?
Add a new line to the configuration file setting the authentication method for george to md5.
local all george md5

Correct setings for pg_hba.conf

Having difficulty getting Mezzanine to connect to Postgresql via Docker
In my postgresql.conf I have:
listen_addresses = '*'
In my pg_hba.conf I have:
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
host all all samenet trust
host all all 0.0.0.0/0 md5
The error I keep getting is:
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
I have PORT in settings.py set to '' but I have PORT defined in postgresql.conf to 5432.
Any suggestions?
Ensure that port mapping is properly configured https://docs.docker.com/userguide/dockerlinks/
If your app is running in one container and postgresql server is running in another container, you need to link containers together.
By the way you are trying to establish connection via localhost and you have md5 authentication method there. For debug purposes change authentication method to trust. You should EDIT this line in your pg_hba.conf NOT to ADD another line.
host all all 127.0.0.1/32 md5
The best way to debug connection issues is to use psql utility.

Impossible to connect to Postgresql using RubyMine

I've been trying to connect to PostgreSQL using RubyMine but it's always asking for a password.
In a terminal I do connect using:
psql -U postgres
I don't have to input a password.
But, when I tried using RubyMine to connect to PostgreSQL is always asking for a password. I tried input some passwords but they don't work. Any idea?
My settings file:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see rails configuration guide
# http://guides.rubyonrails.org/configuring.html#database-pooling
pool: 5
development:
<<: *default
database: portafolio_development
username: postgres
password:
test:
<<: *default
database: portafolio_test
username: postgres
password:
production:
<<: *default
database: portafolio_production
username: portafolio
password: <%= ENV['PORTAFOLIO_DATABASE_PASSWORD'] %>
Edited
My pg_hba.conf:
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Solved
Result that I have two pg_hba.conf files. One for version 9.3 and another for 9.4. I changed the first one to the following and everything is working now:
local all postgres trust
# The same using local loopback TCP/IP connections.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
# The same as the previous line, but using a separate netmask column
#
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
host all all 127.0.0.1 255.255.255.255 trust
# The same over IPv6.
#
# TYPE DATABASE USER ADDRESS METHOD
host all all ::1/128 trust
# The same using a host name (would typically cover both IPv4 and IPv6).
#
# TYPE DATABASE USER ADDRESS METHOD
host all all localhost trust

Postgresql and host

I'm trying to deploy my Rails application through Capistrano 3.
On my own server everything was working but with my new one, I have some problem to access to the database :
DEBUG [05c115bf] FATAL: no pg_hba.conf entry for host "ip.address.of.the.server", user "postgres", database "my_database", SSL on
DEBUG [05c115bf] FATAL: no pg_hba.conf entry for host "ip.address.of.the.server", user "postgres", database "my_database", SSL off
I know that the problem comes form pg_hba but I cannot find where exactly.
This is what I've tried :
# Database administrative login by Unix domain socket
local all postgres md5
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
hostssl all all ip.address.of.the.server/24 md5
hostnossl all all ip.address.of.the.server/24 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
Currently I'm blocked at this point.
put real IP address of the server with which you want to connect instead if ip.address.of.the.server for more info visit pg_hba.conf
The problem came from my deploy.rb where I made a mistake on the host... Simply.
After hours of researches, this problem is finally fixed. Thank you for your help.