# HG changeset patch # User Radek Brich # Date 1348669708 -7200 # Node ID 4fe39c59c515cf548eb4e4c5e3dba4027470231f # Parent a921669e913aa3c7fa0b6c3071899d00239d5b15 Update longqueries tool: add client IP, waiting attributes. diff -r a921669e913a -r 4fe39c59c515 longqueries.py --- a/longqueries.py Wed Sep 26 16:21:59 2012 +0200 +++ b/longqueries.py Wed Sep 26 16:28:28 2012 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python3.2 from pgtoolkit import pgstats, toolbase -from pgtoolkit.highlight import highlight +from pgtoolkit.highlight import highlight, YELLOW, BOLD class LongQueriesTool(toolbase.SimpleTool): @@ -13,7 +13,12 @@ stats = pgstats.PgStats(self.pgm.get_conn('target')) 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(highlight(1), + 'backend PID: ', ln['procpid'], + ', query_start: ', ln['query_start'].strftime('%F %T'), + ', client IP: ', ln['client_addr'], + ln['waiting'] and ', ' + highlight(1, YELLOW|BOLD) + 'waiting' or '', + highlight(0), sep='') print(ln['query']) print() diff -r a921669e913a -r 4fe39c59c515 pgtoolkit.conf.example --- a/pgtoolkit.conf.example Wed Sep 26 16:21:59 2012 +0200 +++ b/pgtoolkit.conf.example Wed Sep 26 16:28:28 2012 +0200 @@ -3,8 +3,7 @@ 'test' : 'host=127.0.0.1 user=test password=test dbname=test' } -### meta database -# connection string (dsn) to meta db +### meta database (contains connection parameters for other databases) meta_db = 'host=10.8.0.1 dbname=central' -# query from meta db, input is database name (will be placed instead of %s), output is values for create_conn +# query for connection parameters, input is database name (will be placed instead of %s) meta_query = '''SELECT host, port, dbname, user, password FROM config.databases WHERE name = %s LIMIT 1''' diff -r a921669e913a -r 4fe39c59c515 pgtoolkit/pgstats.py --- a/pgtoolkit/pgstats.py Wed Sep 26 16:21:59 2012 +0200 +++ b/pgtoolkit/pgstats.py Wed Sep 26 16:28:28 2012 +0200 @@ -41,8 +41,9 @@ curs.close() def list_long_queries(self, longer_than='1m'): - return self._query('''SELECT datname, procpid, usename, current_query AS query, - waiting, xact_start, query_start, backend_start + return self._query('''SELECT + datname, procpid, usename, current_query AS query, + waiting, xact_start, query_start, backend_start, client_addr FROM pg_stat_activity WHERE current_query <> '' AND query_start < now() - interval %s ORDER BY query_start;''', diff -r a921669e913a -r 4fe39c59c515 schemadiff.py --- a/schemadiff.py Wed Sep 26 16:21:59 2012 +0200 +++ b/schemadiff.py Wed Sep 26 16:28:28 2012 +0200 @@ -1,4 +1,10 @@ #!/usr/bin/env python3.2 +# +# Print differences in database schema. +# +# Prints changes from source to destination. +# SQL patch updates source database schema to destination schema. +# from pgtoolkit import pgmanager, pgbrowser, pgdiff, toolbase