Tracking any changes made at the database level is crucial for holding accountable any users with access to PostgreSQL.
During my experience as a database administrator, I encountered two situations where applications reported data loss. Upon investigation, we discovered that a table had been truncated. Unfortunately, we couldn’t confirm the source of the issue because auditing was not enabled on the database. This highlights the importance of tracking all activities at the database level.
PostgreSQL supports auditing, and enabling it is relatively straightforward compared to other RDBMS systems.
Installing and configuring pgaudit
check if pgaudit is available in your repository
sudo apt list | grep -i pgaudit
Since pgaudit is not installed on our server, we will proceed with the installation. As we are using PostgreSQL 15, I will install the appropriate version of pgaudit for PostgreSQL 15.postgresql-15-pgaudit
sudo apt install postgresql-15-pgaudit
Update shared library to include pgaudit open postgresql.conf located in etc/postgresql/15/main
sudo nano /etc/postgresql/15/main/postgresql.conf
update the parameter shared_preload_libraries to include pgaudit