6

It is somewhat annoying to type EXPLAIN (ANALYZE, BUFFERS, VERBOSE) in psql tool every time you tune queries.

So, is there a way to define an aliases (autocompletable ones would be very nice) in psql similar to the way it is in bash?

E.g. FULLEXPLAIN SELECT * FROM pg_stat; results into EXPLAIN (ANALYZE, BUFFERS, VERBOSE) SELECT * FROM pg_stat;

1 Answer 1

11
\set fullexplain EXPLAIN (ANALYZE, BUFFERS, VERBOSE)

:fullexplain SELECT * FROM pg_stat;.

Probably not the most elegant thing I admit.

Also you could put this in .psqlrc.

2
  • so the macro should be between : and . ? May 17, 2021 at 9:36
  • When I run this it expands to EXPLAIN(ANALYZE,BUFFERS,VERBOSE) select * from pg_stat;, with all the spaces removed in EXPLAIN .... Is there a way to avoid that? (psql --version -> 15.5)
    – The Hoff
    Jan 16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.