fatal error : ssl closed pg_hba.conf site, database tool can connect to postgre but in code throw exception - postgresql

I use flink cdc 2.0.0 to connect to postgresql in vmware.
I can connect to mysql in VM and do the SELECT in my code. But I can't do the same to postgres. And it throw an exception 'FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error'
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:197)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:217)
at org.postgresql.Driver.makeConnection(Driver.java:458)
at org.postgresql.Driver.connect(Driver.java:260)
at io.debezium.jdbc.JdbcConnection.lambda$patternBasedFactory$1(JdbcConnection.java:231)
at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:872)
at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:867)
at io.debezium.connector.postgresql.TypeRegistry.<init>(TypeRegistry.java:122)
... 8 more
Suppressed: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "192.168.42.1", user "postgres", database "mydb", SSL off error
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:525)
at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:146)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:206)
... 16 more
I have modified the settings in pg_hba.conf and postgresql.conf:
host all all all trust # at the bottom of the file
listen_addresses = '*'
And it's weird that there's no problem using the database tool DBeaver, this can create and select...
Here's my code:
DebeziumSourceFunction<String> source = PostgreSQLSource.<String>builder()
.hostname("192.168.42.130")
.port(5432)
.username("postgres")
.password("123456")
.database("mydb")
.schemaList("public")
.tableList("big_data_public.public.user")
.deserializer(new StringDebeziumDeserializationSchema())
.build();
The ip '192.168.42.130' is the ip of my VM.
The ip '192.168.42.1' is the ip of VMware Network Adapter VMnet8.(I don't understand why the code throw an exception with this IP)

Related

FATAL: password authentication failed for user "postgres" (macOS, postgresql 15.1, pgAdmin 4)

After installing PSQL 15.1 (https://www.postgresql.org/download/), I try to connect to the server, enter the password that I set during installation. But I am getting this error [connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "postgres"]
enter image description here
Any idea how can I fix this? Thanks!

Unable to connect to postgres database running in a docker container using psycopg2

I am running a postgres database inside a docker container on a Windows 10 machine using Docker desktop. I would like to run postgresql queries on the database using psycopg2 but I am unable to establish connection to the database. I used the following command to run the database
docker run --name thedatabase -p 5432:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_HOST_AUTH_METHOD=md5 postgres:13.5
I used docker inspect to get the IP address for the database. I used the following code to establish a connection with the database using psycopg2.
import psycopg2
from psycopg2 import OperationalError
def create_connection(db_name, db_user, db_password, db_host, db_port):
connection = None
try:
connection = psycopg2.connect(
database=db_name,
user=db_user,
password=db_password,
host=db_host,
port=db_port,
)
print("Connection to PostgreSQL DB successful")
except OperationalError as e:
print(f"The error '{e}' occurred")
return connection
if __name__=="__main__":
connection = create_connection(
"thedatabase", "postgres", "postgres", "172.17.0.2", "5432"
)
I am getting the following error
The error connection to server at 172.17.0.2, port 5432 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?
occurred
Any help would be appreciated. Thanks.
Try to replace docker ip by localhost if your python script is not executed in docker.
if __name__=="__main__":
connection = create_connection(
"thedatabase", "postgres", "postgres", "localhost", "5432"
)

heroku postgresql could not connect to server: Connection timed out

I'm trying to connect to postgres database in heroku using heroku pg:psql postgresql-rigid-33416 --app murmuring-ocean-62645, however I got this message
--> Connecting to postgresql-rigid-33416
psql: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "ec2-50-17-225-140.compute-1.amazonaws.com" (50.17.225.140) and accepting
TCP/IP connections on port 5432?
I have tried to turn off my firewall but the problem persists. Any idea how to solve this?
EDIT:
heroku version
heroku/7.16.0 win32-x64 node-v10.10.0
heroku pg:info
=== DATABASE_URL
Plan: Hobby-dev
Status: Available
Connections: 0/20
PG Version: 10.5
Created: 2018-10-09 14:03 UTC
Data Size: 7.6 MB
Tables: 0
Rows: 0/10000 (In compliance)
Fork/Follow: Unsupported
Rollback: Unsupported
Continuous Protection: Off
Add-on: postgresql-rigid-33416
In case someone else has this issue. I had same problem. I had to lower my network security by changing my Firewall Level on my local compter to 'Low' and it works.

eclipse luna and postgres db 9.4 connection

I am trying to connect postgres in eclipse. But I am getting below error after entering all details for jdbc connection:
Database:postgres
url:jdbc:postgresql://localhost:5432/postgres
user name:postgres
pass :postgres
jar file:D:\Workspace: postgresql-9.4-1202.jdbc41
Ping failed:
org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:427)
at

Zend framework - connection to postgresql

I encountered troubles when trying to connect to postgresql database within Zend framework application. In my application.ini I use
resources.db.adapter = PDO_PGSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = testtest
resources.db.params.dbname = testdb
But when I run the application, I got an error message
Message: SQLSTATE[08006] [7] could not create socket: Address family not supported by protocol.
Could you please tell me what can be wrong?
Zend version 1.12.3., PostgreSQL version 9.0.7, PHP version 5.3.5.
Thanks, Marek .
localhost on your machine is (most likely) resolving to the IPv6 address of localhost (::1), but since the protocol/module used does not support IPv6 connections, your connection fails.
You could either;
Use 127.0.0.1 as a host instead, that will force a connection to the IPv4 localhost.
Remove the host line completely, that will force a connection via UNIX sockets.
I had similar problem:
PDOException: SQLSTATE[08006] [7] 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? in
lock_may_be_available() (line of /app/ctr/ctr
web/drupal/includes/lock.inc).
The problem was caused because of a full disk. and PostgreSQL DB blocked/froze.
Making some free space and restarting of PostgreSQL DB resolved my problem.