</>
Skip to content
PostgreSQL lessons (36/38)

PostgreSQL — Permissions

Grant Permissions

-- Database level
GRANT CONNECT ON DATABASE mydb TO myuser;

-- Schema level
GRANT USAGE ON SCHEMA public TO myuser;

-- Table level
GRANT SELECT ON users TO myuser;
GRANT ALL ON users TO myuser;

Revoke Permissions

REVOKE INSERT ON users FROM myuser;
REVOKE ALL ON users FROM myuser;

Grant to All

GRANT SELECT ON ALL TABLES IN SCHEMA public TO myuser;

Default Privileges

ALTER DEFAULT PRIVILEGES IN SCHEMA public 
GRANT SELECT ON TABLES TO myuser;

Check Permissions

-- Table permissions
SELECT grantee, privilege_type 
FROM information_schema.table_privileges 
WHERE table_name = 'users';

Permission Types

PermissionDescription
SELECTRead data
INSERTAdd data
UPDATEModify data
DELETERemove data
TRUNCATEClear table
REFERENCESForeign keys
TRIGGERCreate triggers

Mini Practice

  1. Grant SELECT permission
  2. Grant multiple permissions
  3. Revoke permissions
  4. Check current permissions

Up Next

Continue with Backup — backup and recovery.

Related Topics

Frequently Asked Questions about Permissions

What is Permissions in PostgreSQL?

Permissions is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Permissions?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Permissions.

Why is Permissions important in PostgreSQL?

Permissions is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.