Module 58: Database Administration

Lesson 1 of 5 · 15–25 minutes

Users, roles and permissions

🏠The everyday picture

In a bank, the cashier can take deposits, the manager can approve loans, the auditor can read every ledger but change none, and the cleaner has no access to the vault at all.

📘What it really is

CREATE ROLE crm_app LOGIN PASSWORD '...';
GRANT SELECT, INSERT, UPDATE ON customers, orders, order_items, payments TO crm_app;

CREATE ROLE reporting LOGIN PASSWORD '...';
GRANT SELECT ON ALL TABLES IN SCHEMA public TO reporting;

🖱️Try it

Write, in admin.sql, the roles your CRM needs (app, migrations, reporting) with exactly the permissions each needs. Next to each GRANT, write a one-line reason. You'll run it in Module 60.

✅Quick check

Should your app connect to the database as the superuser?

Show the answer

No. It should use a role with only the permissions it needs, limiting damage from bugs or attacks.

Why give reporting tools read-only access?

Show the answer

They only need to read; read-only access means a mistake can't change or delete data.

← BackModule 58
ProLearners Assist