如何为我的POSTGRESQL数据库分配主机IP地址

时间:2018-12-14 06:58:23

标签: python-3.x postgresql-9.5

我正在尝试从python连接到PostgreSQL。

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?

我在postgresql.cof文件中更改了listen_addressess ='*'

我在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

0 个答案:

没有答案