Importing data from Db2 to Amazon RDS for Db2 with the INSERT command
You can use the INSERT
command from a self-managed Db2 server to insert your
data into an Amazon RDS for Db2 database. With this migration approach, you use a nickname for the
remote RDS for Db2 DB instance. Your self-managed Db2 database (source) must be able to connect
to the RDS for Db2 database (target).
Important
The INSERT
command method is useful for migrating small tables. If your
network bandwidth between your self-managed Db2 database and RDS for Db2 database is
limited, we recommend that you use a different migration approach. For more information,
see Using native Db2 tools to migrate data from Db2 to Amazon RDS for Db2.
To copy data from a self-managed Db2 database to an RDS for Db2 database
-
Catalog the RDS for Db2 DB instance on the self-managed Db2 instance.
-
Catalog the node. In the following example, replace
dns_ip_address
andport
with the DNS name or the IP address and the port number of the self-managed Db2 database.db2 catalog tcpip node remnode REMOTE
dns_ip_address
SERVERport
-
Catalog the database. In the following example, replace
rds_database_name
with the name of the database on your RDS for Db2 DB instance.db2 catalog database
rds_database_name
as remdb at node remnode \ authentication server_encrypt
-
-
Enable federation on the self-managed Db2 instance. In the following example, replace
source_database_name
with the name of your database on the self-managed Db2 instance.db2 update dbm cfg using FEDERATED YES
source_database_name
-
Create tables on the RDS for Db2 DB instance.
-
Catalog the node. In the following example, replace
dns_ip_address
andport
with the DNS name or the IP address and the port number of the self-managed Db2 database.db2 catalog tcpip node srcnode REMOTE
dns_ip_address
serverport
-
Catalog the database. In the following example, replace
source_database_name
andsource_database_alias
with the name of the self-managed Db2 database and the alias that you want to use for this database.db2 catalog database
source_database_name
assource_database_alias
at node srcnode \ authentication server_encrypt
-
-
Attach to the source database. In the following example, replace
source_database_alias
,user_id
, anduser_password
with the alias that you created in the previous step and the user ID and password for the self-managed Db2 database.db2look -d
source_database_alias
-iuser_id
-wuser_password
-e -l -a -f -wlm \ -cor -createdb -printdbcfg -o db2look.sql -
Set up federation, and create a nickname for the RDS for Db2 database table on the self-managed Db2 instance.
-
Connect to your local database. In the following example, replace
source_database_name
with the name of the database on your self-managed Db2 instance.db2 connect to
source_database_name
-
Create a wrapper to access Db2 data sources.
db2 create wrapper drda
-
Define a data source on a federated database. In the following example, replace
admin
andadmin_password
with your credentials for your self-managed Db2 instance. Replacerds_database_name
with the name of the database on your RDS for Db2 DB instance.db2 "create server rdsdb2 type DB2/LUW version '11.5.9.0' \ wrapper drda authorization "
admin
" password "admin_password
" \ options( dbname 'rds_database_name
', node 'remnode')" -
Map the users on the two databases. In the following example, replace
master_username
andmaster_password
with your credentials for your RDS for Db2 DB instance.db2 "create user mapping for user server rdsdb2 \ options (REMOTE_AUTHID '
master_username
', REMOTE_PASSWORD 'master_password
')" -
Verify the connection to the RDS for Db2 server.
db2 set passthru rdsdb2
-
Create a nickname for the table in the remote RDS for Db2 database. In the following example, replace
NICKNAME
andTABLE_NAME
with a nickname for the table and the name of the table.db2 create nickname REMOTE.
NICKNAME
for RDSDB2.TABLE_NAME.
NICKNAME
-
-
Insert data into the table in the remote RDS for Db2 database. Use the nickname in a
select
statement on the local table in the self-managed Db2 instance. In the following example, replaceNICKNAME
andTABLE_NAME
with a nickname for the table and the name of the table.db2 "INSERT into REMOTE.
NICKNAME
select * from RDS2DB2.TABLE_NAME.NICKNAME
"