POSTGRESQL 및 Django 앱: 클라이언트로부터 데이터를 받을 수 없습니다. 피어에 의해 연결이 재설정되었습니다.

POSTGRESQL 및 Django 앱: 클라이언트로부터 데이터를 받을 수 없습니다. 피어에 의해 연결이 재설정되었습니다.

postgresql, nginx 및 gunicorn을 사용하여 django 앱을 실행하고 있습니다. DB의 한 테이블에서 데이터를 가져와 수정한 다음 해당 테이블의 기존 데이터를 바꿔야 하는 스크립트가 있습니다. 동일한 스크립트에서 몇 개의 테이블도 업데이트됩니다.

스크립트를 실행할 때 502 Bad Gateway스크립트의 내용으로 인해 서버 시간이 초과되기 때문에 항상 결과가 발생합니다. 상당히 새로운 주제이므로 다음 오류로 인해 무슨 일이 일어나고 있는지 파악하는 데 어려움을 겪고 있습니다.

Postgres에서 작업할 수 있는 로그는 다음과 같습니다.

2020-08-22 14:57:59 UTC::@:[8228]:LOG: checkpoint starting: time
2020-08-22 14:57:59 UTC::@:[8228]:LOG: checkpoint complete: wrote 1 buffers (0.0%); 0 WAL file(s) added, 0 removed, 1 recycled; write=0.101 s, sync=0.005 s, total=0.132 s; sync files=1, longest=0.005 s, average=0.005 s; distance=65536 kB, estimate=70182 kB
2020-08-22 14:58:50 UTC:address-ip(45726):pierre@dbexostock:[25618]:LOG: could not receive data from client: Connection reset by peer
2020-08-22 14:58:50 UTC:address-ip(45724):pierre@dbexostock:[25617]:LOG: could not receive data from client: Connection reset by peer

문제는 스크립트의 데이터베이스 연결 내부에 있다고 생각합니다.

#connect to db
engine = create_engine('postgresql+psycopg2://user:[email protected]',
                               connect_args={'options': '-csearch_path={}'.format(dbschema)})

#access the data in the historical_data table 
conn = engine.connect()
metadata = sqlalchemy.MetaData()
histoo = sqlalchemy.Table('uploadfiles_historical_data', metadata, autoload=True, autoload_with=engine)
query = sqlalchemy.select([histoo])
resultproxy = conn.execute(query)
        
        
result_set = resultproxy.fetchall()

#update the historical table 
histo = histo2.head(0).to_sql('uploadfiles_histoo', engine, if_exists='replace')
cur = conn.cursor()
output = io.StringIO()
histo2.to_csv(output, sep='\t', header=False, encoding='utf8')
output.seek(0)
cur.copy_from(output,'uploadfiles_histoo')
conn.commit()

#update other tables (example)
itemmdb = df559.to_sql('dashboard_item', engine, if_exists='replace')

나는 정말 혼란스럽고 한동안 이 문제에 대해 머리를 숙이고 있었는데 아무것도 작동하지 않는 것 같습니다. 누군가 내가 어디를 엉망으로 만들고 있는지 볼 수 있기를 바랍니다.

관련 정보