从 Neon 迁移到 Supabase
Migrate your existing Neon database to Supabase.
本指南演示了如何将你的 Neon 数据库迁移到 Supabase,从而充分利用 Postgres 的优势,同时获取构建项目所需的所有功能。
🌐 This guide demonstrates how to migrate your Neon database to Supabase to get the most out of Postgres while gaining access to all the features you need to build a project.
获取你的 Neon 数据库凭证 #
🌐 Retrieve your Neon database credentials [#retrieve-credentials]
- 登录你的 Neon 控制台 https://console.neon.tech/login。
- 在左边选择项目。
- 在列表中点击你的项目。
- 在你的项目仪表板中找到你的连接字符串,然后点击复制片段将其复制到剪贴板(不要勾选“连接池”)。
示例:
🌐 Example:
1postgresql://neondb_owner:xxxxxxxxxxxxxxx-random-word-yyyyyyyy.us-west-2.aws.neon.tech/neondb?sslmode=require设置你的 OLD_DB_URL#
🌐 Set your OLD_DB_URL environment variable
在命令行中使用你从剪贴板获取的 Neon 数据库凭证设置 OLD_DB_URL 环境变量。
🌐 Set the OLD_DB_URL environment variable at the command line using your Neon database credentials from the clipboard.
示例:
🌐 Example:
1export OLD_DB_URL="postgresql://neondb_owner:xxxxxxxxxxxxxxx-random-word-yyyyyyyy.us-west-2.aws.neon.tech/neondb?sslmode=require"获取你的 Supabase 连接字符串 #
🌐 Retrieve your Supabase connection string [#retrieve-supabase-connection-string]
- 如果你是 Supabase 新手,先创建一个项目。记下你的密码,以后会用到。如果忘记了,可以在这里重置。
- 在你的项目仪表板上,点击 连接
- 在会话池下,点击连接字符串右侧的 复制 按钮,将其复制到剪贴板。
设置你的 NEW_DB_URL#
🌐 Set your NEW_DB_URL environment variable
在命令行中使用你的 Supabase 连接字符串设置 NEW_DB_URL 环境变量。你需要把 [YOUR-PASSWORD] 替换成你实际的数据库密码。
🌐 Set the NEW_DB_URL environment variable at the command line using your Supabase connection string. You will need to replace [YOUR-PASSWORD] with your actual database password.
示例:
🌐 Example:
1export NEW_DB_URL="postgresql://postgres.xxxxxxxxxxxxxxxxxxxx:[YOUR-PASSWORD]@aws-0-us-west-1.pooler.supabase.com:5432/postgres"迁移数据库 #
🌐 Migrate the database
你将需要 pg_dump 和 psql 命令行工具,这些工具包含在完整的 Postgres 安装 中。
🌐 You will need the pg_dump and psql command line tools, which are included in a full Postgres installation.
-
在控制台把你的数据库导出到文件
使用
pg_dump和你的 Postgres 凭据将数据库导出到一个文件(例如,dump.sql)。
1pg_dump "$OLD_DB_URL" \2 --clean \3 --if-exists \4 --quote-all-identifiers \5 --no-owner \6 --no-privileges \7 > dump.sql-
把数据库导入到你的 Supabase 项目里
使用
psql将 Postgres 数据库文件导入到你的 Supabase 项目中。1psql -d "$NEW_DB_URL" -f dump.sql
更多选项
🌐 Additional options
- 如果只想迁移一个数据库模式,在你的
pg_dump命令中添加--schema=PATTERN参数。 - 要排除一个模式:
--exclude-schema=PATTERN。 - 只迁移一个表:
--table=PATTERN。 - 要排除一个表:
--exclude-table=PATTERN。
运行 pg_dump --help 查看完整选项列表。
🌐 Run pg_dump --help for a full list of options.
- 如果你打算迁移一个大于6 GB的数据库,我们建议至少升级到大型计算附加组件。这样可以确保你拥有处理迁移所需的资源。
- 我们强烈建议你提前准备好迁移所需的磁盘空间。在付费项目中,你可以通过前往基础设施设置页面来操作。想了解更多关于磁盘扩展和磁盘限制的信息,可以查看我们的磁盘设置文档。
企业 #
🌐 Enterprise
联系我们 如果你在迁移项目时需要更多帮助。