Postgres 迁移记录
环境
运行在本地的 Postgres 容器,名称为 lobe-postgres,用户名是 postgres
命令
列出所有数据库
1 | docker exec lobe-postgres psql -U postgres -c "\l" |
列出数据库中的所有表
1 | # 进入容器 |
使用 pg_dump 导出数据库
1 | docker exec lobe-postgres pg_dump -U your_username -d your_database > backup.sql |
将 backup 文件复制到目标容器
1 | docker cp backup.sql target_postgres_container:/backup.sql |
创建新数据库并导入数据
1 | docker exec -it target_postgres_container psql -U postgres -c "CREATE DATABASE new_database;" |
- Title: Postgres 迁移记录
- Author: SimpleMaxR
- Created at : 2024-10-02 10:57:26
- Updated at : 2025-02-11 12:15:45
- Link: https://www.hgzre.tech/2024/10/02/Postgres-迁移记录/
- License: This work is licensed under CC BY-NC-SA 4.0.
Comments