# Log Every Query in Local Development

> How to log every SQL statement in local PostgreSQL and MySQL, which settings to use, what it costs, and how to switch it off again safely.

Source: https://sqleye.com/blog/log-every-query-in-local-development/ · Published: 2026-11-10 · Last updated: 2026-11-29 · Publisher: CodeROG (https://coderog.com)

To log every query in local development, set PostgreSQL's `log_min_duration_statement` to `0` and reload the configuration, or switch on MySQL's general query log with `SET GLOBAL general_log = 'ON'`. Both take effect without restarting the server. Switch them off again afterwards, because logging every statement costs disk writes and the files grow quickly.

This guide follows the PostgreSQL "current" documentation and the MySQL 8.4 reference manual.

## How do I log every statement in PostgreSQL?

PostgreSQL has two relevant settings. They behave differently:

| | `log_statement = 'all'` | `log_min_duration_statement = 0` |
|---|---|---|
| What it logs | The text of every statement (values: `none`, `ddl`, `mod`, `all`; default `none`). | The duration of every completed statement (default `-1`, which is off). |
| When | As the statement is received, before it finishes. | After the statement completes. |
| Duration included | No. | Yes. |
| Failed statements | Logged, except those with simple syntax errors. | Only statements that complete are logged. |

When both are on, the statement text logged because of `log_statement` is not repeated in the duration message. You then get two lines per statement, linked only by process ID, which is why the PostgreSQL documentation recommends including the PID or session ID in `log_line_prefix`. For a dev log, `log_min_duration_statement = 0` alone is usually the simpler choice: one entry per statement, with its duration.

With the extended query protocol (what most drivers use for parameterised queries), the durations of the Parse, Bind and Execute steps are logged independently.

Both settings can be changed at runtime by a superuser or a user with the appropriate `SET` privilege, so you can also set them for one session:

```sql
SET log_min_duration_statement = 0;
```

### Make it server-wide and reload

1. Write the setting with `ALTER SYSTEM`, which stores it in `postgresql.auto.conf`:

   ```sql
   ALTER SYSTEM SET log_min_duration_statement = 0;
   ```

2. Reload the configuration. No restart is needed for this parameter:

   ```sql
   SELECT pg_reload_conf();
   ```

3. When you are done, remove the override and reload again:

   ```sql
   ALTER SYSTEM RESET log_min_duration_statement;
   SELECT pg_reload_conf();
   ```

`ALTER SYSTEM` cannot run inside a transaction block. Alternatively, edit `postgresql.conf` and reload with `pg_ctl reload`.

### Where do the lines go, and in what format?

By default PostgreSQL logs to stderr. The documentation describes stderr as suitable only for low log volumes, and logging every statement is not low volume. The usual answer is the logging collector:

- `logging_collector` can only be set at server start, so enabling it needs a restart.
- `log_destination = 'jsonlog'` writes structured JSON log entries, which are easy to parse with a program. It requires the logging collector, and it exists since PostgreSQL 15.
- `log_directory`, `log_filename`, `log_rotation_age`, `log_rotation_size` and `log_truncate_on_rotation` control where files go and how they rotate. They are set in `postgresql.conf` or on the command line.

A pattern from the PostgreSQL documentation keeps seven days of logs, one file per weekday: `log_filename = 'server_log.%a'`, `log_truncate_on_rotation = on`, `log_rotation_age = 1440`.

## How do I log every statement in MySQL?

MySQL's general query log is disabled by default. It records client connects and disconnects and each SQL statement received, in the order received (which can differ from execution order). It is global and dynamic, so no restart is needed:

```sql
SET GLOBAL log_output = 'FILE';
SET GLOBAL general_log_file = '/tmp/mysql-general.log';
SET GLOBAL general_log = 'ON';
```

`log_output` accepts `TABLE`, `FILE` or `NONE`. Statements are written to the file only if `log_output` contains `FILE`; with `NONE`, nothing is written even though the log is on. If you do not set `general_log_file`, the default name is `host_name.log` in the data directory.

To switch it off:

```sql
SET GLOBAL general_log = 'OFF';
```

To rotate the file, rename it and flush: `mv` the file, then run `mysqladmin flush-logs general`. Restarting the server does not create a new file. Plain-text passwords in logged statements are rewritten by the server, and statements that fail to parse are not logged.

### The performance_schema alternative

If you want to read recent statements with SQL instead of a file, use the Performance Schema. `events_statements_history_long` holds the most recent ended statements across all threads, and its consumer is disabled by default. Enable it at runtime:

```sql
UPDATE performance_schema.setup_consumers
SET ENABLED = 'YES'
WHERE NAME = 'events_statements_history_long';

SELECT SQL_TEXT, TIMER_WAIT / 1e12 AS seconds, ROWS_EXAMINED
FROM performance_schema.events_statements_history_long
ORDER BY TIMER_START DESC
LIMIT 20;
```

Timer columns are in picoseconds, hence the division. Two limits matter: the table is a fixed-size window (its size, `performance_schema_events_statements_history_long_size`, can only be set at server startup), and `SQL_TEXT` is cut at `performance_schema_max_sql_text_length`, 1024 bytes by default, also a startup-only setting.

## What does logging every query cost?

Every statement becomes a log write, so you get more disk I/O and files that grow with traffic. Logged statements can also contain sensitive data: the PostgreSQL documentation warns they may include plaintext passwords. This is why logging all statements is something to do on a development database, deliberately and temporarily, and not by default on a shared or production server. If you keep it on for long, rotate and cap the files as shown above.

## How SQLEye helps

SQLEye is unreleased and still in development; there is no download yet. Its Live Eye feature automates the setup described above. Capture is per instance and off by default. For PostgreSQL it sets `log_min_duration_statement` to 0, uses `jsonlog` with a rotated log (daily or at 32 MB, with weekday-named files that are truncated on rotation), and applies the change with `pg_reload_conf()`, with no restart. For MySQL it uses the Performance Schema statement history instead of a log file. Turning capture off restores the server's normal configuration, and it states plainly that capture costs database throughput. Details are on the [Capture](/docs/live-eye/capture/) page; see [Instances and ports](/docs/instances/ports/) for how each instance is isolated.
