Skip to content

Instantly share code, notes, and snippets.

@steve-chavez
Forked from lovubuntu/psql_commands_history.md
Created September 5, 2022 22:06
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 steve-chavez/a36dfc36ae6a78c745b7a801b726a205 to your computer and use it in GitHub Desktop.
Save steve-chavez/a36dfc36ae6a78c745b7a801b726a205 to your computer and use it in GitHub Desktop.
History for psql commands

There's no history in the database itself, if you're using psql you can use "\s" to see your command history there.

You can get future queries or other types of operations into the log files by setting log_statement in the postgresql.conf file. What you probably want instead is log_min_duration_statement, which if you set it to 0 will log all queries and their durations in the logs. That can be helpful once your apps goes live, if you set that to a higher value you'll only see the long running queries which can be helpful for optimization (you can run EXPLAIN ANALYZE on the queries you find there to figure out why they're slow).

Another handy thing to know in this area is that if you run psql and tell it "\timing", it will show how long every statement after that takes. So if you have a sql file that looks like this:

\timing select 1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment