Database security is the set of controls that protect a database, the data inside it, and the ways people and applications reach it. It covers who can connect, what each connection is allowed to do, what data comes back, what is recorded, and how the database server itself is configured and patched. The goal is not a single product. It is a set of layers that still hold when one of them fails.
Databases deserve their own security discipline because they hold the thing attackers usually want: customer records, payment data, health information, credentials and intellectual property. Most other systems are a way to reach the database. And because databases are shared by applications, administrators, analysts, support staff and developers, they accumulate access faster than almost any other system.
This guide explains the layers of database security, how databases are actually compromised, how the layers fit together, and a practical order of work. Each section can be read on its own, and each links to a deeper page where one exists.
Why databases are a special case
Three properties make databases different from most workloads.
- They concentrate value. A single table can hold millions of customer records. One successful query can take all of them.
- They have many kinds of users. Applications connect with service accounts. Administrators manage the server. Developers debug. Analysts run reports. Support staff fix individual customer problems. Each group needs different access, and in practice they often share one or two broad accounts.
- Their normal activity looks like attack activity. A person running
SELECT *on a customer table might be debugging, or might be stealing data. The database cannot tell the difference without context about who they are and why they are there.
For these reasons, perimeter controls such as firewalls and network segmentation are necessary but incomplete. The attacker, or the careless insider, often arrives with a valid login.
The five layers of database security
1. Infrastructure and configuration
This is the database server and the environment around it: where it runs, who can reach it over the network, how it is configured, and whether it is patched.
- Network exposure. A database should rarely have a public address. Private subnets, security groups and private endpoints keep it off the internet. A publicly reachable database turns any leaked credential into an immediate problem. See how to read the attack path of a publicly accessible database.
- Hardening. Disable features and extensions you do not use, remove default accounts, require encrypted connections, and follow a published baseline such as the CIS Benchmark for PostgreSQL or the equivalent for your engine.
- Patching. Database engines ship security fixes regularly. The November 2026 PostgreSQL release fixed 52 flaws, including one that let a user who can create objects run code on the server. We explain it in PostgreSQL’s 52 security fixes. Which fixes to apply first is a prioritization problem, covered in how to prioritize which CVEs to fix.
- Encryption. Encrypt data in transit with TLS, and at rest with disk or database-level encryption and managed keys. Encryption protects stolen disks and backups. It does not protect against someone who has a valid login, which is why the next layers exist.
2. Identity and access control
This layer decides who may connect and what they may do.
- Individual identity. Every human connection should be tied to a named person. A shared
adminpassword cannot tell you who ran a query. - Least privilege. Grant only what each role needs, and nothing more. Applications rarely need to create tables. Analysts rarely need to write. See the principle of least privilege.
- Time-limited access. Human access to production should be requested for a reason and expire. Standing access to production databases is the most common source of excess exposure. See zero standing privilege.
- Service accounts and secrets. Application credentials should be stored in a secrets manager, rotated, and scoped to one application. See secret rotation and non-human identities.
Native database roles and grants are the foundation, but they are coarse. A grant such as SELECT on a table gives access to every row and every column. It cannot hide a column from one person and show it to another.
3. Data-level protection
This layer limits what a legitimate session can see and take.
- Masking. Show only part of a sensitive value, such as the last four digits of a card number, or replace it with a token, depending on who is asking. See real-time data masking.
- Row and column restrictions. Limit which rows and columns a role can read. PostgreSQL’s row-level security is one native tool, and it has had its own fixes, as the November 2026 release shows.
- Query guardrails. Block statements that are almost never legitimate in production, such as a
DELETEwithout aWHEREclause, aDROP, or aSELECTwith no row limit on a customer table. - Data minimization. Data that is not stored cannot be stolen. Delete what you do not need, and keep non-production copies free of real customer data.
4. Monitoring and audit
This layer answers the questions that come after something goes wrong, and ideally during it: who connected, what did they run, what data came back, and when.
- Native logs show connections and, depending on settings, statements. They rarely tie a shared account to a person.
- Database activity monitoring (DAM) records each query with the identity behind it and can raise alerts on unusual patterns.
- A durable audit trail is also a compliance requirement under frameworks such as SOC 2, HIPAA and PCI DSS. See database audit logging.
5. Response and recovery
Plan for the day a credential is stolen or a bad query runs. That means tested backups stored away from the database host, a way to revoke database access quickly, and a runbook for investigating what was read or changed. See incident response.
How databases are actually compromised
| Pattern | What happens | Layer that should stop it |
|---|---|---|
| Stolen or leaked credentials | A database password appears in a repository, a chat message or an infostealer log. The attacker connects as a legitimate user. | Access control, time-limited access, monitoring |
| Excess standing access | A developer who needed access for a task a year ago still has write access to production. | Least privilege, access expiry |
| SQL injection | An application passes user input into a query, and the attacker changes what the query does. | Application code, query guardrails, least privilege |
| Unpatched server flaws | A bug in the engine lets a low-privilege user run code on the server. | Patching, least privilege |
| Public exposure | A database is reachable from the internet with weak or reused credentials. | Network and configuration |
| Insider over-collection | A support engineer exports a table “to check something.” | Masking, guardrails, audit |
| Unmonitored third-party access | A vendor holds a standing database login that nobody reviews. | Access control, expiry, audit |
Notice that most rows involve a valid login. That is why identity and data-level controls matter as much as the network and the patch level.
How the layers fit together
A useful way to think about it is as three questions that every database connection should be able to answer:
- Should this person or application be connected right now? (identity, approval, time limit)
- What should this session be allowed to do and see? (least privilege, guardrails, masking)
- Can we prove what happened afterward? (audit, monitoring)
If you can answer all three for every connection, you have a defensible program. If you can only answer the first one (“they have the password”), you have a gap.
A practical order of work
- Inventory your databases. List every instance, who owns it, what data it holds, and whether it is reachable from the internet. Include the forgotten ones.
- Close the network exposure. Remove public addresses and tighten security groups.
- Patch. Apply engine updates, ordered by exposure and by whether the flaw is being exploited. See what is the CISA KEV catalog.
- Reduce who can connect. Remove shared accounts. List every login and its privileges, and revoke what is not needed. Move human access to production onto requests that expire.
- Protect sensitive columns. Decide which data is sensitive, and mask or restrict it for roles that do not need it.
- Turn on query-level audit. Make sure you can answer who ran what, and keep the log somewhere the database host cannot alter.
- Rehearse the bad day. Practice revoking access and tracing what a compromised account read.
How Cloudanix helps
Cloudanix covers the access, data and activity layers, and connects them to the posture of the cloud around the database.
- Database JIT gives people keyless, identity-stamped access to PostgreSQL, MySQL, MariaDB, SQL Server and CosmosDB, without shared passwords or a jump host. Access is requested, approved, time-boxed and revoked automatically.
- Database Access Management (DAM) is an add-on to Database JIT. It runs as a query proxy inside your own environment, so the data it inspects stays in your infrastructure. For PostgreSQL, MySQL and MSSQL it sanity-checks queries for injection patterns, enforces guardrails (for example, blocking delete, drop and truncate, requiring a
WHEREclause, restricting tables and columns, and capping row counts), masks sensitive values by role after the query runs, and logs every query to storage you own. DAM cannot be bought without Database JIT. - CSPM finds databases exposed to the internet, over-permissioned roles and weak network rules, and ranks them with contextual severity using exposure, environment, data sensitivity and identity.
- Attack path analysis shows how an identity or misconfiguration leads to a database, which supports the inventory and exposure steps.
For examples, see the end of permanent access for database security, query-level audit and PII masking for databases behind ECS and data-sovereign DAM.
A note on boundaries. Cloudanix does not patch your database engine, and DAM is not an exploit shield for server flaws. Its value is in controlling who gets a session, narrowing what a session can do and see, and keeping a complete record.
Further reading
- CIS Benchmark for PostgreSQL, a published hardening baseline
- OWASP: SQL Injection
- NIST SP 800-92: Guide to Computer Security Log Management
- PostgreSQL security information
Frequently asked questions
What is database security?
Database security is the set of controls that protect a database and its data: network and configuration hardening, identity and access control, data-level protection such as masking, monitoring and audit, and recovery planning.
Is encryption enough to secure a database?
No. Encryption at rest protects stolen disks and backups, and encryption in transit protects network traffic. It does not stop someone who connects with a valid login from reading the data. You also need access control, data-level protection and audit.
What is the difference between database security and database activity monitoring?
Database security is the whole discipline. Database activity monitoring is one layer of it: recording and analyzing what users and applications do inside the database. See database activity monitoring and DSPM vs DAM.
Why is standing access to databases risky?
Because any leaked or stolen credential works immediately and indefinitely. Access that exists only while someone has an approved reason shrinks the number of live logins an attacker could use.
Do I need DAM if I already have native database logs?
Native logs show that a connection happened and, with the right settings, which statements ran. They usually do not name the person behind a shared account, mask sensitive columns, or block risky queries. See DAM vs native database logging.