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

  • SEARCH
  • Home
  • 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 8748489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:32:02+00:00 2026-06-13T12:32:02+00:00

Fundamentally, this question is about: Can the same DB connection be used across multiple

  • 0

Fundamentally, this question is about: Can the same DB connection be used across multiple processes (as different map-reduce jobs are in real different independent processes).

I know that this is a little trivial question but it would be great if somebody can answer this as well: What happens in case if the maximum number of connections to the DB(which is preconfigured on the server hosting the DB) have exhausted and a new process tries to get a new connection? Does it wait for sometime, and if yes, is there a way to set a timeout for this wait period. I am talking in terms of a PostGres DB in this particular case and the language used for talking to the DB is java.

To give you a context of the problem, I have multiple map-reduce jobs (about 40 reducers) running in parallel, each wanting to update a PostGres DB. How do I efficiently manage these DB read/writes from these processes. Note: The DB is hosted on a separate machine independent of where the map reduce job is running.

Connection pooling is one option but it can be very inefficient at times especially for several reads/writes per second.

  • 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-13T12:32:03+00:00Added an answer on June 13, 2026 at 12:32 pm

    Can the same DB connection be used across multiple processes

    No, not in any sane or reliable way. You could use a broker process, but then you’d be one step away from inventing a connection pool anyway.

    What happens in case if the maximum number of connections to the
    DB(which is preconfigured on the server hosting the DB) have exhausted
    and a new process tries to get a new connection?

    The connection attempt fails with SQLSTATE 53300 too_many_connections. If it waited, the server could exhaust other limits and begin to have issues servicing existing clients.


    For a problem like this you’d usually use tools like C3P0 or DBCP that do in-JVM pooling, but this won’t work when you have multiple JVMs.

    What you need to do is to use an external connection pool like PgBouncer or PgPool-II to maintain a set of lightweight connections from your workers. The pooler then has a smaller number of real server connections and shares those between the lightweight connections from clients.

    Connection pooling is typically more efficient than not pooling, because it allows you to optimise the number of active PostgreSQL worker processes to the hardware and workload, providing admission control for work.

    An alternative is to have a writer process with one or more threads (one connection per thread) that takes finished work from the reduce workers and writes to the DB, so the reduce workers can get on to their next unit of work. You’d need to have a way to tell the reduce workers to wait if the writer got too far behind. There are several Java queueing system implementations that would be suitable for this, or you could use JMS.

    See IPC Suggestion for lots of small data

    It’s also worth optimizing how you write to PostgreSQL as much as possible, using:

    • Prepared statements
    • A commit_delay
    • synchronous_commit = 'off' if you can afford to lose a few transactions if the server crashes
    • Batching work into bigger transactions
    • COPY or multi-valued INSERTs to insert blocks of data
    • Decent hardware with a useful disk subsystem, not some Amazon EC2 instance with awful I/O or a RAID 5 box with 5400rpm disks
    • A proper RAID controller with battery backed write-back cache to reduce the cost of fsync(). Most important if you can’t do big batches of work or use a commit delay; has less impact if your fsync rate is lower because of batching and group commit.

    See:

    • http://www.postgresql.org/docs/current/interactive/populate.html
    • http://www.depesz.com/index.php/2007/07/05/how-to-insert-data-to-database-as-fast-as-possible/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question about how AppFabric's cache feature can be used. I apologize for asking a
Can I specify interfaces when I declare a member? After thinking about this question
This question is about JavaScript language fundamentals. Why we can use dot ( .
I'm just getting used to Subversion and I have a fundamental question about versioning.
A question about Guice. I'm still learning it, but I can understand the fundamentals.
I would like to do something fundamentally similar to this question: Merge an untracked
This question is fairly fundamental.I gave a simple and straighfoward test on my cygwin:
I come from Windows .Net forms development. This is a pretty basic/fundamental question. I'm
I'm sorry if my question title seems fundamentally uninformed. Let me explain what I
On a recent question about MVC attributes, someone asked whether using HttpPost and HttpDelete

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.