Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com> writes:
> I have no idea why PostgreSQL closes all the cursors as transaction
> ends,
Because the SQL standard says so. If a cursor isn't declared WITH HOLD,
then it's implicitly closed at transaction commit, cf SQL:2011 4.33
"Cursors":
An open cursor that was not defined as a holdable cursor is also
closed by a <commit statement>.
Also, 14.2 <cursor properties> says that WITHOUT HOLD is the default
assumption if you don't explicitly say WITH HOLD.
(Yes, we do support WITH HOLD.)
regards, tom lane