Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
932 views
in Technique[技术] by (71.8m points)

postgresql - Connection to the database failed - server closed the connection unexpectedly. This probably means the server terminated abnormally

The rest of the error is "before or while processing the request."

I have a CentOS server running Postgres on an internal network scheme 192.168.11.0/24 for which I also have pgAdmin4 also installed and running. pgAdmin is connecting via localhost and I can successfully connect to my database.

I am running a windows 10 client on 192.168.11.100 with Lazarus trying to get a TPQConnection object to connect. This error comes up when I click the "Connected" property with all the connection information filled in.

The server is running on 192.168.11.25.

I have the Postgres client libraries extracted and in my system path (the bin directory) for the version of Postgres I'm running (12.5)

My pg_hba.conf file is set up to allow the connecton - Here are the relevant lines:

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.11.0/24         md5
# IPv6 local connections:
host    all             all             ::1/128                 md5

I've set the password for the postgres user and verified that the account works with pgAdmin.

I'm not sure if this has to do with Lazarus or if this is a postgres client library problem.

I have also tried installing the Postgres ODBC client and attempted to create a DSN and was unsuccessful with that as well. I'm guessing this could be a configuration problem on the server not sure though.

Rich

question from:https://stackoverflow.com/questions/65849006/connection-to-the-database-failed-server-closed-the-connection-unexpectedly-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I figured it out finally - been struggling with this for 2 days! By default Postgres only listens on localhost.

I had to edit postgresql.conf listen_addresses parameter and set it to '*' or equivalent IP address if I want to be more restrictive. With the pg_hba.conf restricting from which addresses login can happen on it seems perfectly sufficient to use '*' for listen_addresses.

After that I was able to connect from Lazarus.

Rich


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...