equal
deleted
inserted
replaced
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() |