1

I am running several commands, some repeatedly, from the postgresql command line tool. In Bash, the history function keeps one command for each set of sequential identical commands, it seems that postgresql command line does not do that by default. So for example if I run command 'a' once, then command 'b' 100 times, I have to scroll up 100 times before running command 'a' again. This is a user-unfriendly way of going about things. Is there an option to have alternate, bash-like functionality from the postgresql command line, in which only unique commands are remembered in the history?

asked May 6, 2015 at 7:59
2
  • 1
    This is all managed by the readline library, which has its own separate configuration. Take a look at readline configuration options. Commented May 6, 2015 at 8:04
  • @CraigRinger -- Please turn this into an answer Commented May 7, 2015 at 19:22

1 Answer 1

5

psql has a variable called HISTCONTROL. Quoting the manual:

HISTCONTROL

If this variable is set to ignorespace, lines which begin with a space are not entered into the history list. If set to a value of ignoredups, lines matching the previous history line are not entered. A value of ignoreboth combines the two options. If unset, or if set to any other value than those above, all lines read in interactive mode are saved on the history list.

I have this configured to automatically take effect on psql startup by adding the line

\set HISTCONTROL ignoredups

to my .psqlrc.

answered May 6, 2015 at 8:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.