I was wondering if there is a more efficient way than scrolling up every command history to find what I need, such as searching for specific characters in a command when writing in the PostgreSQL server. I am running iTerm in macOS and I know this can be done using Control + R
but this does not work when I am writing in the PostgreSQL server. Are there any ways around this?
For example, as I am frequently working with the Apache AGE extension, I will always need to SET
the search path and LOAD
the extension manually each time the PostgreSQL server is started. I know that the search path can be defined permanently using commands and that the postgresql.conf
file can be modified as well, but I just want to know if I can search for specific characters in my command history.
By writing in the PostgreSQL server, I mean when writing in SQL query after running the bin/psql
command:
➜ pgsql-12 bin/psql --port=5431 test1
psql (12.14)
Type "help" for help.
test1=#
2
Answers
Regarding loading AGE automatically without needing to type it every time, you can go to your database folder and change the
postgresql.conf
file withshared_preload_libraries = 'age'
and alsosearch_path = 'ag_catalog, "$user", public'
these variables will be initially set as comments, so it is needed to remove the " # " to apply these changes.Update:
One way to get auto suggestions from history is by using pgcli instead of psql
On most terminals
ctrl+shift+f
orcmd+f
opens the find menu:Alternatively, instead of ‘scrolling up’ you can use the
s
command to print the psql’s command line history.Aditionally, this history can be written to a file using
s filename
.Now, psql commands in this file (or any other file) can be executed by using
i filename
.You can read more about these psql commands here