问题描述
我使用pyqt5和postgresql数据库创建了2个GUI应用程序
其中一个是读写应用程序,而两个ND是只读的
我想在一台包含只读应用程序的计算机上安装数据库,而在另一台计算机上该应用程序读取写操作
请注意,两台PC是使用DHCP(动态主机配置协议)服务器连接的,我用来将我的应用程序连接到数据库的代码是这样的
connection = psycopg2.connect(user="postgres",password="password",host="localhost",port="5432",database="SIFAX")
解决方法
找到解决方案
文件首位
pg_hba.conf
在C:\ Program Files \ PostgreSQL \ 12 \ data中 像这样添加客户端PC的IP地址
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all x.x.x.x/32 md5#ip of the first client
host all all x.x.x.x/32 md5#ip of the 2nd client
,并且在服务器中使用的gui代码中,就像这样
connection = psycopg2.connect(user="postgres",password="password",host="localhost",port="5432",database="database")
以及客户端PC中使用的gui代码,就像这样
connection = psycopg2.connect(user="postgres",host="ip adress of the server",database="database")