A tool to run queries against different postgres settings. Normally one would scour the postgres logs for slow queries.
Author: Matt Harrison (firstname.lastname@example.org) LICENSE: MIT
Scouring logs for queries
Run the following to pull queries from log files:
pgtweak --extract-queries --log-file some/pg/log/file > extracted.sql
Getting a query file
One can go through extracted.sql to find a query to example, or hand write them in a text file.
Generating a sample config file
A config file is used to indicate what settings to tweak. It is a json file that looks like this:
[ [ "work_mem", [ "1MB", "512MB" ] ], [ "maintenance_work_mem", [ "1MB", "512MB" ] ] ]
That is the one generated by:
You can add more settings and possible values for settings. Remember though, that it will test the combination of each setting. For every new value option you add to a setting, you double the runs. (Note that just adding an setting with a single value just includes that in every run.)
pgtweak --query-file simple.sql --analyze-queries --dburl postgres://postgres@localhost/testetl --config-file conf.json > results.json
dburl is a SqlAlchemy style connection string like
results.json file contains JSON list containing the query, time to
run, results, and settings for that query.
Settings and explanations
Explain settings (TODO)
Need to turn on Postgres logging in
log_destination = stderr logging_collector = on log_filename = 'pgsql-%Y-%m-%d.log' log_min_error_statement = 'error' log_connections = false log_line_prefix = '<%t>' log_statement = all log_directory = '/var/log/pglog'
- Make sure log_directory exists and has correct permissions
- Restart postgres