G
G
gkozyrev2020-08-06 18:14:34
Python
gkozyrev, 2020-08-06 18:14:34

psycopg2.OperationalError?

Help me please!

I've been struggling with the error for several hours now, I can not reproduce and understand what is happening.
Peewee library (psycopg add-on). Previously, everything worked fine until I decided to add a new column to the database (I also declared it in the model), now about 40 minutes after the launch (and successful operation), the following error occurs and repeats with each attempt to access the database:

psycopg2.OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.


On the same PostgreSQL server (11), other databases of other services are running, but there is no problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Tikhonov, 2020-08-07
@tumbler

It looks like the server closes the connection due to inactivity, and the client doesn't reopen it afterwards. You can read about persistent database connections in the Django docs, as it is usually implemented. Surely Peewee also has something similar.

G
gkozyrev, 2020-08-07
@gkozyrev

So, I fixed this problem, I will share the solution in case someone encounters it.
Added initialization of the connection before each request and its closing after the request is completed.
db.connect(
)
.
db.close()
Most likely this is not the only solution, and mine is generally a crutch, but I did not find another one. If you find another solution - you can write it here))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question