Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
We don't bite newbies here... much
 
PerlMonks  

Perl with Database connection.

by santhosh_89 (Scribe)
on Aug 03, 2009 at 07:21 UTC ( #785366=perlquestion: print w/ replies, xml ) Need Help??
santhosh_89 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,
I will be used DBI module.I wanted to create a database connection with perl a time,The connection will be global Whenever I need to execute the postgres query,I will check the connection and execute the sql query is it good method or whenever i need to execute the postgres query on that time I need to connect with database and execute the query,once operation is succeed,close the connection.is it good method.which is the best method in this module.

Comment on Perl with Database connection.
Re: Perl with Database connection.
by Anonymous Monk on Aug 03, 2009 at 07:37 UTC
    Either one will work

      Is it you are telling that both the method are same?

      I have been using the ping method from the DBI module every time I execute a Postgresql query.

        Is it you are telling that both the method are same?

        Essentially. Keep a connection open is only better under high traffic (like perlmonks)

        hello ree,
        I am not asking which method you are using.I need to know creating the many connection is better or creating a single connection(global) is better.I need to know will it cause any data base and performance issue.

Re: Perl with Database connection.
by scorpio17 (Monsignor) on Aug 03, 2009 at 13:35 UTC

    The answer is "it depends".

    In most situations, database connections are a limited resource, just like disk space or bandwidth, etc. For example, if you had a maximum limit of 100 database connections, and many clients trying to connect at the same time, you would want each client to get its data then disconnect as soon as possible, in order to not block other clients. This would be like an ATM machine checking an account balance at a bank.

    On the other hand, if you had a server connected to the database, and lots of clients making similar requests at the same time, it might be better for the server to establish a single, persistent connection to the database, and cache commonly accessed data to avoid redundant queries. This would be like a web site where users read book reviews, for example.

Re: Perl with Database connection.
by bichonfrise74 (Vicar) on Aug 03, 2009 at 18:57 UTC
    I think it is better to just have a single connection if possible. So that if anything goes wrong, you can just terminate a single process in the database.

    Imagine if you have multiple connection and something goes wrong then you can end up saturating your database with your script and making it unusable.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://785366]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-04-18 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (461 votes), past polls