Skip to content
Platform

从 Heroku 迁移到 Supabase

Migrate your Heroku Postgres database to Supabase.

Supabase 是最好的 Heroku Postgres 免费替代方案 之一。这个指南演示了如何将你的 Heroku Postgres 数据库迁移到 Supabase。这个迁移需要使用 pg_dumppsql 命令行工具,它们会作为完整 Postgres 安装包的一部分自动安装。

🌐 Supabase is one of the best free alternatives to Heroku Postgres. This guide shows how to migrate your Heroku Postgres database to Supabase. This migration requires the pg_dump and psql CLI tools, which are installed automatically as part of the complete Postgres installation package.

或者,使用 Heroku 到 Supabase 迁移工具 来几次点击就完成迁移。

🌐 Alternatively, use the Heroku to Supabase migration tool to migrate in a few clicks.

快速演示 #

🌐 Quick demo

获取你的 Heroku 数据库凭证 #

🌐 Retrieve your Heroku database credentials [#retrieve-heroku-credentials]

  1. 登录你的 Heroku 账户 并选择你想要迁移的项目。
  2. 在菜单中点击 资源,然后选择你的 Heroku Postgres 数据库。
  3. 在菜单中点击设置
  4. 点击 查看凭证 并保存以下信息:
    • 主机 ($HEROKU_HOST)
    • 数据库($HEROKU_DATABASE
    • 用户($HEROKU_USER
    • 密码($HEROKU_PASSWORD

获取你的 Supabase 连接字符串 #

🌐 Retrieve your Supabase connection string [#retrieve-supabase-connection-string]

  1. 如果你是 Supabase 新手,创建一个项目
  2. 通过点击你的项目仪表板上的 连接 获取你项目的 Session 池连接字符串。
  3. 在连接字符串中将 [YOUR-PASSWORD] 替换为你的数据库密码。如果你没有密码,可以在 数据库设置页面 重置你的数据库密码。

将你的 Heroku 数据库导出到一个文件 #

🌐 Export your Heroku database to a file [#export-heroku-database]

使用 pg_dump 和你的 Heroku 凭证将 Heroku 数据库导出到一个文件(例如,heroku_dump.sql)。

🌐 Use pg_dump with your Heroku credentials to export your Heroku database to a file (e.g., heroku_dump.sql).

1
pg_dump --clean --if-exists --quote-all-identifiers \
2
-h $HEROKU_HOST -U $HEROKU_USER -d $HEROKU_DATABASE \
3
--no-owner --no-privileges > heroku_dump.sql

将数据库导入到你的 Supabase 项目中 #

🌐 Import the database to your Supabase project [#import-database-to-supabase]

使用 psql 将 Heroku 数据库文件导入到你的 Supabase 项目中。

🌐 Use psql to import the Heroku database file to your Supabase project.

1
psql -d "$YOUR_CONNECTION_STRING" -f heroku_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.

企业 #

🌐 Enterprise

联系我们 如果你在迁移项目时需要更多帮助。