Did it help? If yes - maybe you can help me? Donate BTC to 19zPa5diT2LZqGtTi8f8bfApLn8rw9zBHx
So, lately I have been thinking about integrating explain.depesz.com with psql. Currently, you have to run explain, copy the output, switch to webbrowser, go to explain.depesz.coma> site, paste output, click submit. It's not that it's a lot of work, but it can be simplified.
To simplify it, we need just 2 minutes.
First, you need to create /usr/local/bin/explain.depesz.com script (path and name is irrelevant, but /usr/local/bin/ is usually in $PATH, and explain.depesz.com name will be pretty self-explanatory when using it.
Content of this file should be:
#!/usr/bin/env bash explain="$( cat - )" google-chrome "$( curl --silent --include --data-urlencode "plan=$explain" http://explain.depesz.com/ | perl -ne 'print if s/\ALocation:\s*(\S+)\s*\z/$1/' )"
Instead of “google-chrome" you can use any webbrowser you want, though you might need to play with options to it.
Anyway. When you'll do it, and the script will have 0755 privileges, then in your psql, you run something along the lines of:
$ \o |explain.depesz.com $ explain analyze select * from pg_class where relname = 'YEAH'; $ \o Created new window in existing browser session.
That is, you run: “\o |explain.depesz.com", which redirects output of all commands to this script (it should be started by now, by psql).
Then you run your explain command.
And afterwards – you let psql know that you're done with output redirection – with \o.
At this time (at the end), explain.depesz.com, will get all the data, post it to explain.depesz.com, and open explain page in your browser (but only after final \o). You can also put the final \o at the end of explain line (after semicolon).
If this is too much for you to remember (switching \o on and off), you can get the same results by doing:
$ explain analyze select * from pg_class where relname = 'YEAH' \g | explain.depesz.com
that is – replacing “;" with “\g | …".
Hope if will help you, a bit