A flamegraph generator for Postgres EXPLAIN ANALYZE
output.
A almost rewrite version,
- static.go is generated with zipdata from static directory.
- Support offline.
- Use webview to automatically open created html.
- Support DATABASE_URL enviroment variable.
Try the demo here.
If you'd like to build a binary from the source code, run the following commands. Note that compiling requires Go version 1.13+.
$ go get -u github.com/alitrack/pg_flame
A pg_flame
binary will be created that you can place in your $GOPATH/bin
.
usage: pg_flame [<flags>]
A flamegraph generator for Postgres EXPLAIN ANALYZE output.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-U, --username="steven" database user name
-h, --host="localhost" database server host or socket directory
-p, --port=5432 database server port
--sslmode="disable" database server sslmode
--password=PASSWORD database server password
--dbname="postgres" database name
-o, --output="pg_flame.html" output html file
-c, --command=COMMAND run only single command (SQL)
-f, --file=FILE execute commands from file
-s, --show_browser Launch browser if successful
--version Show application version.
$ pg_flame -c 'EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) SELECT id FROM users'
Create a SQL file with the EXPLAIN ANALYZE
query.
-- query.sql
EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)
SELECT id
FROM users
Then run the query and save the JSON to a file.
$ pg_flame -f query.sql
Flamegraphs were invented by Brendan Gregg to visualize CPU consumption per code-path of profiled software. They are useful visualization tools in many types of performance investigations. Flamegraphs have been used to visualize Oracle database query plans and query executions , proving useful for debugging slow database queries.
Pg_flame is in extension of that work for Postgres query plans. It generates a visual hierarchy of query plans. This visualization identifies the relative time of each part of a query plan.
This tool relies on the
spiermar/d3-flame-graph
plugin to
generate the flamegraph.