longqueries.py
changeset 27 5fb4883604d6
parent 9 2fcc8ef0b97d
child 39 0cef3540b69f
equal deleted inserted replaced
26:7f219da7ab71 27:5fb4883604d6
     1 #!/usr/bin/env python3.2
     1 #!/usr/bin/env python3.2
     2 
     2 
     3 from pgtoolkit import pgstats, toolbase
     3 from pgtoolkit import pgstats, toolbase
       
     4 from pgtoolkit.highlight import highlight
     4 
     5 
     5 
     6 
     6 class LongQueriesTool(toolbase.SimpleTool):
     7 class LongQueriesTool(toolbase.SimpleTool):
     7     def __init__(self):
     8     def __init__(self):
     8         toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.')
     9         toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.')
     9         self.init()
    10         self.init()
    10 
    11 
    11     def main(self):
    12     def main(self):
    12         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    13         stats = pgstats.PgStats(self.pgm.get_conn('target'))
    13 
    14 
    14         for ln in stats.list_long_queries():
    15         for ln in stats.list_long_queries('0m'):
       
    16             print(highlight(1), 'backend PID: ', ln['procpid'], ', query_start: ', ln['query_start'].strftime('%F %T'), highlight(0), sep='')
    15             print(ln['query'])
    17             print(ln['query'])
    16             print('   ', 'query_start:', ln['query_start'].strftime('%F %T'))
       
    17             print()
    18             print()
    18 
    19 
    19 
    20 
    20 tool = LongQueriesTool()
    21 tool = LongQueriesTool()
    21 tool.main()
    22 tool.main()