author | Radek Brich <radek.brich@devl.cz> |
Fri, 23 Mar 2012 14:54:04 +0100 | |
changeset 32 | d59c473c9ad7 |
parent 27 | 5fb4883604d6 |
child 39 | 0cef3540b69f |
permissions | -rwxr-xr-x |
2 | 1 |
#!/usr/bin/env python3.2 |
2 |
||
9
2fcc8ef0b97d
Reorganize again :-) Add setup.py.
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
3 |
from pgtoolkit import pgstats, toolbase |
27
5fb4883604d6
Add analyzeall tool. Updates, fixes.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
4 |
from pgtoolkit.highlight import highlight |
2 | 5 |
|
6 |
||
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
7 |
class LongQueriesTool(toolbase.SimpleTool): |
2 | 8 |
def __init__(self): |
7
685b20d2d3ab
Reorganize directories. PgDataDiff - reworked. PgManager - add fetchone_adapted, fetchall_adapted to cursor.
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
9 |
toolbase.SimpleTool.__init__(self, name='longqueries', desc='List long queries.') |
2 | 10 |
self.init() |
11 |
||
12 |
def main(self): |
|
13 |
stats = pgstats.PgStats(self.pgm.get_conn('target')) |
|
14 |
||
27
5fb4883604d6
Add analyzeall tool. Updates, fixes.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
15 |
for ln in stats.list_long_queries('0m'): |
5fb4883604d6
Add analyzeall tool. Updates, fixes.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
16 |
print(highlight(1), 'backend PID: ', ln['procpid'], ', query_start: ', ln['query_start'].strftime('%F %T'), highlight(0), sep='') |
2 | 17 |
print(ln['query']) |
5 | 18 |
print() |
2 | 19 |
|
20 |
||
21 |
tool = LongQueriesTool() |
|
22 |
tool.main() |
|
23 |