Я пытаюсь подключиться к PostgreSQL из python.
import psycopg2
import csv
import json
conn = psycopg2.connect(database="testdb", user = "postgres", password = "postgres",host = "131.80.12.196", port = "5432")
cur = conn.cursor()
cur.execute("SELECT * FROM test;")
data = cur.fetchall()
Ошибка:
Traceback (most recent call last):
File "ex.py", line 4, in <module>
conn = psycopg2.connect(database="newrelic", user = "postgres", password = "postgres",host = "131.80.12.196", port = "5432")
File "/usr/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "131.80.12.196" and accepting
TCP/IP connections on port 5432?
Я изменил listen_addressess ='*'
в своем файле postgresql.cof
Я добавил следующие строки в pg_hba.conf
host all all 0.0.0.0/0 md5
host all all ::/0 md5
Здесь я указываю значение netstat
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN