Fixes.
authorRadek Brich <radek.brich@devl.cz>
Mon, 09 Jul 2012 10:29:47 +0200
changeset 39 0cef3540b69f
parent 38 d3593869d624
child 40 922d7fb63384
Fixes.
batchquery.py
longqueries.py
mytoolkit/mymanager.py
pgtoolkit/pgstats.py
--- a/batchquery.py	Thu May 31 11:28:41 2012 +0200
+++ b/batchquery.py	Mon Jul 09 10:29:47 2012 +0200
@@ -7,7 +7,7 @@
 class BatchQueryTool(toolbase.SimpleTool):
     def __init__(self):
         toolbase.SimpleTool.__init__(self, name='batchquery', desc='Run a query using columns from CSV file as arguments.')
-        self.parser.add_argument('--query', dest='query', type=str, help='Query to run. Use %s for arguments, or %(name)s for named arguments (see --names).')
+        self.parser.add_argument('--query', dest='query', type=str, help='Query to run. Use %%s for arguments, or %%(name)s for named arguments (see --header).')
         self.parser.add_argument('--file', dest='file', type=str, help='CSV file with data to use as arguments.')
         self.parser.add_argument('--init', dest='init', type=str, help='Query which initialize database session (eg. temporary function).')
         self.parser.add_argument('--output', dest='output', type=str, help='File name for results.')
--- a/longqueries.py	Thu May 31 11:28:41 2012 +0200
+++ b/longqueries.py	Mon Jul 09 10:29:47 2012 +0200
@@ -12,7 +12,7 @@
     def main(self):
         stats = pgstats.PgStats(self.pgm.get_conn('target'))
 
-        for ln in stats.list_long_queries('0m'):
+        for ln in stats.list_long_queries('1m'):
             print(highlight(1), 'backend PID: ', ln['procpid'], ', query_start: ', ln['query_start'].strftime('%F %T'), highlight(0), sep='')
             print(ln['query'])
             print()
--- a/mytoolkit/mymanager.py	Thu May 31 11:28:41 2012 +0200
+++ b/mytoolkit/mymanager.py	Mon Jul 09 10:29:47 2012 +0200
@@ -117,13 +117,13 @@
         try:
             return super(Cursor, self).execute(query, args)
         finally:
-            log.debug(self._executed)
+            log.debug(self._executed.decode('utf8'))
 
     def callproc(self, procname, args=None):
         try:
             return super(Cursor, self).callproc(procname, args)
         finally:
-            log.debug(self._executed)
+            log.debug(self._executed.decode('utf8'))
 
     def row_dict(self, row, lstrip=None):
         adjustname = lambda a: a
--- a/pgtoolkit/pgstats.py	Thu May 31 11:28:41 2012 +0200
+++ b/pgtoolkit/pgstats.py	Mon Jul 09 10:29:47 2012 +0200
@@ -44,6 +44,7 @@
         return self._query('''SELECT datname, procpid, usename, current_query AS query,
             waiting, xact_start, query_start, backend_start
             FROM pg_stat_activity
-            WHERE current_query <> '<IDLE>' AND query_start < now() - interval %s;''',
+            WHERE current_query <> '<IDLE>' AND query_start < now() - interval %s
+            ORDER BY query_start;''',
             longer_than)