Skip to content

is pq memory friendly? #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nuliknol opened this issue Feb 9, 2018 · 7 comments
Open

is pq memory friendly? #713

nuliknol opened this issue Feb 9, 2018 · 7 comments

Comments

@nuliknol
Copy link

nuliknol commented Feb 9, 2018

I need to query retrieve 10 million records with lib/pq.
Is rows.Next() memory friendly or do I have to use cursors?

@timbunce
Copy link

Cursors, sadly. See #635 and #81 (now 5 years old).

@johto
Copy link
Contributor

johto commented Apr 20, 2018

@timbunce You have that backwards. Those issues happen because pq uses a cursor underneath. If we read all the rows into memory first, we wouldn't have those issues.

In other words, there's no need to use a cursor explicitly.

@johto
Copy link
Contributor

johto commented Apr 20, 2018

In other words, there's no need to use a cursor explicitly.

I guess I should clarify: there's no need to use a cursor explicitly if you're only worried about memory usage.

@timbunce
Copy link

Yes, you're right, I'd got it backwards. Thanks @johto!

@mbeirouti
Copy link

mbeirouti commented May 22, 2019

@johto are you saying pq uses a server side or client side cursor? I can't seem to find any reference in the code base to a server side cursor except in unused error messages and types, maybe I'm missing something..

@cbandy
Copy link
Contributor

cbandy commented May 24, 2019

@mbeirouti it's implicit in the wire protocol. The unnamed portal acts like a server side cursor.

https://www.postgresql.org/docs/current/protocol-flow.html

@auror
Copy link

auror commented Dec 9, 2019

@mbeirouti Just to clarify,

  1. Does this unnamed portal act as an explicit server side cursor i.e., DECLARE Cursor?
  2. What are the significant differences b/w these two approaches?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants