Pcornel
Browse topics
Options
Recent
Favorites
Databases · Technical reference

Database Security

Direct answer

Database security: authentication, least-privilege roles, network restrictions, TLS in transit, encryption at rest, auditing and patching.

When to use this

Use it when hardening a database or reviewing access.

First 30 seconds

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.

Operational verification

network filter → authentication → authorisation (roles/grants) → audit

Evidence · next step

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
Common mistakes
What not to infer

Security owns organizational identity/crypto policy. Databases owns engine accounts, grants, connection security and audit behavior; secret stores remain in Security/Automation as appropriate.

Platform / version applicability
MariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformMariaDB / MySQL / PostgreSQL / Microsoft SQL Server concepts · Security owns organizational identity/crypto policy. Databases owns engine accounts, grants, connection security and audit behavior; secret stores remain in Security/Automation as appropriate.
Scope / prerequisiteUse it when hardening a database or reviewing access.
What next?3 suggested next steps
Child topics (this level)2
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

test · 1
Drill down

Subtopics

Go one level deeper into this subject.

Key points

No shared superuser accounts for apps. Restrict network access (pg_hba.conf, bind-address, firewall). Require TLS. Audit privileged actions. Patch regularly.

Key checks
  • \du — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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.

AreaPractice
NetworkNot reachable from the internet; firewall to application servers only
AuthenticationStrong methods (SCRAM, Kerberos/AD), no default accounts
AuthorisationSeparate least-privilege accounts per application; no app using superuser
EncryptionTLS in transit; encryption at rest (TDE, disk) with protected keys
AuditingLog privileged actions, logins and access to sensitive tables
PatchingTrack and apply security updates
Data minimisationMasking 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
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PostgreSQL PostgreSQL 14 or laterLeast-privilege read-only role for reporting.

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

PostgreSQL PostgreSQL 14 or laterSELECT 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.
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-29 · otherMariaDB / PostgreSQL / Microsoft SQL Server concepts PostgreSQL current documentation

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
database securitydatabase least privilegedatabase TLSSQL grants roles
Embedded reference data

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.

BoundaryInspectHealthy interpretationDo not infer
IntentAuthenticationIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeLeast privilege / Roles/grantsOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateTLS transportIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeCredential/secret handling boundariesThe original bounded check succeeds in the same time windowProduction correctness outside this scope
Depth when you need it

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.

Confirmation

Confirm action

Continue?