LoginSignup
2
2

More than 3 years have passed since last update.

[RDSへのデータ移行]2.SCT(AWS Schema Conversion Tool)でスキーマ変換

Last updated at Posted at 2019-11-13

前回→[RDSへのデータ移行]1.SCT(AWS Schema Conversion Tool)の設定

1.スキーマ変換

スキーマの変換

  • 変換対象スキーマを右クリックしConvert schemaをクリック 17.png
  • Yesをクリック 18.png
  • スキーマ変換が終了すると。プロジェクトの右のパネルでスキーマの候補が表示される
    • この時点では、ターゲットDBにスキーマは適用されていない
    • ターゲットDBの下中央パネルに、計画したスキーマコマンドが表示される 19.png
  • ターゲットDB側で対象スキーマを右クリックしApply to databseをクリックしてターゲットDBに変換を適用 20.png
  • Yesをクリック 21.png
  • 適用が完了したらスキーマのアイコンが変わる 22.png
  • 移行対象スキーマのテーブルを選択するとSQL文が表示される 23.png

2.スキーマの確認

  • Aurora(PostgresSQL)にログインしSCOTTを確認
-- クラスタにログイン
$ sudo psql --host=targetdb-cluster.cluster-xxxx.ap-northeast-1.rds.amazonaws.com --port=5432 --username=postgres --password --dbname=targetdb
ユーザ postgres のパスワード: 
psql (9.2.24, サーバー 10.7)
注意: psql バージョン 9.2, サーバーバージョン 10.0.
         psql の機能の中で、動作しないものがあるかもしれません。
SSL 接続 (暗号化方式: ECDHE-RSA-AES256-GCM-SHA384, ビット長: 256)
"help" でヘルプを表示します.

targetdb=> 
targetdb=> 

-- DB一覧を確認
targetdb=> \l
                                         データベース一覧
   名前    |  所有者  | エンコーディング |  照合順序   | Ctype(変換演算子) |      アクセス権       
-----------+----------+------------------+-------------+-------------------+-----------------------
 postgres  | postgres | UTF8             | en_US.UTF-8 | en_US.UTF-8       | 
 rdsadmin  | rdsadmin | UTF8             | en_US.UTF-8 | en_US.UTF-8       | rdsadmin=CTc/rdsadmin
 targetdb  | postgres | UTF8             | en_US.UTF-8 | en_US.UTF-8       | 
 template0 | rdsadmin | UTF8             | en_US.UTF-8 | en_US.UTF-8       | =c/rdsadmin          +
           |          |                  |             |                   | rdsadmin=CTc/rdsadmin
 template1 | postgres | UTF8             | en_US.UTF-8 | en_US.UTF-8       | =c/postgres          +
           |          |                  |             |                   | postgres=CTc/postgres
(5 )

targetdb=> 

-- 現在の実行ユーザの確認
targetdb=> select current_user;
 current_user 
--------------
 postgres
(1 )

-- 現在の実行スキーマの確認
targetdb=> select current_schema();
 current_schema 
----------------
 public
(1 )

-- スキーマ一覧確認
targetdb=> \dn
         スキーマ一覧
        名前        |  所有者  
--------------------+----------
 aws_oracle_context | postgres
 aws_oracle_data    | postgres
 aws_oracle_ext     | postgres
 public             | postgres
 scott              | postgres
(5 )

-- スキーマ切り替え(public → scott)
targetdb=> SET search_path = scott;
SET
targetdb=> 

-- 現在の実行スキーマの確認
targetdb=> select current_schema();
 current_schema 
----------------
 scott
(1 )

-- テーブル一覧確認
targetdb=> \dt;
          リレーションの一覧
 スキーマ | 名前 |        |  所有者  
----------+------+----------+----------
 scott    | tbl1 | テーブル | postgres
(1 )

-- テーブル内のデータを確認
targetdb=> select * from tbl1;
 id | txt 
----+-----
(0 )

-- 接続断
targetdb=> \q
$
  • SCOTTとSCOTTのオブジェクト(tbl1表)を確認できた
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2