2.3 Disable PostgreSQL Command History

Information

On Linux/UNIX, the PostgreSQL client logs most interactive statements to a history file. The default PostgreSQL history file is named .psql_history in the user's home directory.

The PostgreSQL command history should be disabled.

Rationale:

Disabling the PostgreSQL command history reduces the probability of exposing sensitive 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:

Remove .psql_history if it exists.

rm -f ~<user>/.psql_history || true

Use either of the techniques below to prevent it from being created again:

Set the HISTFILE variable to /dev/null in ~<user>/.psqlrc

cat << EOF >> ~<user>/.psqlrc
set HISTFILE /dev/null
EOF

Create ~<user>/.psql_history as a symbolic to /dev/null.

ln -s /dev/null $HOME/.psql_history

Set the PSQL_HISTORY variable for all users:

sudo echo 'PSQL_HISTORY=/dev/null' >> /etc/environment

See Also

https://workbench.cisecurity.org/benchmarks/17003

Item Details

Category: MEDIA PROTECTION

References: 800-53|MP-6

Plugin: Unix

Control ID: 2e9ddf45bb15b1397fd10475faf8c276f88cda7e706aa9a31fc49a4740e0de8c