> For the complete documentation index, see [llms.txt](https://nats.golang.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nats.golang.im/nats-streaming-server/configuring/persistence.md).

# 持久化

NATS Streaming Server默认使用内存来存储状态，这意味着一旦服务停止，所有的状态都丢失了。当服务重启时，因为没有可以用于恢复的连接信息，运行中的应用程序将会停止接收消息并且新发送的消息将会被拒绝并返回`invalid publish request` 错误。支持并且设置了`Connection Lost` handler (详情查看关于[连接状态](https://github.com/nats-io/stan.go#connection-status)的文档) 的客户端将会收到连接丢失的错误`client has been replaced or is no longer registered`。

话虽如此，这种级别的持久性已经允许应用重启后继续消费之前的消息,避免应用程序因为连接断开(网络或者程序崩溃导致)而丢失消息。

* [文件存储](/nats-streaming-server/configuring/persistence/file_store.md)
* [SQL 存储](/nats-streaming-server/configuring/persistence/sql_store.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://nats.golang.im/nats-streaming-server/configuring/persistence.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.
