# 3.在未启用 WAL 的情况下运行

{% hint style="success" %}
对应的[官方页面地址](https://github.com/dani-garcia/vaultwarden/wiki/Running-without-WAL-enabled)
{% endhint %}

{% hint style="warning" %}
WAL 是专用于 SQLite 的设置，它在 Postgres 或 MySQL 上不起作用；如果您使用这些后端之一，则 `ENABLE_DB_WAL` 配置选项无效。
{% endhint %}

默认情况下，`vaultwarden` 在启动期间将尝试为数据库启用 [WAL](https://sqlite.org/wal.html)。添加此功能可以提高性能，并且在某些情况下有助于避免请求失败。

## 关闭 WAL 的原因 <a href="#reasons-to-turn-wal-off" id="reasons-to-turn-wal-off"></a>

一般而言，除非您相当确定需要关闭 WAL，否则应将其保持为启用状态。但是，可能有一些情况需要将其关闭，比如：

* 某些文件系统不支持 WAL（对于网络文件系统尤其如此）。如果您使用的是这样的文件系统，该服务将无法启动并显示 `Failed to turn on WAL` 错误。
* （要启用 WAL）数据库要求 sqlite 的版本为 `3.7.0` 或更高，因此，出于某种原因（例如备份）您需要使用无法更新的低版本工具来直接访问数据库，此时也需要禁用 WAL。
* 某个[这里描述的缺陷](https://sqlite.org/wal.html#advantages)也会影响您（不得不禁用 WAL）。

## 关闭 WAL 的步骤 <a href="#how-to-turn-wal-off" id="how-to-turn-wal-off"></a>

### 0、执行备份 <a href="#id-0-make-backup" id="id-0-make-backup"></a>

这些更改通常是安全的，可以顺利完成并且不会丢失数据，但是强烈建议在进行任何更改之前[备份您的数据](/backup/backing-up-your-vault.md)。

### 1、在低版本数据库上禁用 WAL <a href="#id-1-disable-wal-on-old-db" id="id-1-disable-wal-on-old-db"></a>

如果您使用启用了 WAL 的低版本数据库，则需要使用 sqlite 来禁用它：

1）停止 `vaultwarden`

2）定位您的[数据文件夹](/other-information/changing-persistent-data-location.md)。除非您指定了其他名称，否则这里通常会有一个名为 `db.sqlite3` 的文件。

3）使用 sqlite 打开此文件：

```sql
sqlite3 db.sqlite3
```

4）键入 `PRAGMA journal_mode=delete;` 并按 Enter，以禁用 WAL：

```sql
sqlite> PRAGMA journal_mode=delete;
delete
```

5）键入 `.quit` 并按回车退出 sqlite 实用程序（注意前面的点）。

### 2、在 `vaultwarden` 中禁用 WAL <a href="#id-2-disable-wal-in-vaultwarden" id="id-2-disable-wal-in-vaultwarden"></a>

要关闭 WAL，您需要通过将 `ENABLE_DB_WAL` 变量的值设置为 `false` 来启动 `vaultwarden`。

```shell
docker run -d --name vaultwarden \
  -e ENABLE_DB_WAL=false \
  -v /vw-data/:/data/ \
  -p 80:80 \
  vaultwarden/server:latest
```

确保在启动前始终使用了此变量，否则一旦没有此变量将会再次启用 WAL（如果发生这种情况，请从[第 1 步](#1-disable-wal-on-old-db)开始再次禁用它）。

## 如何开启 WAL <a href="#how-to-turn-wal-on" id="how-to-turn-wal-on"></a>

通常来说，只要您在未将 `ENABLE_DB_WAL` 变量的值设置为 `false` 的情况下启动 `vaultwarden`，服务器将自动为您启用 WAL。您可以通过运行以下命令进行验证：

```sql
sqlite3 db.sqlite3 'PRAGMA journal_mode'
```

`db.sqlite3` 是 `vaultwarden` 所使用的数据库文件。此命令将报告当前使用的模式，在我们的例子中将返回 `wal`。如果已禁用 WAL，默认通常返回 `delete` 。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rs.ppgg.in/configuration/database/running-without-wal-enabled.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
