23

I am very fond of bash's reverse-search-history (C-r) (command-line feature):

Search backward starting at the current line and moving ‘up’ through the history as necessary. This is an incremental search.

When I hit control-r in bash, I get the following:

(reverse-i-search)`':

And I am able to type characters of previously executed commands, honing in on what I am looking for. If I make a mistake, I can enter control-h to erase a character (equivalent of backspace).

This command-line functionality makes it extremely easy to refer to previously executed commands. I am wondering if such a capability exists for psql. I find it extremely inefficient to rely on just control-p and control-n.

For what it's worth, I am using PostgreSQL 9.3.1 on x86_64-apple-darwin13.0.0, compiled by Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn), 64-bit - obtained via Postgres.app.

7
  • 4
    Have you tried Ctrl-r already? :)
    – dezso
    Apr 18, 2014 at 4:31
  • Of course, and it has no effect for me. Are you suggesting ctrl-r works for you??
    – user664833
    Apr 18, 2014 at 5:30
  • Use rlwrap...
    – Philᵀᴹ
    Apr 18, 2014 at 8:51
  • I installed rlwrap via homebrew (brew install rlwrap) and tried it out (rlwrap psql) - but control-r still does not work; in fact, it behaves in the exact same way as control-r without rlwrap (which is that nothing happens). Perhaps this is the sign of a deeper problem.
    – user664833
    Apr 18, 2014 at 16:31
  • 7
    ctrl-r is normally provided by the readline library. It appears there's an open issue for postgres.app about this. Apr 18, 2014 at 17:05

1 Answer 1

17

A conversation about this on GitHub led to an interim "quick fix" solution:

open ~/.editrc and add:

bind "^R" em-inc-search-prev

Apparently the bigger issue is that PostgresApp uses libedit instead of libreadline. And supposedly libedit lacks some command-line features of libreadline, so until PostgresApp is compiled against libreadline, just use the above quick fix.

1
  • Do you have to be in psql to use it? Aug 6, 2020 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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