【OCI云迁移指南】 尝试将Amazon RDS for PostgreSQL迁移到OCI Database with PostgreSQL
OCI云迁移指南是什么?
这是由云工程师(@araidon, @kazunishi, @yama6)组成的团队,他们致力于从本地环境或AWS等多个平台向Oracle Cloud Infrastructure进行迁移的项目。本系列文章总结了OCI迁移的步骤。每一篇文章都会针对一个样本工作负载,介绍相应的迁移步骤。下面是总结文章。
服务迁移:亚马逊RDS用于PostgreSQL
本次迁移的目标是Amazon RDS for PostgreSQL。
我们将使用PostgreSQL客户端应用程序pg_dump和pg_restore,将RDS for PostgreSQL的数据库迁移到OCI带有PostgreSQL的数据库。
转型形象

前提条件 (qian2 ti2 tiao2 jian4)
-
- AWSとOCI、それぞれに接続するための踏み台・作業用サーバがパブリックサブネット上に構築されていること。
- OCI Database with PostgreSQLが構築済みなこと。
OCI数据库与PostgreSQL是在2023年11月15日刚刚发布的服务。
希望您可以参考下面搭建的文章。
操作验证数据库
在本博客中,我们将使用以下网站提供的dvdrental数据库来确认迁移前后的表内容。
在Amazon RDS for PostgreSQL上的操作确认结果。
关系列表
结构 | 名称 | 类型 | 所有者
——–+—————+——-+———-
公共 | 演员 | 表格 | postgres
公共 | 地址 | 表格 | postgres
公共 | 类别 | 表格 | postgres
公共 | 城市 | 表格 | postgres
公共 | 国家 | 表格 | postgres
公共 | 客户 | 表格 | postgres
公共 | 电影 | 表格 | postgres
公共 | 电影_演员 | 表格 | postgres
公共 | 电影_类别 | 表格 | postgres
公共 | 库存 | 表格 | postgres
公共 | 语言 | 表格 | postgres
公共 | 付款 | 表格 | postgres
公共 | 租赁 | 表格 | postgres
公共 | 员工 | 表格 | postgres
公共 | 商店 | 表格 | postgres
(15 行)
DVD租赁=> 选择*从演员限制20;
演员ID | 名字 | 姓 | 最后更新
———-+————+————–+————————
1 | Penelope | Guiness | 2013-05-26 14:47:57.62
2 | Nick | Wahlberg | 2013-05-26 14:47:57.62
3 | Ed | Chase | 2013-05-26 14:47:57.62
4 | Jennifer | Davis | 2013-05-26 14:47:57.62
5 | Johnny | Lollobrigida | 2013-05-26 14:47:57.62
6 | Bette | Nicholson | 2013-05-26 14:47:57.62
7 | Grace | Mostel | 2013-05-26 14:47:57.62
8 | Matthew | Johansson | 2013-05-26 14:47:57.62
9 | Joe | Swank | 2013-05-26 14:47:57.62
10 | Christian | Gable | 2013-05-26 14:47:57.62
11 | Zero | Cage | 2013-05-26 14:47:57.62
12 | Karl | Berry | 2013-05-26 14:47:57.62
13 | Uma | Wood | 2013-05-26 14:47:57.62
14 | Vivien | Bergen | 2013-05-26 14:47:57.62
15 | Cuba | Olivier | 2013-05-26 14:47:57.62
16 | Fred | Costner | 2013-05-26 14:47:57.62
17 | Helen | Voight | 2013-05-26 14:47:57.62
18 | Dan | Torn | 2013-05-26 14:47:57.62
19 | Bob | Fawcett | 2013-05-26 14:47:57.62
20 | Lucille | Tracy | 2013-05-26 14:47:57.62
(20 行)
DVD租赁=> 选择计数(*)从演员;
计数
——-
200
(1 行)
DVD租赁=>
DVD租赁=> 选择*从电影_演员限制10;
演员ID | 电影ID | 最后更新
———-+———+———————
1 | 1 | 2006-02-15 10:05:03
1 | 23 | 2006-02-15 10:05:03
1 | 25 | 2006-02-15 10:05:03
1 | 106 | 2006-02-15 10:05:03
1 | 140 | 2006-02-15 10:05:03
1 | 166 | 2006-02-15 10:05:03
1 | 277 | 2006-02-15 10:05:03
1 | 361 | 2006-02-15 10:05:03
1 | 438 | 2006-02-15 10:05:03
1 | 499 | 2006-02-15 10:05:03
(10 行)
DVD租赁=> 选择*从商店限制10;
商店ID | 经理员工ID | 地址ID | 最后更新
———-+——————+————+———————
1 | 1 | 1 | 2006-02-15 09:57:12
2 | 2 | 2 | 2006-02-15 09:57:12
(2 行)
DVD租赁=> 选择*从城市限制10;
城市ID | 城市 | 国家ID | 最后更新
———+——————–+————+———————
1 | A Corua (La Corua) | 87 | 2006-02-15 09:45:25
2 | Abha | 82 | 2006-02-15 09:45:25
3 | Abu Dhabi | 101 | 2006-02-15 09:45:25
4 | Acua | 60 | 2006-02-15 09:45:25
5 | Adana | 97 | 2006-02-15 09:45:25
6 | Addis Abeba | 31 | 2006-02-15 09:45:25
7 | Aden | 107 | 2006-02-15 09:45:25
8 | Adoni | 44 | 2006-02-15 09:45:25
9 | Ahmadnagar | 44 | 2006-02-15 09:45:25
10 | Akishima | 50 | 2006-02-15 09:45:25
(10 行)
转移流程
-
- 在AWS的工作用EC2实例上安装PostgreSQL客户端
-
- 使用pg_dump命令创建数据库的备份文件
-
- 手动将备份文件复制到OCI的工作用Compute实例上
-
- 在OCI的工作用Compute实例上安装PostgreSQL客户端
- 使用pg_restore命令执行数据库还原操作
1. 安装 AWS 上的工作用 EC2 上的 PostgreSQL 客户端
请按照适用于各种Linux的步骤进行安装。
请参考以下各种操作系统的相应步骤。
(例)使用Ubuntu的步骤
$ sudo apt install -y postgresql-client
$ psql --version
psql (PostgreSQL) 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1)
2. 使用AWS的EC2实例进行工作: 使用pg_dump命令创建数据库的Dump文件
使用以下命令创建Dump文件。
$ pg_dump -h rds-postgresql.xxxxxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -U postgres -O -x --format=t --file=fromaws_dvdrental.tar dvdrental
Password:
$
$ ls -l ./fromaws_dvdrental.tar
-rw-rw-r-- 1 ubuntu ubuntu 2831872 Nov 15 14:22 ./fromaws_dvdrental.tar
$
请参考以下官方网站以了解项目的详细信息。
将Dump文件手动复制到OCI的工作计算机上。
请以任何方式复制已创建的文件。
4. 安装OCI操作Compute所需的PostgreSQL客户端。
请根据适用于各种Linux的步骤进行安装。
请参考以下各种操作系统的相应步骤。
使用OCI的Compute进行操作:使用pg_restore命令执行数据库的恢复操作。
5.1. 创建原始数据库备份
在进行恢复操作之前,需要预先创建一个数据库。
数据库的名称可以与迁移前不同也可以。
在接下来的步骤中,我们将以“oci_dvdrental”作为数据库名称进行创建。
$ psql -h 10.1.1.134 -U postgres -d postgres
Password for user postgres:
psql (15.3, server 14.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, compression: off)
Type "help" for help.
postgres=> create database oci_dvdrental;
CREATE DATABASE
确认数据库已被创建,并且内容为空。
postgres=> \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
---------------+---------------+----------+-------------+-------------+------------+-----------------+---------------------------------
oci_dvdrental | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
postgres | oci_superuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc |
template0 | oci_superuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/oci_superuser +
| | | | | | | oci_superuser=CTc/oci_superuser
template1 | oci_superuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | | libc | =c/oci_superuser +
| | | | | | | oci_superuser=CTc/oci_superuser
(4 rows)
postgres=> \c oci_dvdrental;
psql (15.3, server 14.9)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, compression: off)
You are now connected to database "oci_dvdrental" as user "postgres".
oci_dvdrental=> \dt;
Did not find any relations.
oci_dvdrental=>
使用pg_restore工具执行数据库的还原操作
用以下命令执行恢复操作:
$ pg_restore -h 10.1.1.134 -U postgres -O -d oci_dvdrental ./fromaws_dvdrental.tar
Password:
$
请参考以下官方网站以获取项目的详细信息。
确认动作
我会登录到OCI数据库与PostgreSQL的终端,并进行操作确认。
postgres用户的密码:
psql(15.3,服务器14.9)
SSL连接(协议:TLSv1.2,密码:ECDHE-RSA-AES256-GCM-SHA384,压缩:关闭)
键入“help”获取帮助。
oci_dvdrental=>
oci_dvdrental=> \dt;
关系列表
模式|名称|类型|所有者
——–+—————+——-+———-
public | actor | 表 | postgres
public | address | 表 | postgres
public | category | 表 | postgres
public | city | 表 | postgres
public | country | 表 | postgres
public | customer | 表 | postgres
public | film | 表 | postgres
public | film_actor | 表 | postgres
public | film_category | 表 | postgres
public | inventory | 表 | postgres
public | language | 表 | postgres
public | payment | 表 | postgres
public | rental | 表 | postgres
public | staff | 表 | postgres
public | store | 表 | postgres
(15行)
oci_dvdrental=> select * from actor limit 20;
演员ID |名字|姓氏|最后更新时间
———-+————+————–+————————
1 | 姓氏A | 名字A | 2013-05-26 14:47:57.62
2 | 姓氏B | 名字B | 2013-05-26 14:47:57.62
3 | 姓氏C | 名字C | 2013-05-26 14:47:57.62
4 | 姓氏D | 名字D | 2013-05-26 14:47:57.62
5 | 姓氏E | 名字E | 2013-05-26 14:47:57.62
6 | 姓氏F | 名字F | 2013-05-26 14:47:57.62
7 | 姓氏G | 名字G | 2013-05-26 14:47:57.62
8 | 姓氏H | 名字H | 2013-05-26 14:47:57.62
9 | 姓氏I | 名字I | 2013-05-26 14:47:57.62
10 | 姓氏J | 名字J | 2013-05-26 14:47:57.62
11 | 姓氏K | 名字K | 2013-05-26 14:47:57.62
12 | 姓氏L | 名字L | 2013-05-26 14:47:57.62
13 | 姓氏M | 名字M | 2013-05-26 14:47:57.62
14 | 姓氏N | 名字N | 2013-05-26 14:47:57.62
15 | 姓氏O | 名字O | 2013-05-26 14:47:57.62
16 | 姓氏P | 名字P | 2013-05-26 14:47:57.62
17 | 姓氏Q | 名字Q | 2013-05-26 14:47:57.62
18 | 姓氏R | 名字R | 2013-05-26 14:47:57.62
19 | 姓氏S | 名字S | 2013-05-26 14:47:57.62
20 | 姓氏T | 名字T | 2013-05-26 14:47:57.62
(20行)
oci_dvdrental=> select count(*) from actor;
计数
——-
200
(1行)
oci_dvdrental=> select * from film_actor limit 10;
演员ID | 电影ID |最后更新时间
———-+———+———————
1 | 1 | 2006-02-15 10:05:03
1 | 23 | 2006-02-15 10:05:03
1 | 25 | 2006-02-15 10:05:03
1 | 106 | 2006-02-15 10:05:03
1 | 140 | 2006-02-15 10:05:03
1 | 166 | 2006-02-15 10:05:03
1 | 277 | 2006-02-15 10:05:03
1 | 361 | 2006-02-15 10:05:03
1 | 438 | 2006-02-15 10:05:03
1 | 499 | 2006-02-15 10:05:03
(10行)
oci_dvdrental=> select * from store limit 10;
商店ID | 商店经理员工ID | 地址ID |最后更新时间
———-+——————+————+———————
1 | 1 | 1 | 2006-02-15 09:57:12
2 | 2 | 2 | 2006-02-15 09:57:12
(2行)
oci_dvdrental=> select * from city limit 10;
城市ID |城市|国家ID|最后更新时间
———+——————–+————+———————
1 | 阿科拉(拉科鲁尼亚)| 87 | 2006-02-15 09:45:25
2 | 阿布哈| 82 | 2006-02-15 09:45:25
3 | 阿布扎比| 101 | 2006-02-15 09:45:25
4 | 阿宽| 60 | 2006-02-15 09:45:25
5 | 阿达纳| 97 | 2006-02-15 09:45:25
6 | 亚的斯亚贝巴| 31 | 2006-02-15 09:45:25
7 | 艾登| 107 | 2006-02-15 09:45:25
8 | 阿多尼| 44 | 2006-02-15 09:45:25
9 | 阿赫马德纳格尔| 44 | 2006-02-15 09:45:25
10 | 明岛| 50 | 2006-02-15 09:45:25
(10行)
总结
由于OCI Database与PostgreSQL在2023年11月15日变为GA,我尝试使用常规步骤从RDS进行迁移。
服务发布文章
截至2023年11月15日,OCI Database with PostgreSQL的官方文档尚未提供日文手册。
请归参考。