Skip to content

Commit

Permalink
New way of working for checking if the system user running pg_activit…
Browse files Browse the repository at this point in the history
…y has enough rights in Data.pg_is_local_access(): retreive instance PID file through pg_settings view, open the file and get its content which is the postmasters's PID and finally try to fetch IO counters for this process. Thanks to Julien Rouhaud for the idea.
  • Loading branch information
julmon committed Oct 17, 2015
1 parent 8f46c22 commit 1f195b8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pgactivity/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,27 @@ def pg_connect(self,
def pg_is_local_access(self,):
"""
Verify if the user running pg_activity can acces
system informations for a postgres process.
system informations for the postmaster process.
"""
for psproc in psutil.process_iter():
try:
name = psproc.name()
except NameError:
name = psproc.name
except TypeError:
name = psproc.name
if name in ('postgres', 'postmaster', 'edb-postgres'):
try:
query = "SELECT setting AS pid_file FROM pg_settings WHERE name = 'external_pid_file'"
cur = self.pg_conn.cursor()
cur.execute(query)
ret = cur.fetchone()
pid_file = ret['pid_file']
with open(pid_file, 'r') as fd:
pid = fd.read().strip()
try:
proc = PSProcess(psproc.pid)
proc = PSProcess(int(pid))
proc.io_counters()
proc.cpu_times()
return True
except psutil.AccessDenied:
return False
except Exception:
return False
return False
except Exception:
return False

def pg_get_version(self,):
"""
Expand Down

0 comments on commit 1f195b8

Please sign in to comment.