Locks view - Javier Carlos
authorchriskl <chriskl>
Wed, 24 May 2006 04:53:40 +0000 (04:53 +0000)
committerchriskl <chriskl>
Wed, 24 May 2006 04:53:40 +0000 (04:53 +0000)
CREDITS
HISTORY
TODO
classes/Misc.php
classes/database/Postgres.php
classes/database/Postgres73.php
database.php
help/PostgresDoc73.php
lang/english.php
lang/recoded/english.php

diff --git a/CREDITS b/CREDITS
index 751c8851561a2184f2752f47ba42eb3c68d9a863..b9f1e79dfa51114fc10fa8f86395f050f9728ac5 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -55,6 +55,7 @@ Contributors
 - Russell Smith
 - Guillaume Lelarge
 - Ian Barwick
+- Javier Carlos (Locks view)
 
 Third Party Libraries
 
diff --git a/HISTORY b/HISTORY
index 051a0b971b8243a67799eac22bf8b0332ae4637c..a3a153ce16b8cb4a2b36bfeaca15cf636691d87f 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -13,6 +13,7 @@ Features
 * Autovacuum configuration support (Robert Treat)
 * Basic ROLE support (Chris Kings-Lynne)
 * Add support for SSL connections (Eric Kinolik)
+* Display content of pg_locks view (Javier Carlos)
 
 Version 4.0
 -----------
diff --git a/TODO b/TODO
index ce3cd145938e430804236b572bc6d93092fccc09..dd971f6c6f63a295c9f9ed70c6b57007d51bbe2e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -163,7 +163,7 @@ Miscellaneous
 * -Allow management of built-in autovacuum in 8.1 (xzilla)
 * Support per-user and per-database connection limits per 8.1
 * Put a 'What's blocking this query' on Processes view
-* Show locks on database view
+* -Show locks on database view (Javier)
 * Show NOTICES on queries in SQL window/file
 - Add sslmode to connection variables (Eric Kinolik)
 * Printable view of things
@@ -176,7 +176,6 @@ Miscellaneous
   Most objects are now covered thanks to those provided by Niko,
   but we still need icons for:
     Introduction, Variables, Admin, Privileges, Reports
-  
 
 Exotic
 ------
index d1860905d9b0ed77bac8e082ad7a0d759dfcadf2..69f5d2a7c95afb70348d9247c1777ad34c9856d7 100644 (file)
@@ -2,7 +2,7 @@
        /**
         * Class to hold various commonly used functions
         *
-        * $Id: Misc.php,v 1.127 2006/05/22 17:31:22 xzilla Exp $
+        * $Id: Misc.php,v 1.128 2006/05/24 04:53:40 chriskl Exp $
         */
         
        class Misc {
                                                        'tree'  => false,
                                                        'icon'  => 'Processes',
                                                ),
+                                               'locks' => array (
+                                                       'title' => $lang['strlocks'],
+                                                       'url'   => 'database.php',
+                                                       'urlvars' => array('subject' => 'database', 'action' => 'locks'),
+                                                       'hide'  => (!$data->hasLocksView()),
+                                                       'help'  => 'pg.locks',
+                                                       'tree'  => false,
+                                                       'icon'  => 'Key',
+                  ),
                                                'admin' => array (
                                                        'title' => $lang['stradmin'],
                                                        'url'   => 'database.php',
index fd03603f38c51b330de9128f1172722d67ec49e7..4fdee082740eb58359f2fbfa4d7bd1bf8413d4d7 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.284 2006/05/19 07:17:30 chriskl Exp $
+ * $Id: Postgres.php,v 1.285 2006/05/24 04:53:40 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -4560,6 +4560,7 @@ class Postgres extends ADODB_base {
        function hasRoles() { return false; }
        function hasAutovacuum() { return false; }
        function hasAlterSequence() { return false; }
+       function hasLocksView() { return false; }
 
 }
 
index f92dfcd683298aa5443cca7a5520e0a5d11f0483..e9e6053878e8cb489ea00acb654deb403dc07254 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres73.php,v 1.156 2006/05/19 07:17:30 chriskl Exp $
+ * $Id: Postgres73.php,v 1.157 2006/05/24 04:53:40 chriskl Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -273,7 +273,27 @@ class Postgres73 extends Postgres72 {
                
                return $this->selectSet($sql);
        }
-       
+
+       /**
+        * Returns table locks information in the current database
+        * @return A recordset
+        */
+       function getLocks() {
+               global $conf;
+               
+               if (!$conf['show_system'])
+                       $where = "AND pn.nspname NOT LIKE 'pg\\\\_%'";
+               else 
+                       $where = "AND nspname !~ '^pg_t(emp_[0-9]+|oast)$'";
+
+               $sql = "SELECT pn.nspname, pc.relname AS tablename, pl.transaction, pl.pid, pl.mode, pl.granted
+               FROM pg_catalog.pg_locks pl, pg_catalog.pg_class pc, pg_catalog.pg_namespace pn
+               WHERE pl.relation = pc.oid AND pc.relnamespace=pn.oid {$where}
+               ORDER BY nspname,tablename";
+
+               return $this->selectSet($sql);
+       }
+
        // Table functions
 
        /**
@@ -1913,7 +1933,8 @@ class Postgres73 extends Postgres72 {
        function hasUserAndDbVariables() { return true; }
        function hasCompositeTypes() { return true; }   
        function hasFuncPrivs() { return true; }
-
+       function hasLocksView() { return true; }
+       
 }
 
 ?>
index d5da3a2ead954d98a1adcdd9bc8d3a636ef6f76e..acc30ce224fb1fa76a05fbdeebeb191e9557f4f7 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Manage schemas within a database
         *
-        * $Id: database.php,v 1.82 2006/05/19 07:17:29 chriskl Exp $
+        * $Id: database.php,v 1.83 2006/05/24 04:53:40 chriskl Exp $
         */
 
        // Include application functions
                $misc->printTable($processes, $columns, $actions, $lang['strnodata']);
        }
 
+       /**
+        * Show the existing table locks in the current database
+       */
+       function doLocks() {
+               global $PHP_SELF, $data, $misc;
+               global $lang;
+
+               // Get the info from the pg_locks view
+               $variables = $data->getLocks();
+
+               $misc->printTrail('database');
+               $misc->printTabs('database','locks');
+
+               $columns = array(
+                       'namespace' => array(
+                               'title' => $lang['strschema'],
+                               'field' => 'nspname',
+                       ),
+                       'tablename' => array(
+                               'title' => $lang['strtablename'],
+                               'field' => 'tablename',
+                       ),
+                       'transactionid' => array(
+                               'title' => $lang['strtransaction'],
+                               'field' => 'transaction',
+                       ),
+                       'processid' => array(
+                               'title' => $lang['strprocessid'],
+                               'field' => 'pid',
+                       ),
+                       'mode' => array(
+                               'title' => $lang['strmode'],
+                               'field' => 'mode',
+                       ),
+                       'granted' => array(
+                               'title' => $lang['strislockheld'],
+                               'field' => 'granted',
+                               'type'  => 'yesno',
+                       ),
+               );
+
+               $actions = array();
+
+               $misc->printTable($variables, $columns, $actions, $lang['strnodata']);
+       }
+
        /**
         * Allow database administration and tuning tasks
         */
                case 'processes':
                        doProcesses();
                        break;
+               case 'locks':
+                       doLocks();
+                       break;
                case 'export':
                        doExport();
                        break;
index 2d4ba088d44c5b05c1f652d94e5c542e9d4cbbdb..99d357f1edf9b94b6138613da3474e947dbab463 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Help links for PostgreSQL 7.3 documentation
  *
- * $Id: PostgresDoc73.php,v 1.4 2005/04/30 18:02:01 soranzo Exp $
+ * $Id: PostgresDoc73.php,v 1.5 2006/05/24 04:53:40 chriskl Exp $
  */
 
 include('./help/PostgresDoc72.php');
@@ -15,4 +15,6 @@ $this->help_base = sprintf($GLOBALS['conf']['help_base'], '7.3');
 $this->help_page['pg.database.alter'] = 'sql-alterdatabase.html';
 $this->help_page['pg.database.create'][1] = 'manage-ag-createdb.html';
 
+$this->help_page['pg.locks'] = 'view-pg-locks.html';
+
 ?>
index 247dd4a3fd1c98c6138e69a76ef6a549c3cae2f9..b109a4914b3dbb26807d2cd9d6d119f28d7778c6 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.187 2006/05/19 07:17:30 chriskl Exp $
+        * $Id: english.php,v 1.188 2006/05/24 04:53:40 chriskl Exp $
         */
 
        // Language and character set
        $lang['strvacuumcostdelay'] = 'Vacuum Cost Delay'; 
        $lang['strvacuumcostlimit'] = 'Vacuum Cost Limit';  
 
+        //Table-level Locks
+       $lang['strlocks'] = 'Locks';
+       $lang['strtransaction'] = 'Transaction ID';
+       $lang['strprocessid'] = 'Process ID';
+       $lang['strmode'] = 'Lock mode';
+       $lang['strislockheld'] = 'Is lock held?';
+
 ?>
index 7e8a06847fcd93f36369bdcad8d9d0e7374cda70..2583c3682096e973c511590e6a1bc564a9814a2c 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.140 2006/05/19 07:17:30 chriskl Exp $
+        * $Id: english.php,v 1.141 2006/05/24 04:53:40 chriskl Exp $
         */
 
        // Language and character set
        $lang['strvacuumcostdelay'] = 'Vacuum Cost Delay'; 
        $lang['strvacuumcostlimit'] = 'Vacuum Cost Limit';  
 
+        //Table-level Locks
+       $lang['strlocks'] = 'Locks';
+       $lang['strtransaction'] = 'Transaction ID';
+       $lang['strprocessid'] = 'Process ID';
+       $lang['strmode'] = 'Lock mode';
+       $lang['strislockheld'] = 'Is lock held?';
+
 ?>