Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Location
    Sweden
    Posts
    10

    Unanswered: Best connection practice for applications

    Hi all,

    I was wondering what the best practices are regarding
    creating connections from a client application to a database
    (PostgreSQL in particular).

    As i see it, there are two ways..

    1. Make a connection when an application starts and
    keep this until the user exits the application.

    2. Make connections upon demand and close them as soon
    as they're done.

    Option number 2 creates a lot of connection overhead, option
    1 needs to be prepared for database connection failures.


    Regards,
    Robert

  2. #2
    Join Date
    Sep 2002
    Location
    Germany, near Aachen
    Posts
    120
    The answer is, as always, 'depends . . .' ;-)

    First of all, you always have to prepare against connection failures.
    A long running connection may drop and a new connection may not be established.
    So always catch exceptions from all database interactions.

    If your application uses the database rarely, it may be good to open the connection each time, because this way you can perhaps lower the max. number of connections to the server (and connections to PostgreSQL are fast!).

    If your application uses the database all the time, the overhead will be too much.

    As always, run some tests. If you can feel the overhead, open the connection on startup.

    rgds

    Bernd

  3. #3
    Join Date
    Sep 2005
    Location
    Sweden
    Posts
    10
    Ok,

    Thanks for your help. It is highly appretiated!

    Regards,
    Robert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •