zenoss / ZenPacks.zenoss.PostgreSQL

PostgreSQL Monitoring
GNU General Public License v2.0
8 stars 7 forks source link

Change getLocks' query #9

Closed SantoshMathew closed 6 years ago

SantoshMathew commented 10 years ago

The query is using a LEFT join which is a LEFT outer join really, so it returns databases which don't have a lock with the mode and granted column as null.

Changed the LEFT join to INNER join to fix the problem

SantoshMathew commented 10 years ago

We are using postgres' Zenpack in production and our locks data is showing much bigger than it is in reality.

SantoshMathew commented 10 years ago

This works with simple EQUI joins as well i.e. without using the INNER join syntax.

So, the query can be simplified to :

SELECT d.datname, l.mode, l.granted FROM pg_database AS d JOIN pg_locks AS l ON l.database = d.oid WHERE NOT d.datistemplate AND d.datallowconn;