I am running a django app with postgresql, nginx and gunicorn. I have a script where data is pulled from one table in the DB, modified and then needs to replace the existing data in that one table. In the same script, a few tables are also being updated.
When runnning the script, it always results in 502 Bad Gateway
because the server times out because of something in the script. Being fairly new the topic, I am struggling to figure out what is going on with the following error.
I only have the following log to work with from 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
I think the issue is inside of the connections to the database in the script:
#connect to db
engine = create_engine('postgresql+psycopg2://user:password@amazon.host.west',
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')
I am really confused and been banging my head on this problem for a while and nothing seem to be working. Hoping that someone could see where I am messing up.