Pgcli Row-Level Security lets you inspect and enforce access policies on PostgreSQL tables with precision. Pgcli is a command-line client for Postgres with autocompletion, syntax highlighting, and quick navigation. Combined with PostgreSQL’s Row-Level Security (RLS), you can lock down records so only the right users—or roles—can see them.
RLS works by attaching policies directly to tables. When a query runs, PostgreSQL checks these policies before returning rows. This happens on SELECT, INSERT, UPDATE, and DELETE. If the policy blocks the row, Pgcli won’t display it, because the database simply doesn’t send it.
To enable Row-Level Security in PostgreSQL:
ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;
Define a policy:
CREATE POLICY account_owner_policy
ON accounts
FOR SELECT
USING (owner_id = current_setting('app.current_user')::int);
In Pgcli, you can switch the app.current_user setting dynamically: