Reise45
Reise45

Reputation: 1203

Does redeclaring a cursor create new connection while using psycopg2?

I am using the psycopg2 library with Python3 on a linux server to create some temporary tables on Redshift and querying these tables to get results and write to files on the server.

  1. Since my queries are long and takes about 15 minutes to create all these temp tables that I ultimate pull data from, how do I ensure that my connection persists and I don't lose the temp tables that I later query? Right now I just do a cursor() before the execute(), is there a default timeout for these?
  2. I have noticed that whenever I do a

Select a,b from #results_table

or

select * from #results_table

the query just freezes/hangs, but

select top 35 from #results_table

returns the results (select top 40 fails!). There are about a 100 rows in #results_table, and I am not able to get them all. I did a ps aux and the process just stays in the S+ state. If I manually run the query on Redshift it finishes in seconds. Any ideas?

Upvotes: 0

Views: 95

Answers (1)

Yuri Levinsky
Yuri Levinsky

Reputation: 1595

Re-declaring a cursor doesn't create new connection while using psycopg2.

Upvotes: 1

Related Questions