That was the moment I knew Pgcli needed auditing. Not tomorrow. Not next week. Now.
Pgcli makes working with PostgreSQL fast, colorful, and productive. But like any database client, every query you run, every table you peek into, and every connection you open leaves a trace. Without proper auditing, you lose the chain of events that led to a failure, a security breach, or a surprise data change.
Auditing Pgcli is not about slowing things down. It’s about clarity. It’s about making sure every command has a record, every user leaves a signature, and every number in your report has a history you can trust.
Start by enabling PostgreSQL’s native logging. Pgcli is just a client, so its activity is visible to the database. Adjust log_statement and log_duration to capture all queries — including those that run too fast for a human to notice. Use log_line_prefix to tag each action with the username, PID, and timestamp.
Once your database logs everything, pipe the logs to a centralized store. File-based logs work, but structured logs in JSON open the door for real-time analysis. With tools like pgAudit, you can add fine-grained detail on exactly which rows were read or changed, and by whom.