The terminal blinks, waiting for your next command. You’ve connected to your database, but not everyone should see or change everything. This is where pgcli Role-Based Access Control (RBAC) turns from an idea into a system you can enforce.
Pgcli is a command-line interface for PostgreSQL with autocomplete and syntax highlighting. When combined with RBAC, it becomes a fast, secure way to manage permissions without sacrificing speed or control. RBAC lets you define roles, grant privileges, and apply them to users with precision. In PostgreSQL, roles can be users, groups, or both. Pgcli gives you a quick way to inspect, assign, and revoke those roles in real time.
To implement RBAC in pgcli, start by connecting to your database:
pgcli -h your-db-host -U admin -d your-db-name
Create a role with specific privileges:
CREATE ROLE analyst;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO analyst;
Assign the role to a user: