I am trying to connect to a Postgres server using Python.
import psycopg2
conn = psycopg2.connect(
host="ec2-blablabla.compute-1.amazonaws.com",
database="postgres",
user="myuser",
password="mypassword",
port = 5432,
sslmode ='prefer',
sslcompression = 0
)
cur = conn.cursor()
I get the following error:
OperationalError: SSL SYSCALL error: Connection reset by peer
FATAL: no pg_hba.conf entry for host "207.100.100.100", user "myuser", database "postgres", SSL off
I am able to connect to this server from my IP using pgadmin and same ssl settings as I set in Python code. What could be the issue here?
no pg_hba.conf entry for host
I cannot modify pg_hba.conf so if there is any other way, please let me know!!
Related
I'm getting the followign error when trying to connect to postgres database from a vm:
psycopg2.OperationalError: FATAL: password authentication failed for user "user1"
FATAL: password authentication failed for user "user1"
I've created the user
CREATE USER user1 WITH PASSWORD 'pass1';
and added the following to my pg_hba.conf file
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all 0.0.0.0/0 md5
local all postgres md5
but when using pscopg2.connect() and specifying the dbname, user, password, port and host, I'm still getting the same error
for reference, when trying to connect to the server using psql on the vm I get the following error:
psql --host=localhost --port=5432 --username=user1 --dbname=postgres
Password for user user1:
psql: FATAL: password authentication failed for user "user1"
FATAL: password authentication failed for user "user1"
please let me know if more info is needed!
I have bought a VPS for my website. I have built a small project with vue and node.
In this I used postgresql that is working fine on localhost.
I want to change my database from localhost to the server database where I have installed postgres and made a database and table.
My db.js file looks like this:
const Pool = require('pg').Pool;
const pool = new Pool({
user: "postgres",
password: "root",
database: "todo_database",
host:"45.111.241.15",
port: 5432
});
module.exports = pool;
Then I tried to send form data from the localhost vue page and it gave the following error:
error connecting db Error: connect ECONNREFUSED 45.111.241.15:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '45.111.241.15',
port: 5432
I do not have much knowledge about this and how to solve this.
Can you please guide me what should I do to connect with my server db?
I follow these steps and it worked:
edit your /etc/postgresql/9.1/main/postgresql.conf and change
Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
In /etc/postgresql/10/main/pg_hba.conf
IPv4 local connections:
host all all 0.0.0.0/0 md5
Now restart your DBMS
sudo service postgresql restart
Now you can connect with
psql -h hostname(IP) -p 5432 -U postgres
I'm trying to connect to postgres docker container via psycopg2, but i keep getting the same error.
I'm doing this on jupyter (docker container), i restart several times postgres container and i change postgresql.config listen_addresses = '*' to listen_addresses = 'localhost' and it's the same error.
This is the docker run command:
docker run --name postgres -e POSTGRES_PASSWORD=xxxxxxx -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
python
import psycopg2 as pg
connection = pg.connect("host=localhost dbname=easy_cleaning user=root")
I expect to connect, but i got this error:
----> 3 connection = pg.connect("host=localhost dbname=easy_cleaning user=root")
/opt/conda/lib/python3.7/site-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
124
125 dsn = _ext.make_dsn(dsn, **kwargs)
--> 126 conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
127 if cursor_factory is not None:
128 conn.cursor_factory = cursor_factory
OperationalError: 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?
could not connect to server: Cannot assign requested address
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
On your configuration, your container is not on localhost, Docker created a private IP to it. So you need to run:
docker inspect postgres
And look for IPAddress field to use in your connection as:
connection = pg.connect("host=<DOCKER_IP_ADDRESS> dbname=easy_cleaning user=root")
OR
You can use docker-compose to run your images as services and each service has it's name, which can be used as a hostname in your connections, like:
connection = pg.connect("host=postgres dbname=easy_cleaning user=root")
Read more here
I am unable to connect to my SQL Server 2014 from node server.
I get this error:
Failed to connect to 192.168.1.3,2207:2207:1433 - getaddrinfo ENOTFOUND 192.168.1.3,2207:2207'
TCP port also enabled but same issue
By using knex i resolve this problem
connection: {
server : 'IP Address',
user : 'sa',
password : '******',
database : '*****',
options: {
port: 14831
}
}
I can able to connect postgres from terminal as well as python manage.py dbshell command
But when i'm trying to connect from apache i'm Getting error as follows.
Error : OperationalError: could not connect to server: Permission denied
Is the server running on host "192.168.1.10" and accepting
TCP/IP connections on port 5432?
My listen Address on postgress conf file is 192.168.1.10 Address
pg_hg_cong allowed host all all 192.168.0.0/24 trust
And also selinux turned httpd_can_network_connect_db on
Port is listening on 192.168.1.10:5432 on netstat output.
And database's are storing in /tmp directory
wxrwxrwx. 1 postgres postgres 0 Dec 18 07:40 .s.PGSQL.5432
-rw-------. 1 postgres postgres 50 Dec 18 07:40 .s.PGSQL.5432.lock
Actually I have enabled selinux httpd_can_network_connect_db parameters on db server instead of web server
So issue got solved after enabling httpd_can_network_connect_db on web server