The pg_stat_activity PID column name has changed on 9.2.
authorDavid E. Wheeler <david@justatheory.com>
Wed, 12 Sep 2012 21:41:30 +0000 (14:41 -0700)
committerDavid E. Wheeler <david@justatheory.com>
Wed, 12 Sep 2012 21:41:30 +0000 (14:41 -0700)
So detect if we're on 9.2 or higher, and use the new name, `pid`. Still use
the old name, `procpid`, for older versions of PostgreSQL.

Bucardo.pm
t/BucardoTesting.pm

index 9e7e855abc126a01911e6bcb2ba6e62517099e02..6bb6ef657dd2cf81dcae08a2dcfe1e3862212fc4 100644 (file)
@@ -6773,7 +6773,8 @@ sub terminate_old_goats {
     }
 
     ## Use pg_stat_activity to find a match, then terminate it
-    $SQL = 'SELECT 1 FROM pg_stat_activity WHERE procpid = ? AND query_start = ?';
+    my $pidcol = $maindbh->{pg_server_version} >= 90200 ? 'pid' : 'procpid';
+    $SQL = "SELECT 1 FROM pg_stat_activity WHERE $pidcol = ? AND query_start = ?";
     my $SQLC = 'SELECT pg_cancel_backend(?)';
     my $total = 0;
     for my $dbname (sort keys %{ $self->{sdb} }) {
@@ -7335,6 +7336,7 @@ sub get_deadlock_details {
             ? 'clock_timestamp()' : 'timeofday()::timestamptz';
 
         ## Fetch information about the conflicting process
+        my $pidcol = $dldbh->{pg_server_version} >= 90200 ? 'pid' : 'procpid';
         my $queryinfo =$dldbh->prepare(qq{
 SELECT
   current_query AS query,
@@ -7350,7 +7352,7 @@ SELECT
   CASE WHEN client_port <= 0 THEN 0 ELSE client_port END AS port,
   usename AS user
 FROM pg_stat_activity
-WHERE procpid = ?
+WHERE $pidcol = ?
 });
         $queryinfo->execute($process);
         my $q = $queryinfo->fetchall_arrayref({})->[0];
index 6d29065aeb8eb74cfd4bc6cccdeafac759dbcbef..5e66d56179a153f03aefdf2b270387c3f0d19e3b 100644 (file)
@@ -1019,7 +1019,8 @@ sub setup_bucardo {
     my $dbh = $self->connect_database($clustername, 'postgres');
     if (database_exists($dbh,'bucardo')) {
         ## Kick off all other people
-        $SQL = q{SELECT procpid FROM pg_stat_activity WHERE datname = 'bucardo' and procpid <> pg_backend_pid()};
+        my $pidcol = $dbh->{pg_server_version} >= 90200 ? 'pid' : 'procpid';
+        $SQL = qq{SELECT $pidcol FROM pg_stat_activity WHERE datname = 'bucardo' and $pidcol <> pg_backend_pid()};
         for my $row (@{$dbh->selectall_arrayref($SQL)}) {
             my $pid = $row->[0];
             $SQL = 'SELECT pg_terminate_backend(?)';