Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8236247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:04:54+00:00 2026-06-07T19:04:54+00:00

I have a postgre server that is located in the network and I am

  • 0

I have a postgre server that is located in the network and I am working with the database.
I need to go over large amount of records (1mil+) and each selection takes time.

This is my current method:

DataSet ds = new psqlWork().getDataSet("SELECT * FROM z_sitemap_links"); 
DataTable dt = ds.Tables[0]; 
Parallel.ForEach(dt.AsEnumerable(), dr => 
{ 
    new Sitemap().runSitemap(dr[1].ToString(), counter); 
    counter++; 
}); 

but when the DB size will grow, this method (in my opinion) will not be as effective. Could you suggest a better way of doing this? Maybe pulling the data to process in chunks; although I don’t know how to manage this right now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:04:56+00:00Added an answer on June 7, 2026 at 7:04 pm

    Points for optimization:

    • Create named types, and use ADO.NET to read into named types, instead of using DataSet and DataTable, that will reduce some of the memory footprint.
    • Only pull the records you actually need to work with (you don’t often need to bring in over a million records, but we don’t know your business logic)

    Questions to clarify your original post:

    • Do you have reasons why this won’t scale in the future?
    • How are you processing it that you’re taking advantage of the Parallel.ForEach? Provided that underlying system has the capacity for it, you will probably be just fine with the approach you have now. Consider also, that you should probably profile the actual performance instead of just guessing what’s going to happen.
    DataSet ds = new psqlWork().getDataSet(@"
      SELECT * FROM z_sitemap_links 
      order by timestamp asc /*always order when skipping records so you get the same skips */
      LIMIT 100000 /* using these two with variables you could skip so many records /*
      OFFSET 100000 /* depending on what you're aiming for */
    "); 
    DataTable dt = ds.Tables[0]; 
    Parallel.ForEach(dt.AsEnumerable(), dr => 
    { 
        new Sitemap().runSitemap(dr[1].ToString(), counter); 
        counter++; 
    }); 
    

    And, if you can utilize something like this: row_number() OVER (ORDER BY col1) AS i then you could skip the counter, as that would be provided for you as you select the rows coming back, but my postgres knowledge doesn’t tell me if that will be 1..100000 everytime from the above code, or if it will be what you want, but the guys over at Database Administrators would know for sure. This means your code would become:

    Parallel.ForEach(recordList, record => 
    { 
        new Sitemap().runSitemap(record.FieldYouNeed, record.RowNumberFromDatabase);
    }); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an existing SQL database, and I'm writing a node.js server that accesses
I have been working with Microsoft SQL Server since 6.5 along with other database
I have application that use mysql database, but now i need to port it
I have a postgres database that I want to know some quick stats. For
I currently have a Postgres 8.4 database that contains a varchar(10000) column. I'd like
I have an app running on my production server that uses the pg gem
I have decided to use postgre instead of sql server. My only problem is
We have a postgresql database that is backed up nightly from a cron job
I have access to an Oracle server that has some databases that I would
I have a process that must create and close threads on demand. Each thread

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.