<!-- Source: @site/projects/sqlens-for-laravel/docs/rules/sec-cfg-statement-logging.md -->
<!-- Canonical: https://docs.pushery.com/sqlens-for-laravel/rules/sec-cfg-statement-logging/ -->

# SEC.CFG.STATEMENT_LOGGING — Statements and their values are written to the server log

> The same setting is good practice on a laptop and a disclosure in production, so for a value that logs data this rule asks where it is looking.

- **Category:** privacy
- **Severity:** medium
- **Level:** 0
- **Confidence:** deterministic
- **Downtime class:** none — the finding is about a server parameter, not about a statement
- **Stability:** stable
- **Suites:** audit
- **Applies to:** PostgreSQL 18

## What the value means

`log_statement` is an enum with four members, and two of them reach data.

| Value | What is logged | Does it carry row values? |
|---|---|---|
| `none` | nothing | no |
| `ddl` | schema statements | **no** — column names, never rows |
| `mod` | statements that change data | **yes** — every row a migration or job writes |
| `all` | every statement | **yes** — including every `WHERE email = …` |

`ddl` is where the line falls, and the reason is data rather than verbosity: a schema statement
names columns, so it says nothing about a person. `ddl` on a production server is an ordinary audit
trail, and reporting it would train people to ignore this rule.

## Why the log is the problem rather than the setting

Nothing here is a defect. The parameter is doing exactly what it says, and the server is
functioning correctly — which is why this is **reported** rather than prevented.

What changes is where the data lives. A log file rarely enjoys the database's own protection:

- it is read by operators who were never granted the tables it quotes,
- it is shipped to an aggregator that keeps it under a different retention policy,
- and it sits in backups that outlive the row an erasure request removed.

None of those paths involves a privilege on the database. The grant model you designed does not
reach the file.

## Why the environment decides

This is the only rule in the pack whose verdict depends on something outside the database, and it
is the reason the rule exists in this shape rather than as a plain server-baseline check.

`log_statement = all` on a laptop is how people debug. The same value on a production instance is
personal data leaving the database's protection. **The value cannot tell those apart**, so a rule
that judged it alone would be muted within a week by the people it is meant to help.

So the rule reads the value first. `none` and `ddl` are no finding on any server, and a server in
its factory settings needs no answer about its environment. `all` and `mod` are, and for those the
rule establishes the environment and answers three-valued:

| What the run can establish | Answer |
|---|---|
| this is production | a finding |
| this is not production | **pass, with its sentence** — checked, and it exposes nothing here |
| nothing places it | **undetermined**, with the reason named |

That third row is the point. `app.env` unset, or carrying a name this check does not recognize, and
the connection name saying nothing either, is not a reason to report a pass — a pass would be a
statement about a server nobody placed.

`app.env` describes the process that runs the audit, so it is read only for the server that process
is itself configured against: the one its default connection reaches, or the one
`sqlens.security.runtime_connection` names as serving its requests, whichever connection name,
database or role leads there. A pipeline with `APP_ENV=testing` or a laptop with `APP_ENV=local`
pointed at another server says nothing about that server. There, a connection name, database name or
host that marks it as production still places it, `SQLENS_SERVER_LIFETIME=disposable` places it as a server
the pipeline creates and destroys, and anything else is undetermined. For a verdict about a remote
server, run the audit where its application runs.

## Why medium and not higher

The data is inside your own infrastructure. This is exposure to a wider circle than the database
grants, not exposure to the public.

Medium also sits below the CI gate's `high` default, so an honest finding does not block a pipeline
that never opted into privacy gating.

## What it looks like

```ini
# postgresql.conf: every statement and every parameter value, written to the server log.
log_statement = all
```

## What to do about it

```ini
# Schema statements carry column names, never row values — an audit trail without the data.
log_statement = ddl
```

`log_statement` takes effect on a configuration reload; no restart is needed. Its context is
`superuser`, so a session may also set it for itself — which is why this rule judges what a fresh
session resets to rather than what the audit's own connection is running with.

## What this rule cannot see

Who can read the log, where it is shipped, how long it is kept, and whether anything redacts it on
the way. Those are questions about the host rather than about the server's catalog, and this
finding does not claim them.

It also cannot tell a server deliberately logging everything during an incident from a switch left
on afterwards. That is the honest limit of a value read at one moment.

<!-- BEGIN generated: remediation -->
## The fix material this rule carries

A finding from this rule carries a payload whose strategy is `none`: this rule has looked,
and there is no safe standard sequence. That is a conclusion rather than an omission — a
finding with no payload at all says only that nobody wrote one.

The payload is material for you or an agent to apply. SQLens writes no migration and runs no
DDL. See [the remediation payload](https://docs.pushery.com/sqlens-for-laravel/remediation-schema.md) for every field, the placeholder
semantics, and the version rules a consumer has to follow.
<!-- END generated: remediation -->
