Database access control is the combination of authentication, authorization and policy enforcement that determines who may connect to a database, which objects they may see and which operations they may perform on them. It is a central discipline of database security: even a perfectly patched server leaks data if the wrong account can run SELECT on the wrong table.
In databases, access control works at several levels at once, from network connection rules to individual rows and columns. Its guiding rule is the principle of least privilege: every user, role and service account receives only the permissions its task requires, and nothing more.
How database access control decides each request
Database access control evaluates every request in a sequence of gates, and a request must pass all of them. First the server checks whether the client may connect at all, then it verifies identity, and finally it compares the requested operation with the privileges granted to that identity on the specific object.
- Connection filtering: host-based rules or a database firewall accept or reject the network source.
- Authentication: the server verifies the identity with a password, certificate, Kerberos ticket or external identity provider.
- Authorization: the engine checks object privileges such as SELECT, INSERT, UPDATE, DELETE or EXECUTE.
- Fine-grained policies: row-level and column-level rules filter or block specific data.
- Auditing: the decision and the statement are recorded for later review.
Each layer covers a different weakness. A strong password does not help if the account holds ALL PRIVILEGES, and tight grants do not help if a shared administrator account is used by everyone. Effective control therefore depends on all layers being configured together.
Access control models used in databases
Database engines implement several access control models, and most production systems combine them. SQL standard engines are built on discretionary access control (DAC), in which object owners grant privileges, extended by role-based access control (RBAC) for manageability.
| Model | Decision basis | Typical database feature |
|---|---|---|
| Discretionary (DAC) | Owner grants rights to others | GRANT and REVOKE on tables and views |
| Role-based (RBAC) | Permissions attached to roles, roles to users | Database roles such as reporting_reader |
| Attribute-based (ABAC) | Attributes of user, data and context | Policies using session context or labels |
| Mandatory (MAC) | Central security labels and clearances | Label security in high-assurance systems |
RBAC is the practical default because it scales: an administrator manages a few dozen roles rather than thousands of individual grants. ABAC adds flexibility for multi-tenant applications, where the visible rows depend on a tenant identifier carried in the session.
Granularity levels of database permissions
Permissions can be granted at several levels of granularity, from the whole server down to single cells. Finer levels reduce exposure but add administrative complexity and sometimes query overhead.
| Level | Example control | Main purpose |
|---|---|---|
| Server or instance | Permission to create databases or manage logins | Separate administrators from users |
| Database or schema | USAGE on a schema, CONNECT on a database | Isolate applications and teams |
| Table or view | SELECT on a reporting view only | Expose curated data sets |
| Column | Column-level security on salary fields | Hide sensitive attributes |
| Row | Row-level security filtered by tenant | Separate tenants or regions |
| Procedure | EXECUTE without direct table rights | Allow controlled operations only |
Views and stored procedures are classic tools for indirect access: users receive rights to the view or procedure, not to the underlying tables. Row-level security, available in PostgreSQL, SQL Server and Oracle, enforces filtering inside the engine so that application bugs cannot bypass it.
How access control relates to other security controls
Access control is one layer of database security and is often confused with neighboring controls. The distinction matters because each control fails differently and none replaces the others.
| Control | Question it answers | What it does not cover |
|---|---|---|
| Access control | Who may do what on which object | Data stolen from disks or backups |
| Database authentication | Is this identity genuine | What the identity may access |
| Database encryption | Is stored or transmitted data unreadable to outsiders | Misuse by authorized accounts |
| Dynamic data masking | How is sensitive output obscured | Inference through crafted queries |
| Database audit | Who did what and when | Prevention of the action itself |
A typical failure illustrates the point: encryption at rest protects a stolen disk, but an over-privileged application account reads the same data in clear text. Only access control limits what legitimate connections can reach.
Designing access control in practice
A sound design starts from roles that mirror job functions and application components, not from individual people. Privileges are granted to roles, users join roles, and nobody works routinely with the owner or superuser account.
- Separate accounts per application so that a compromised service exposes only its own data.
- Remove default public privileges, such as the historical CREATE right on the public schema in older PostgreSQL versions.
- Grant on views or procedures rather than base tables where business rules apply.
- Use central identity through directory or single sign-on integration to revoke access promptly when staff leave.
- Review grants periodically, for example quarterly, and remove privileges that are no longer used.
Applications should also use parameterized queries. SQL injection runs attacker statements with the application’s own privileges, so a narrowly scoped account limits the damage even when the code is vulnerable.
Common weaknesses and how to fix them
Most access control incidents result from configuration drift rather than missing features. Permissions accumulate over years, and nobody remembers why an account holds them.
| Problem | Risk | Fix |
|---|---|---|
| Shared administrator login | No accountability for changes | Personal accounts with role membership |
| Application runs as owner | Injection gains full control | Dedicated least-privilege service role |
| Privilege creep | Former duties keep live access | Scheduled access reviews |
| Wildcard grants | New tables become exposed automatically | Explicit grants and default privilege review |
The simple explanation
Think of a database as an office building full of filing cabinets. Access control is the combination of badges, locks and rules that decides who may enter, which rooms they may open and which drawers they may read.
A cleaner can enter the building but not open the payroll cabinet. An accountant can read payroll but not change the locks. Each person gets exactly the keys their job needs, which keeps mistakes and break-ins small.
How it is used in practice
A regional hospital runs its patient records in a relational database used by clinicians, billing staff and an analytics team. Previously, the clinical application connected with one powerful shared account, and analysts queried production tables directly.
The database team introduces separate roles for clinical, billing and analytics access. Clinicians reach full records only through the application role, and row-level security limits each ward to its own patients. Billing staff see diagnosis codes and invoices but not clinical notes, and analysts query a masked reporting schema with pseudonymized identifiers. Grants are reviewed every quarter against the staff directory.
Within the first review, the team revokes more than 40 stale accounts left by former contractors, and an external audit later confirms that every query against patient data can be traced to an individual role.