Go straight to an AI summary of this blog post instead

  • Summarize this post with Perplexity
  • Summarize this post with Gemini

Key Takeaways

  • PostgreSQL ships with reasonable defaults, but “reasonable” isn’t “production-ready” – authentication, network exposure, and role privileges all need active hardening before you go live.
  • Built-in features like SCRAM-SHA-256, Row-Level Security, and TLS encryption do most of the heavy lifting, but only if you actually turn them on and audit them regularly.
  • For deployments running PostgreSQL 13 past its November 2025 EOL, TuxCare provides ongoing vulnerability patches for as long as needed before you can migrate.

Most PostgreSQL compromises don’t start with a zero-day. They start with a temporary exception – trust authentication left in pg_hba.conf after a late debugging session – that nobody ever takes back out.

PostgreSQL security in 2026 is less about exotic attacks and more about the unglamorous work of keeping configurations tight, patches current, and access boundaries enforced. The embarrassing truth is that most compromises are preventable – they happen because the boring stuff didn’t get done. What follows are the threats actually hitting PostgreSQL deployments right now, the built-in defenses that move the needle, and the hardening steps worth your time.

Why Should PostgreSQL Users Think About Security?

PostgreSQL has a genuinely strong security model — it’s not the problem. The problem is that production-grade security still depends on deliberate configuration: the defaults are tuned to get you running, not to keep you safe under real traffic. Authentication methods, listening addresses, role privileges, logging – all of it needs deliberate configuration. It’s not a flaw in the software; it’s just a gap that every team has to close themselves, and many don’t until something goes wrong.

The threat landscape has also changed in ways that catch teams off guard. Cryptojacking operations now run automated scanners specifically hunting for exposed PostgreSQL instances on port 5432, dropping miners via PL/Python or PL/Perl once they’re in. SQL injection still matters wherever dynamic SQL, extensions, or procedural languages are involved. Separately – and increasingly – supply-chain attacks on your application dependencies can scrape .pgpass files, environment variables, or connection strings before PostgreSQL ever sees a request. And if your organization is subject to PCI DSS, HIPAA, or SOC 2, the question isn’t whether to harden your database – auditors will require it, and they’ll want documented evidence, not just good intentions.

The teams that handle this well treat security debt the same way they treat technical debt – they track it, schedule it, and pay it down incrementally. The ones that don’t tend to find out the hard way, usually at the worst possible time.

Common Security Threats to PostgreSQL

None of the threats below are hypothetical. They’re what’s actively being exploited against PostgreSQL deployments right now – often against teams who genuinely believed they were on top of their security posture.

Infographic outlining common PostgreSQL security threats, including SQL injection, authentication misconfiguration, unpatched CVEs, and supply chain risks.

Threat #1: SQL Injection Through Extensions and Procedural Languages

SQL injection is the oldest attack in the book, but PostgreSQL’s extension ecosystem keeps finding new ways to make it relevant. CVE-2025-1094, disclosed in February 2025, is a good example of how this evolves – it was a flaw in libpq’s quoting functions (PQescapeLiteral, PQescapeIdentifier, and others): they failed to neutralize quoting syntax in text containing invalid byte sequences, so when that output was fed to psql, an attacker could achieve SQL injection. It carried a CVSS score of 8.1, affected all supported versions before 17.3, 16.7, 15.11, 14.16, and 13.19, and – per Rapid7 – was required in every scenario they tested to turn the BeyondTrust flaw (CVE-2024-12356) into remote code execution.

The interesting thing about this CVE is that it wasn’t a novel technique – invalid byte sequence handling has been a known problem class for years. It just hadn’t been found in this specific code path until someone looked hard enough.

CVE-2025-1094 vulnerability details page displaying a high severity CVSS score, vulnerability information, and links to security advisories.

Procedural languages widen the attack surface in a different way. It’s the untrusted procedural languages – PL/Python (which exists only as plpython3u) and plperlu – that can execute arbitrary OS-level code. That’s the feature, not a bug. The catch is the inverse of what people assume: a trusted language like plperl is sandboxed and safe for unprivileged users, while only superusers can create functions in untrusted ones. So the real risk is handing out that ability – or superuser itself – more freely than you think. A 40-person SaaS team running a shared database shouldn’t be handing out CREATE FUNCTION to anyone outside the DBA – but plenty do, because it’s faster than writing proper migration scripts and nobody expects it to matter until it does.

Pro Tip: The remediation isn’t glamorous. Parameterize all queries, restrict who can run CREATE EXTENSION and create functions in untrusted languages, audit your installed extensions on a schedule, and revoke CREATE from any role without a documented operational need for it.

Threat #2: Misconfigured pg_hba.conf

This is the most common own-goal in PostgreSQL security. The host-based authentication file controls who can connect to your database, from where, and via what method. A single misconfigured line can silently open your database to the internet.

Flowchart showing PostgreSQL pg_hba.conf connection rule evaluation, where the first matching authentication rule determines database access.

The two patterns that bite teams hardest:

  • trust authentication left in production after local debugging. With trust, PostgreSQL accepts any username without a password as long as the connection comes from an allowed host.
  • Wildcard host entries (0.0.0.0/0) combined with weak password methods, exposing the database to the internet behind nothing more than a guessable password.

pg_hba.conf is evaluated top-to-bottom and the first matching rule wins. This is the detail that trips people up most: a permissive rule above a strict one doesn’t get overridden – it silently wins, every time, without any error or warning. You end up with a connection that should never have been allowed, and nothing in the logs to tell you why it was.

Note: If your PostgreSQL instance is reachable from anything outside 127.0.0.1 or your private VPC, stop reading and go audit this file first.

Threat #3: Unpatched CVEs

PostgreSQL ships security releases on a predictable schedule – the problem isn’t the releases, it’s the gap between “released” and “applied in production.” CVE-2024-10979, disclosed in November 2024, is a good illustration of the stakes: a high-severity flaw (CVSS 8.8) in PL/Perl allowed unprivileged users to modify environment variables like PATH and achieve arbitrary code execution. Every version before 17.1, 16.5, 15.9, 14.14, 13.17, and 12.21 was affected.

CVE-2024-10979 vulnerability details page displaying a high severity CVSS score, technical information, and links to related security advisories.

That’s six minor-version branches. Plenty of teams were on at least one of them, and plenty are still on one of them today.

Then there’s the end-of-life problem, which is arguably worse. PostgreSQL community support runs for five years per major version. PostgreSQL 12 reached EOL in November 2024, and PostgreSQL 13 followed in November 2025. Both are now running without upstream security patches – no fixes, regardless of severity, unless you upgrade or arrange extended support.

If you’re stuck on either version because of an application dependency or a platform migration that keeps getting pushed, you need a plan. TuxCare provides Endless Lifecycle Support (ELS) specifically for PostgreSQL 13 post-EOL, meaning your deployment keeps receiving security patches while you work through the upgrade.

Threat #4: Cryptojacking via Remote Code Execution

Once an attacker gets RCE on a PostgreSQL host, cryptomining is the path of least resistance. It’s low-risk for them – no data exfiltration to move, no ransomware negotiation to manage – just compute they’re using for free. Automated scanners hunt for exposed instances on port 5432, run credential sprays against the postgres superuser, and on success drop a miner via COPY ... FROM PROGRAM or PL/Python.

Most teams discover it the same way: CPU pegged at 100% on the database host, queries crawling to a halt, someone finally opens htop and sees a process they don’t recognize. By that point the attacker has usually been in for days.

The defenses overlap heavily with general hardening: don’t expose 5432 to the internet, enforce strong authentication on the postgres superuser and other privileged roles, and lock down the features attackers abuse for code execution – restrict COPY ... FROM PROGRAM (already limited to superusers and roles granted pg_execute_server_program) and avoid installing untrusted procedural languages like PL/Python unless you actually need them.

Threat #5: Supply Chain Attacks Through Dependencies

One of the most consequential PostgreSQL risks isn’t a PostgreSQL vulnerability at all – it’s the application layer. Malicious or compromised npm packages have been caught doing exactly what you’d expect: reading environment variables, scraping .pgpass files, and quietly exfiltrating connection strings. Once those credentials are out, your database is the target – regardless of how well PostgreSQL itself is locked down.

PostgreSQL can’t protect against this on its own – the credentials were stolen before they even reached the database. The fix lives in how you manage the boundary between application code and database access: rotate credentials on a schedule, scope each database user to the minimum permissions it actually needs, and use short-lived credentials or secrets management where your stack allows it.

For deeper reading on the dependency side of this problem, TuxCare on transitive dependencies and their SBOMs guide are the right starting points.

Key PostgreSQL Security Features

PostgreSQL gives you the primitives to build a solid security model. The following are the features that actually matter in practice, along with the configuration details that separate “technically enabled” from “actually working.”

Feature #1: Authentication Methods

PostgreSQL supports a long list of authentication methods, but the ones worth using in 2026 are SCRAM-SHA-256, certificate-based authentication, and integration with an external identity provider via LDAP or Kerberos.

SCRAM-SHA-256 became the default value for password_encryption in PostgreSQL 14 — it had been supported and recommended since PostgreSQL 10 — replacing MD5, which has well-documented weaknesses. But here’s the part that often gets missed: upgrading your PostgreSQL version doesn’t automatically migrate your existing password hashes.

Users who set their passwords before the change are still using MD5 under the hood until they reset them. You need to explicitly set password_encryption = scram-sha-256 in postgresql.conf and force a password rotation – and even then, remember that existing passwords stay MD5-hashed until each user resets them. Once a password is stored as a SCRAM hash, an md5 line in pg_hba.conf will automatically authenticate it with SCRAM – so the lingering risk is unreset passwords and unclear config, not the auth line silently winning.

Certificate-based authentication is the strongest option for service-to-service connections. Each client presents a certificate signed by your CA, and PostgreSQL verifies it before accepting the connection. No passwords to leak, no shared secrets in environment variables.

For human users, push toward LDAP or Kerberos integration so you can centralize account management and offboarding. A user who leaves the company should lose database access the same day, automatically.

Feature #2: Role-Based Access Control

PostgreSQL’s role and privilege system is one of the most granular in any open-source database. You can grant privileges on databases, schemas, tables, columns, sequences, functions, and more. You can also create role hierarchies, where one role inherits the privileges of another.

The principle that matters: every role gets the minimum privileges it needs and nothing more. In practice this means application roles that can only SELECT, INSERT, UPDATE, and DELETE on the specific tables they touch – not blanket ALL PRIVILEGES on the whole schema, and definitely not superuser.

A reality check: most teams who think they’re following least privilege actually aren’t. The application connects as a role with broad access “to keep things simple,” and nobody touches it because rebuilding the privilege matrix is tedious. Worth doing anyway.

Feature #3: Row-Level Security

Row-Level Security (RLS) lets you attach policies to tables that filter which rows a given role can see or modify. It’s the right tool for multi-tenant applications, where one database holds data for many customers and you need a strong guarantee that customer A can never see customer B’s rows.

What makes RLS genuinely valuable is that the guarantee lives in the database, not the application. Application-layer filtering can be forgotten, bypassed by a query that doesn’t include the right WHERE clause, or silently broken by an ORM abstraction. RLS enforces the policy server-side for roles subject to it – a buggy query that forgets to filter by tenant_id still won’t leak rows, because PostgreSQL applies the policy before returning results. The caveat that bites people: table owners, superusers, and roles with BYPASSRLS skip policies by default, so make sure your application role is none of those, and use FORCE ROW LEVEL SECURITY where it matters.

The catch is that RLS can be tricky to debug and has performance implications you need to test. Policies are evaluated for every row, and complex policies on large tables can hurt query plans. Test it under realistic load before relying on it.

Feature #4: SSL/TLS Encryption

Data in transit between client and server should be encrypted. PostgreSQL supports TLS, but you have to configure it – it’s not on by default in most installations.

Two settings to get right: ssl = on in postgresql.conf, and hostssl (not host) entries in pg_hba.conf for any connection that should be encrypted. Without the hostssl requirement, clients can still connect over plaintext if they choose to.

For client verification, set sslmode=verify-full on the client side. This makes the client verify both the server certificate and that the hostname matches, defeating man-in-the-middle attacks. sslmode=require alone is not enough — it encrypts the connection but doesn’t verify the server’s identity the way verify-ca or verify-full does, so a network-level attacker can still impersonate the server.Feature #5: Audit Logging and pgAudit

Native PostgreSQL logging captures a lot, but for compliance-grade audit trails you’ll want the pgaudit extension. It logs structured records of every statement executed, by which role, against which objects, with parameters. It makes SOC 2, HIPAA, and PCI DSS evidence far easier to produce – at the cost of significant log volume if you scope it too broadly.

A practical pattern: scope pgAudit’s pgaudit.log parameter to the categories you actually need – typically ddl, role, and read for sensitive tables – rather than enabling blanket logging. Full statement logging on a busy database generates volumes that nobody actually reads, and log storage becomes its own operational headache. Log what your auditors need, route it to your SIEM, and resist the temptation to log everything “just in case.”

Best Practices to Strengthen PostgreSQL Security

Security hardening isn’t a one-time project. It’s an ongoing operational discipline, and the teams that do it well tend to have systems that make the boring stuff automatic. The practices below are where that discipline actually shows up.

1. Apply Patches Promptly

The single factor that most consistently separates compromised PostgreSQL deployments from secure ones is patch latency – the gap between when a CVE is disclosed and when the fix actually lands in production. That window is where attackers operate, and the wider it is, the more exposure you carry.

Apply minor version updates promptly – they contain only security and bug fixes and require nothing more than a service restart. The risk of applying them is almost always lower than the risk of skipping them. The teams that fall behind are usually the ones waiting for a formal maintenance window to justify a two-minute restart.

2. Lock Down pg_hba.conf and Network Access

Treat pg_hba.conf like a firewall rule set. Document every entry. Review it on a schedule – quarterly is reasonable. Remove anything that’s not actively in use.

Specific rules:

  • Use no trust authentication for any TCP connection, including loopback; for local Unix-domain socket connections, prefer peer so the database identity is tied to the operating-system user.
  • Use hostssl instead of host for any non-local connection.
  • Restrict source IPs to specific CIDR ranges. 0.0.0.0/0 is almost never the right answer.
  • Bind PostgreSQL to specific addresses using listen_addresses, not *.

If you’re running in a cloud VPC, layer this with security groups so the database is only reachable from your application tier. Defense in depth – pg_hba.conf is one layer, network ACLs are another.

3. Audit Roles, Privileges, and Extensions Regularly

Role sprawl happens to every long-lived database. Someone needs temporary superuser access for a migration. The grant never gets revoked. Multiply that by years and you have a privilege graph that nobody fully understands.

Run a quarterly review:

  • List all roles and their privileges using \du+ and the information_schema.role_table_grants view.
  • Identify roles that haven’t logged in within the last 90 days. Disable them, or at minimum require justification to keep.
  • List installed extensions with SELECT * FROM pg_extension. Anything not in active use is a risk surface for no benefit.
  • Check for roles with SUPERUSER, CREATEDB, or CREATEROLE. Each one needs a documented reason to exist.

The goal isn’t perfection. It’s making sure your privilege model reflects what you actually need today, not what you needed two years ago.

Tools to Strengthen PostgreSQL Security

The tools below cover the main gaps in a default PostgreSQL deployment: patching, auditing, scanning, and compliance reporting. No single tool does all of it well, so most teams end up running a combination.

Tool #1: TuxCare

PostgreSQL 13 reached end of life in November 2025, and PostgreSQL 12 before it in November 2024. Both versions are now running without upstream security patches – meaning no fixes from the community, regardless of severity, until you upgrade.

For teams that can’t upgrade immediately – because of application dependencies, third-party integrations, or migration complexity – TuxCare’s Endless Lifecycle Support for PostgreSQL 13 keeps those deployments receiving security patches while a proper migration is planned. That’s a meaningfully different position than running unpatched and hoping nothing critical drops before you’re ready.

The practical case for ELS is straightforward: a rushed major version upgrade under pressure from a critical CVE is exactly the kind of situation that causes outages. ELS buys you time to do the migration properly.

Tool #2: pgAudit

pgAudit is the de facto extension for compliance-grade audit logging in PostgreSQL. It produces structured log entries that map cleanly to what SOC 2, HIPAA, and PCI DSS auditors want to see. Configuration is straightforward but the log volume can balloon fast – plan for storage and shipping to a SIEM rather than letting logs accumulate locally.

It’s free, maintained, and widely deployed. The tradeoff is that it logs and nothing more. You still need a separate system to actually analyze the logs and alert on anomalies. Pair it with whatever SIEM your security team already runs.

Tool #3: pg_stat_statements + Prometheus Exporters

Not a security tool in name, but pg_stat_statements plus a Prometheus exporter (like postgres_exporter) gives you the query-level visibility needed to spot abuse patterns. Sudden spikes in COPY statements, queries against system catalogs from application roles, or unusual connection counts from new IPs are all signals worth alerting on.

It’s the cheap version of a database activity monitoring solution. Not as polished as a dedicated DAM tool, but free, lightweight, and good enough for most teams who can’t justify enterprise pricing.

Tool #4: Vulnerability Scanners

For environments where PostgreSQL runs on Linux hosts you control, vulnerability scanners catch known CVEs in your PostgreSQL binaries and dependencies. Most scanners tell you what’s vulnerable but struggle with remediation validation – they’ll flag a CVE as open even after it’s been fixed via a backport, which creates noise and erodes trust in the output.

Strengthen PostgreSQL Security with TuxCare

PostgreSQL security isn’t a project with a completion date – it’s an ongoing operational discipline. CVEs keep coming, configurations drift, roles accumulate permissions they shouldn’t have, and EOL deadlines arrive whether you’re ready for them or not. The teams that stay ahead aren’t doing anything heroic. They’ve built systems that make routine security work visible, repeatable, and hard to let slip – so the next CVE or EOL date is a scheduled task, not a fire drill.

For teams running PostgreSQL 13 past its November 2025 EOL, TuxCare’s Endless Lifecycle Support keeps security patches coming while a migration is planned on a realistic timeline – not a crisis one forced by the next critical CVE.

FAQs

Is PostgreSQL secure by default after installation?

No. PostgreSQL ships with sensible starting defaults, but several settings that matter for production – TLS, restrictive pg_hba.conf rules, strong authentication methods, audit logging – require explicit configuration. A default install on a public-facing server is not a secure install. Always harden before it sees real traffic.

What is the biggest security mistake PostgreSQL admins make?

Leaving trust authentication in pg_hba.conf after debugging. It’s the most common cause of accidentally public databases. Close behind: granting application roles too many privileges because writing a precise privilege model is tedious.

How does PostgreSQL handle encryption?

PostgreSQL supports TLS for data in transit (configured via ssl = on and hostssl entries in pg_hba.conf) and offers pgcrypto for column-level encryption of data at rest. Full transparent disk encryption is handled at the filesystem or volume level, not by PostgreSQL itself.

How do I know if my PostgreSQL version has known vulnerabilities?

Check the official PostgreSQL security page at postgresql.org/support/security, run a vulnerability scanner against your binaries, and subscribe to the pgsql-announce mailing list. Any version older than the latest minor release in your major version branch is missing fixes.

Is upgrading PostgreSQL always the best way to fix vulnerabilities?

Minor version upgrades (e.g., 15.9 to 15.11) are usually safe and contain only security and bug fixes. Major version upgrades (e.g., 14 to 16) involve breaking changes and need real testing. If you’re on an EOL major version and a major upgrade isn’t feasible, extended support is the practical alternative.

 

Summary
PostgreSQL Security 2026: Risks, Solutions & Best Practices
Article Name
PostgreSQL Security 2026: Risks, Solutions & Best Practices
Description
Learn how to secure your PostgreSQL database with best practices for authentication, access control, encryption, auditing, and patching in 2026.
Author
Publisher Name
TuxCare
Publisher Logo

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.

Table of Contents
Get the open-source security answers you need

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.