X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 3479D9FA25D for ; Tue, 2 May 2006 16:06:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 70958-02 for ; Tue, 2 May 2006 16:06:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from pproxy.gmail.com (pproxy.gmail.com [64.233.166.177]) by postgresql.org (Postfix) with ESMTP id 0E20F9F9CC1 for ; Tue, 2 May 2006 16:06:31 -0300 (ADT) Received: by pproxy.gmail.com with SMTP id x66so3231822pye for ; Tue, 02 May 2006 12:06:30 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=RdQn1gCujdGVQKRKJ3jv9eWYUccUOHza/g0jYsmVsNU4U1bF8FV0t3DWJhS71FSi1nOmx+ZC+XCInFMGwnYufzf8BozrdFO2Dh2N24LmCLuISLIboRUL0voALwutXZq4PSuYYwn0CLZKfmbFNNAbFUzT93LhXnVmvgsLf3STaUA= Received: by 10.35.100.6 with SMTP id c6mr1152329pym; Tue, 02 May 2006 12:06:30 -0700 (PDT) Received: by 10.35.49.6 with HTTP; Tue, 2 May 2006 12:06:30 -0700 (PDT) Message-ID: <6d8daee30605021206h8170a48w94670b5d23633a72@mail.gmail.com> Date: Tue, 2 May 2006 12:06:30 -0700 From: "Tony Wasson" To: "Vivek Khera" Subject: Re: postgresql transaction id monitoring with nagios Cc: "Pgsql performance" In-Reply-To: <628A837A-9718-46BB-85D7-8A63BBB1CA32@khera.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_8859_249774.1146596790507" References: <6d8daee30605021126o7b44e255q552dcdc676c565bf@mail.gmail.com> <628A837A-9718-46BB-85D7-8A63BBB1CA32@khera.org> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/36 X-Sequence-Number: 18823 ------=_Part_8859_249774.1146596790507 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 5/2/06, Vivek Khera wrote: > > On May 2, 2006, at 2:26 PM, Tony Wasson wrote: > > > The script detects a wrap at 2 billion. It starts warning once one or > > more databases show an age over 1 billion transactions. It reports > > critical at 1.5B transactions. I hope everyone out there is vacuuming > > *all* databases often. > > Something seems wrong... I just ran your script against my > development database server which is vacuumed daily and it said I was > 53% of the way to 2B. Seemed strange to me, so I re-ran "vacuum -a - > z" to vacuum all databases (as superuser), reran the script and got > the same answer. Ah thanks, it's a bug in my understanding of the thresholds. "With the standard freezing policy, the age column will start at one billion for a freshly-vacuumed database." So essentially, 1B is normal, 2B is the max. The logic is now.. The script detects a wrap at 2 billion. It starts warning once one or more databases show an age over 1.5 billion transactions. It reports critical at 1.75B transactions. If anyone else understands differently, hit me with a clue bat. ------=_Part_8859_249774.1146596790507 Content-Type: application/x-perl; name=check_pg_transactionids.pl Content-Transfer-Encoding: 7bit X-Attachment-Id: f_emqm38g2 Content-Disposition: attachment; filename="check_pg_transactionids.pl" #!/usr/bin/perl -w use strict; use DBI; my $dbhost=$ARGV[0] || die "Pass the IP or hostname of a postgresql server to check."; my $dbname=$ARGV[1] || 'template1'; my $dbuser=$ARGV[2] || 'postgres'; my $dbpass=$ARGV[3] || ''; #"With the standard freezing policy, the age column will # start at one billion for a freshly-vacuumed database." # 2000M = 2 Billion. Too many zeros hurt my eyes. my $wrap_xid_M=2000; # Record wrap at 2 Billion my $warn_xid_M=1500; # Warn at 1.5 Billion my $crit_xid_M=1700; # Critical at 2.0 Billion my $status=3; # default to an UNKNOWN status my $max_xid_pct=-99; # default to a negative percentage my $max_xid_M=-9999; # default to negative XID # my $max_xid_datname="NOT SET (script broke)"; my $Con = "DBI:Pg:dbname=$dbname;host=$dbhost"; my $Dbh = DBI->connect($Con, $dbuser, $dbpass, {RaiseError =>1}) || die "Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr; my $sql="SELECT datname, age(datfrozenxid) FROM pg_database;"; my $sth = $Dbh->prepare($sql); $sth->execute(); while (my ($datname,$max_xid) = $sth->fetchrow()) { my $xid_used_M=sprintf('%1d',($max_xid/1000000)); my $xid_used_pct=sprintf('%1d', ($xid_used_M/$wrap_xid_M)*100); #find the database with the highest transaction id if ($xid_used_M > $max_xid_M) { $max_xid_pct=$xid_used_pct; $max_xid_M=$xid_used_M; $max_xid_datname=$datname; } } $Dbh->disconnect; # 3 UNKNOWN, 2 CRITICAL, 1 WARNING, 0 OK if ($max_xid_M >= $crit_xid_M) { $status=2; } elsif ($max_xid_M >= $warn_xid_M) { $status=1; } elsif ($max_xid_M < $warn_xid_M && $max_xid_M > 0 ) { $status=0; } else { #This means something is wrong with the query or math above $status=3; } print "Transaction IDs are $max_xid_pct% used ($max_xid_M M) in database $max_xid_datname.\n"; exit $status; ------=_Part_8859_249774.1146596790507--