How to debug "could not receive data from client: Connection reset by peer"
Asked Answered
M

3

24

I'm running a django-celery application on Ubuntu-12.04.

When I run a celery task from my web interface, I get the following error, taken form postgresql-9.3 logfile (maximum level of log):

2013-11-12 13:57:01 GMT tss_usr 8113 LOG:  could not receive data from client: Connection reset by peer

tss_usr is the postgresql user of the django application database and (in this example) 8113 is the pid of the process who killed the connection, I guess.

Have you got any idea on why this happens or at least how to debug this issue?

To make things work again I need to restart postgresql which is extremely uncomfortable.

Monadelphous answered 12/11, 2013 at 14:5 Comment(4)
This msg usually gets logged when Postgres figures out that the application that was connected has gone away and not closed the connection to the database. I'm really surprised you have to restart Postgres to get a new connection. Is this with any app? or just yours? Can you connect via psql?Salsbury
I've googled and I found out what this message means but I have no idea how to inspect what is the cause. I have a django app which uses celery, but I have no lines managing directly connections closing. I can connect via psql but when the connection breaks down I cannot do anything from a local terminal too!Monadelphous
It's possible that you've run out of non-superuser connections (your config file will show , but I'd be surprised if PostgreSQL itself stopped responding.Phalangeal
But my tss_usr user has super user privileges on django app database...of wich config file are you talking about, postgresql.conf?Monadelphous
T
9

I know this is an older post, but I just found it because I had the same error today in my postgres logs. I narrowed it down to a PDO select statement. I'm using Zend Framework 1.10.3 on Ubuntu Precise.

The following pdo statement generated an error if $opinion is a long text string. The column opinion is type Text in my postgres table. The query succeeds if $opinion is under a certain number of characters. 1000 characters works fine. 2000 characters fails with "could not receive data from client: Connection reset by peer".

  $select = $this->db->select()
           ->from( 'datauserstopics' )
           ->where("opinion = ?",trim($opinion))
           ->where("datatopicsid = ?",trim($tid))
           ->where("datausersid= ?",$datausersid);

  $stmt = $this->db->query($select);

I circumvented the problem by using: ->where("substr(opinion,1,100) = ?",trim(substr($opinion,1,100)))

This is not a perfect solution, but for my purposes, the select statement using substr() suffices.

Note that I have no problem inserting long strings into the same table/column. The disconnect problem only appears for me on the PDO select with relatively long text strings.

Team answered 30/9, 2014 at 20:54 Comment(0)
W
4

I'm getting it in 2017 with 9.4, I have no text fields, don't know what a PDO is. My select statement is about 50 bytes long, I'm trying to fetch an int4 and a double precision. I suspect the error message can mean multiple things.

I've since found https://dba.stackexchange.com/questions/142350/postgres-could-not-receive-data-from-client-connection-reset-by-peer which indicates it could be a problem with the client configuration. My client is libpg and PQconnectdb() is giving me a CONNECTION_OK return. It works at least partly.

Whitted answered 12/4, 2017 at 13:56 Comment(2)
did you find a solution, i use libpg to connect postgres too, and stuck with this errorFerebee
Sorry, I don't rememberWhitted
S
-2

For me, restarting the hypervisor where both the Postgres and the application using it helped. I've seen stack traces in dmesg before, though.

Sylvester answered 23/9, 2019 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.