Using the inline '--command' argument with psql doesn't produce logs in .psql_history

Viewed 143

When I log into my PostgreSQL server manually on Ubuntu and execute a command, I can then find it logged in /root/.psql_history.

However when I try to run a command in a bash script via psql -c "*query goes here*", the command returns data but is not logged in .psql_history.

Has anyone encountered this before?

1 Answers

Command line retrieval and editing, as well as the history file, are functions of the “readline” library that is linked to psql.

Readline support is only active in interactive sessions, so there is also no history written if you invoke psql with the -c or -f options.

Related