Skip to content

Instantly share code, notes, and snippets.

@codeslinger
Forked from mikeyk/gist:2307647
Created April 12, 2012 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeslinger/2371012 to your computer and use it in GitHub Desktop.
Save codeslinger/2371012 to your computer and use it in GitHub Desktop.
Run PGFouine for 30 seconds, logging all queries and analyzing the logs
def run_pg_fouine():
info = host_info[env.host_string]
db_name = info.tags.get('Name')
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 0/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
time.sleep(30)
sudo('perl -pi -e "s/log_min_duration_statement = .*/log_min_duration_statement = 500/" /etc/postgresql/9.*/main/postgresql.conf')
sudo('/etc/init.d/postgresql reload')
run('tail -n 100000 /var/log/postgresql/postgresql-9.*-main.log > /tmp/pgfouine.txt')
run('gzip -f /tmp/pgfouine.txt')
get('/tmp/pgfouine.txt.gz', local_path = '/tmp/latest-pgfouine.txt.gz')
local('gunzip -f /tmp/latest-pgfouine.txt.gz')
now = int(time.time())
local('~/src/pgfouine/pgfouine.php -logtype stderr -file /tmp/latest-pgfouine.txt -quiet > /tmp/pgfouine-%s-%d.html 2>1' % (db_name, now))
local('open /tmp/pgfouine-%s-%d.html' % (db_name, now) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment