Information
On Linux/UNIX, the PostgreSQL client logs most interactive statements to a history file.The default PostgreSQL history file is namedpsql_history in the user's home directory.
The PostgreSQL command history should be disabled.
Disabling the PostgreSQL command history reduces the probability of exposingsensitive information, such as passwords, encryption keys, or sensitive data.
Solution
For each OS user on the PostgreSQL server, perform the following steps to implement this setting:
-
Removepsql_history if it exists.
# whoami
root
# rm -f ~<user>/.psql_history || true
```
2. Use either of the techniques below to prevent it from being created again:
1. Set the `HISTFILE` variable to `/dev/null` in `~<user>/.psqlrc`
```
# whoami
root
# cat << EOF >> ~<user>/.psqlrc
\set HISTFILE /dev/null
EOF
```
2. Create `~<user>/.psql_history` as a symbolic to `/dev/null`.
```
# whoami
root
# ln -s /dev/null $HOME/.psql_history
``
3. Set the `PSQL_HISTORY` variable for all users:
```
# whoami
root
# echo 'PSQL_HISTORY=/dev/null' >> /etc/environment
```