psycopg2: Will PostgreSQL store a copy of a table on disk if it has run out of memory

柔情痞子 提交于 2019-12-06 08:33:07
  1. If you want to fetch this table by chunks and sorted then you need to create an index. Every fetch will need to sort this whole table if there will be no such index. Your cursor probably sorted this table once for every row fetched — waiting for red giant sun would probably end sooner…
    create index tablename_order_idx on tablename (x, y, z, h, j, l);

  2. If your table data is relatively stable then you should cluster it by this index. This way table data will be fetched without too much seeking on disk.
    cluster tablename using tablename_order_idx;

  3. If you want to get data in chunks the you should not use cursor, as it will always work one row at a time. You should use limit and offset:
    select * from tablename order by x, y, z, h, j, l
    limit 30000 offset 44*30000

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!