Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Share a temp table in child process using Net::Server

by shammi000 (Novice)
on Feb 24, 2010 at 16:46 UTC ( [id://825110]=perlquestion: print w/replies, xml ) Need Help??

shammi000 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am running an application, which is build on Net::Server::PreFork.

Currently it creates 4 child process, and i want all the child process to access a temporary table created psql. How can i do it ?.

Precisely, I want to create a temporary table in the main application and all the child process should have access to it (The table should be in existence till the application is up).

I tried to create the table in post_configure_hook (custom, override) but it is not working.

In which function i can add the code to create the table.

Regards, Shameem

  • Comment on Share a temp table in child process using Net::Server

Replies are listed 'Best First'.
Re: Share a temp table in child process using Net::Server
by james2vegas (Chaplain) on Feb 25, 2010 at 07:03 UTC
    From DBD::Pg:
    ATTRIBUTES COMMON TO ALL HANDLES InactiveDestroy (boolean) If set to true, then the "disconnect" method will not be automatically called when the database handle goes out of scope. This is required if you are forking, and even then you must tread carefully and ensure that either the parent or the child (but not both!) handles all database calls from that point forwards, so that messages from the Postgres backend are only handled by one of the processes. If you don't set things up properly, you will see messages such as "server closed the connection unexpectedly", and "message type 0x32 arrived from server while idle". The best solution is to either have the child process reconnect to the database with a fresh database handle, or to rewrite your application not to use use forking. See the section on "Asynchronous Queries" for a way to have your script continue to work while the database is processing a request.
    so sharing the database handle between children will not work. You weren't exactly clear on what you meant by having access to the table, but since it is temporary, it will be destroyed at the end of the session and so re-opening the database handle for each forked child will not work either. Perhaps you should create a non-temporary table, re-open the database handle in each child and drop the table when your parent process exits. Alternatively you could use a different Net::Server personality, like Net::Server::Multiplex, which doesn't fork.
Re: Share a temp table in child process using Net::Server
by afoken (Chancellor) on Feb 27, 2010 at 03:21 UTC

    Temporary tables have some usages, but most times, I see them being abused, either because the database design is severely broken (typically not fully normalized), or because the (ab)user wasn't aware of views. Do you really need a temporary table?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://825110]
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2024-04-20 13:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found