I have created 5000 child process from a parent. Made a global database connection. Every child process will share that db connection. Here SIGALARM is handled. If the alarm is generated before the sleep(10000) by manually. The prepared DB query will be executed simultaneously. While passing the signal to the child process. 5000 rows are updated successfully. but it has thrown following error message as

message type 0x5a arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle

I am using DBI module to connect with database. I wanted to know whether DBI using thread?...

For your reference:-
#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; if( $#ARGV < 0 ) { die "no sufficient argument.\n"; } my $fork_count = shift; #print STDERR $local_time."\n"; #print STDERR $execute_time."\n"; my $user="zivah"; my $password="zivah"; my $database="zivah"; my $schema="public"; my $server="192.168.1.40"; my $port="5432"; my $logfile="Log.txt"; my $LOG_FILE; open ($LOG_FILE, ">$logfile") or die "Can't open the file, $!!\n"; $SIG{"ALRM"} = \&handler; sub handler() { my $handle=$_[0]; my $time=localtime; if($handle eq "ALRM") { print $LOG_FILE "SIGNAL SIG$handle is generated on $ti +me -- $$\n"; &Fork_Execute(); } } my $Database_handler; my $sth; sub Database_Connect { # connect with database. #print "Connecting Database\n"; unless( $Database_handler = DBI->connect("dbi:Pg:database=".$d +atabase.";host=$server;port=$port", $user, $password, { RaiseError = +> 0, AutoCommit => 1, PrintError => 1, InactiveDestroy => 1, pg_serve +r_prepare => 0}) ) { # Print an error message for unsuccessfull connection, print "EMERG: connect_database : connecting database f +ailed, $DBI::errstr" ; # Return -1. return -1 ; } # Return the database handler. return $Database_handler; } sub Fork_Prepare { my ($result, $query, $return_value, $delete_time, @tables); # Prepare sql queries for finding unwanted tables. #$query="INSERT INTO $schema.a(name) values('santhosh');"; my $id=shift; $query="Update $schema.a SET name='single',mtime=now() where n +o=$id;"; unless($sth = $Database_handler->prepare($query)){ # print an error message. print "ERROR:can't prepare SQL statement:[ $query ]:[$ +DBI::errstr]"; # return -1. return -1; } } sub Fork_Execute { my ($result); unless($result = $sth->execute()){ # Print an error message print "ERROR:can't execute SQL statement::[$DBI::errst +r]"; return -1; } } &Database_Connect(); my $fc=1; my $cnt=1; my @pids; system("date"); while( $fork_count >= $fc ) { my $pid = fork(); if (not defined $pid) { print "resources not avilable.\n"; } elsif ($pid == 0) { &Fork_Prepare($cnt); #&Database_Connect(); sleep(1000); exit; } else { $fc++; $cnt++; next; } } system("date");

In reply to DB update issue by santhosh_89

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.