Use it when hardening a database or reviewing access.
Database Security
Database security: authentication, least-privilege roles, network restrictions, TLS in transit, encryption at rest, auditing and patching.
1. List users and privileges: \du / SELECT user,host FROM mysql.user; / sys.server_principals.
2. Network exposure: ss -ltnp — listen addresses and firewall.
3. TLS required?
4. Audit logging enabled.
5. Version patched.
network filter → authentication → authorisation (roles/grants) → audit
Failures include broad shared accounts, forgotten host/database-specific grants, plaintext or weakly validated TLS, credentials in scripts, privilege accumulation, audit gaps and assuming storage encryption prevents privileged database reads. Preserve the first divergent observation and repeat the same bounded verification after remediation.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Security owns organizational identity/crypto policy. Databases owns engine accounts, grants, connection security and audit behavior; secret stores remain in Security/Automation as appropriate.
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification workflow Verify boundary
Identify the account/role actually used, effective grants and authentication source. Verify TLS from the client/session, test a permitted and denied action, inspect audit/log output, and trace where credentials are stored/rotated. Confirm encryption-at-rest ownership at the database/storage/platform layer.
Step 2 Failure signatures and limits Narrow the fault
Failures include broad shared accounts, forgotten host/database-specific grants, plaintext or weakly validated TLS, credentials in scripts, privilege accumulation, audit gaps and assuming storage encryption prevents privileged database reads.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
No shared superuser accounts for apps. Restrict network access (pg_hba.conf, bind-address, firewall). Require TLS. Audit privileged actions. Patch regularly.
\du— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
ReferenceWhat it is1 section · depth on demand
Operating model
Database Security covers engine-facing authentication, authorization, roles/grants, encrypted transport and auditing. Least privilege should be expressed through stable roles and narrowly scoped grants; TLS protects connections but does not by itself secure stored data, credentials or application authorization.
ReferenceHow it works1 section · depth on demand
In depth
Database security protects data through authentication, authorisation, encryption, auditing and secure configuration. Databases often hold the organisation's most sensitive data, and application vulnerabilities such as SQL injection target them directly.
| Area | Practice |
|---|---|
| Network | Not reachable from the internet; firewall to application servers only |
| Authentication | Strong methods (SCRAM, Kerberos/AD), no default accounts |
| Authorisation | Separate least-privilege accounts per application; no app using superuser |
| Encryption | TLS in transit; encryption at rest (TDE, disk) with protected keys |
| Auditing | Log privileged actions, logins and access to sensitive tables |
| Patching | Track and apply security updates |
| Data minimisation | Masking in non-production copies |
-- PostgreSQL: application role with only needed rights
CREATE ROLE app_rw LOGIN PASSWORD '...';
GRANT CONNECT ON DATABASE appdb TO app_rw;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA app TO app_rw;
ReferenceImportant terms & boundaries1 section · depth on demand
Scope map
- Authentication
- Least privilege
- Roles/grants
- TLS transport
- Credential/secret handling boundaries
- Auditing
- Encryption-at-rest responsibility boundaries
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Configuration & expected output
Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.
Configuration example
Assumptions: Schema public holds the application tables.
CREATE ROLE report_ro LOGIN PASSWORD NULL; -- set via \password or SCRAM secret
GRANT CONNECT ON DATABASE app TO report_ro;
GRANT USAGE ON SCHEMA public TO report_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO report_ro;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO report_ro;Expected output
SELECT grantee, privilege_type FROM information_schema.role_table_grants WHERE grantee = 'report_ro' AND table_name = 'orders';Expected state: The role has SELECT only on application tables.
grantee | privilege_type
-----------+----------------
report_ro | SELECT
(1 row)ALTER DEFAULT PRIVILEGES covers tables created later by the same owner; without it, new tables are not readable by the role. Illustrative authored output: field layout matches the tool, values will differ in your environment.Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Documentation verification: confirms the upstream model used by the Topic. It does not assert local production behavior.
Basis: https://www.postgresql.org/docs/current/client-authentication.html · confidence 92%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Database Security verification boundary matrix
A compact lookup separating intent, owning component state, effective state and consumer-visible outcome for Database Security.
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Authentication | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Least privilege / Roles/grants | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | TLS transport | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Credential/secret handling boundaries | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Deep reference
Design & tradeoffs
Scope
Security owns organizational identity/crypto policy. Databases owns engine accounts, grants, connection security and audit behavior; secret stores remain in Security/Automation as appropriate.