我正试图在Ubuntu上设置一个远程访问数据的PostgreSQL 9.1服务器。我已经正确安装了PostgreSQL,服务器进程正在运行,并且我正在尝试配置它,以便我可以从我的局域网外的几台计算机上通过互联网远程访问该服务器。
我已经修改了我的pg_hba.conf文件:
host all all 0.0.0.0 trust
并使用以下postgresql.conf:
listen_addresses = '*'
port = 5432
我额外修改了我的iptables以接受5432端口的连接。
当我尝试使用Python中的psycopg2进行连接时:
conn=psycopg2.connect('host=XX.XX.XX.XX port=5432 dbname=postgres user=myUser password=mypassword')
我收到了以下错误信息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: Connection refused
Is the server running on host "XX.XX.XX.XX" and accepting
TCP/IP connections on port 5432?
我不确定是否插入了正确的IP地址,我想知道如何确切地找出在这里连接到我的服务器需要使用什么IP地址。我使用运行postgres服务器的计算机的公共IP,但我不确定是否正确。或者还有其他步骤我还错过了吗?我知道这是不好的安全风格,但我暂时只想建立一个连接。此外,我的计算机位于路由器后面,那么我如何访问我的服务器?任何帮助将不胜感激。