Pcornel
Databases · PostgreSQL

PostgreSQL Roles and Privileges

Cheat sheet · https://pcornel.dk/topic.php?topic=6180

Back to the Topic

Answer

PostgreSQL roles are users and groups in one concept; privileges are granted on databases, schemas, tables and sequences, and default privileges cover future objects.

Remember

Grant on the schema (USAGE) and the tables. Use ALTER DEFAULT PRIVILEGES for new tables. Don't use superuser for applications.

First checks

  • \du — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

role → membership → schema USAGE → object privileges

Where it usually breaks

Granting on existing tables does not cover tables created later.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6180

Confirmation

Confirm action

Continue?