我正在尝试在ubuntu上设置一个postgresql 9.1服务器,用于远程访问数据.我已正确安装postgres,服务器进程正在运行,我正在尝试对其进行配置,以便我可以通过Internet从局域网外的其他几台计算机远程访问服务器.
我已经修改了我的pg_hba.conf:
host all all 0.0.0.0 trust
Run Code Online (Sandbox Code Playgroud)
和postgresql.conf:
listen_addresses = '*'
port = 5432
Run Code Online (Sandbox Code Playgroud)
我还修改了我的iptables以接受端口5432上的连接.
当我尝试在python上使用psycopg2连接时:
conn=psycopg2.connect('host=XX.XX.XX.XX port=5432 dbname=postgres user=myUser password=mypassword')
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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?
Run Code Online (Sandbox Code Playgroud)
我不确定我是否插入了正确的IP地址,我很好奇我将如何确切地知道在这里使用哪个IP地址连接到我的服务器.我使用运行postgres服务器的计算机的公共IP,但我不确定是否正确.或者还有其他一步我仍然缺席?我知道这是不好的安全风格,但目前我想建立一个连接.我的电脑也在路由器后面,所以我如何专门访问我的服务器?
任何帮助非常感谢.