Skip to main content

备份

概述

¥Overview

专业版和商业版 上,Prisma Postgres 会自动创建数据库快照,以支持恢复和备份工作流。导航到 中 Prisma Postgres 实例的“备份”选项卡,以查看并重新实例化可用的备份。

¥On Pro and Business plans, Prisma Postgres automatically creates snapshots of your database to support recovery and backup workflows. Navigate to the Backups tab of your Prisma Postgres instance in the to view and re-instantiate your available backups.

快照每天创建,但仅在数据库有活动的日子创建。根据你的套餐,你将看到不同数量的可用快照:

¥Snapshots are created daily, but only on days when the database has activity. Depending on your plan, you will see a different number of available snapshots:

计划快照保留
专业版过去 7 天
商业最后 30 天

请注意,在最新快照之后发生的任何数据库更改或事件都可能无法恢复。

¥Please note that any database changes or events that occurred after the most recent snapshot may not be restored.

有关备份可用性和套餐特定功能的更多详细信息,请访问我们的 定价页面

¥For more details about backup availability and plan-specific features, visit our pricing page.

注意

未来,Prisma Postgres 将根据用户特定的配置提供更细粒度的备份机制,并具有时间点恢复功能。

¥In the future, Prisma Postgres will provide more fine-grained backup mechanisms based on user specific configurations and with point-in-time restore functionality.

通过 pg_dump 手动创建备份文件

¥Manually creating a backup file via pg_dump

如果你想创建数据库的备份文件,可以使用 pg_dump 并使用 直接连接。这对于在数据库之间迁移数据或创建数据库的本地副本非常有用。

¥If you would like to create a backup file of your database, you can use pg_dump and use a direct connection. This is useful for migrating data between databases or creating a local copy of your database.

先决条件

¥Prerequisites

开始之前,请确保你已具备:

¥Before you begin, make sure you have:

  • 已安装 Node.js(版本 16 或更高版本)。

    ¥Node.js installed (version 16 or higher).

  • 用于创建备份的 PostgreSQL CLI 工具 (pg_dump)。请使用 Postgres 版本 17,因为 Prisma Postgres 基于此版本。

    ¥PostgreSQL CLI Tools (pg_dump) for creating backups. Use Postgres version 17 as Prisma Postgres is based on this version.

  • Prisma Postgres 数据库的直接连接字符串。

    ¥A direct connection string for your Prisma Postgres database.

1. 安装 PostgreSQL 命令行工具

¥ Install PostgreSQL command-line tools

要创建备份,请确保你已安装 PostgreSQL 命令行工具。根据你的操作系统运行以下命令:

¥To create backups, ensure you have the PostgreSQL command-line tools installed. Run the following commands based on your operating system:

brew install postgresql@17
which pg_dump
which pg_restore
提示

如果你安装了 PostgreSQL,但仍看到 pg_dumppg_restore 的“找不到命令”错误,请确保你的安装目录位于系统的 PATH 环境变量中。

¥If you installed PostgreSQL but still see a “command not found” error for pg_dump or pg_restore, ensure your installation directory is in your system’s PATH environment variable.

2. 使用 pg_dump 创建备份

¥ Creating the Backup with pg_dump

按照 此处 说明获取 Prisma Postgres 的直接连接字符串。

¥Get your direct connection string for Prisma Postgres by following the instructions here.

现在,你可以通过运行以下命令并使用你自己的连接字符串来转储数据库:

¥You can now dump the database by running the following command and using your own connection string:

pg_dump --dbname="postgres://USER:PASSWORD@postgres.prisma-data.net:5432/?sslmode=require" > ./mydatabase.bak

这将在当前目录中创建名为 mydatabase.bak 的备份文件。

¥This will create your backup file named mydatabase.bak in the current directory.