資料庫的一般任務
您可以在 RDS for Db2 資料庫執行個體上建立、捨棄或還原資料庫。建立、捨棄或還原資料庫需要更高層級的 SYSADM 授權,這不適用於主要使用者。請改用 Amazon RDS 預存程序。
您也可以執行常見的管理任務,例如監控、維護,以及收集資料庫的相關資訊。
建立資料庫
若要在 RDS for Db2 資料庫執行個體上建立資料庫,請呼叫 rdsadmin.create_database 預存程序。如需詳細資訊,請參閱 IBM Db2 文件中的 CREATE DATABASE 命令
注意
如果您打算修改 db2_compatibility_vector 參數,在建立資料庫之前,請修改參數。如需更多詳細資訊,請參閱 設定 db2_compatibility_vector 參數。
若要建立資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.create_database來建立資料庫。如需更多詳細資訊,請參閱 rdsadmin.create_database。db2 "call rdsadmin.create_database('database_name')" -
(選用) 為您要建立的每個資料庫呼叫
rdsadmin.create_database來建立其他資料庫。每個 Db2 資料庫執行個體最多可包含 50 個資料庫。如需更多詳細資訊,請參閱 rdsadmin.create_database。db2 "call rdsadmin.create_database('database_name')" -
(選用) 使用下列其中一種方法確認已建立您的資料庫:
-
呼叫
rdsadmin.list_databases。如需更多詳細資訊,請參閱 rdsadmin.list_databases。 -
執行下列 SQL 命令:
db2 "select varchar(r.task_type,25) as task_type, r.database_name, varchar(r.lifecycle,15) as lifecycle, r.created_at, r.database_name, varchar(bson_to_json(task_input_params),256) as input_params, varchar(r.task_output,1024) as task_output from table(rdsadmin.get_task_status(null,null,'create_database')) as r order by created_at desc"
-
設定資料庫的設定
若要在 RDS for Db2 資料庫執行個體上設定資料庫的設定,請呼叫 rdsadmin.set_configuration 預存程序。例如,您可以設定在還原作業期間要建立的緩衝區或緩衝區操縱器數量。
設定資料庫的設定
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
(選用) 呼叫
rdsadmin.show_configuration以檢查您目前的組態設定。如需更多詳細資訊,請參閱 rdsadmin.show_configuration。db2 "call rdsadmin.show_configuration('name')" -
呼叫
rdsadmin.set_configuration來設定資料庫的設定。如需更多詳細資訊,請參閱 rdsadmin.set_configuration。db2 "call rdsadmin.set_configuration( 'name', 'value')"
修改資料庫參數
Amazon RDS for Db2 使用三種類型的參數:資料庫管理員組態參數、登錄變數和資料庫組態參數。您可以透過參數群組更新前兩種類型,並透過 rdsadmin.update_db_param 預存程序更新最後一個類型。
注意
您只能修改現有參數的值。您無法新增 RDS for Db2 所不支援的新參數。
如需這些參數以及如何修改其值的詳細資訊,請參閱 Amazon RDS for Db2 參數。
設定日誌保留原則
若要設定 Amazon RDS 保留 RDS for Db2 資料庫日誌檔案的時間,請呼叫 rdsadmin.set_archive_log_retention 預存程序。
設定資料庫的日誌保留
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
(選用) 呼叫
rdsadmin.show_archive_log_retention來檢查目前組態的日誌保留。如需更多詳細資訊,請參閱 rdsadmin.show_archive_log_retention。db2 "call rdsadmin.show_archive_log_retention( ?, 'database_name')" -
呼叫
rdsadmin.set_archive_log_retention來設定資料庫的日誌保留。如需更多詳細資訊,請參閱 rdsadmin.set_archive_log_retention。db2 "call rdsadmin.set_archive_log_retention( ?, 'database_name', 'archive_log_retention_hours')"
列出日誌資訊
若要列出封存日誌檔案的詳細資訊,包括使用的總儲存大小等詳細資訊,請呼叫 rdsadmin.list_archive_log_information 預存程序。
列出資料庫的日誌資訊
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.list_archive_log_information來傳回日誌檔案資訊清單。如需更多詳細資訊,請參閱 rdsadmin.list_archive_log_information。db2 "call rdsadmin.list_archive_log_information( ?, 'database_name')"
停用資料庫
若要停用 RDS for Db2 資料庫執行個體上的資料庫,請呼叫 rdsadmin.deactivate_database 預存程序。
根據預設,當您在 RDS for Db2 資料庫執行個體上建立資料庫時,Amazon RDS 會啟用資料庫。您可以停用不常使用的資料庫,以節省記憶體資源。
停用資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.deactivate_database來停用資料庫。如需更多詳細資訊,請參閱 rdsadmin.deactivate_database。db2 "call rdsadmin.deactivate_database( ?, 'database_name')"
啟用資料庫
若要在獨立的 RDS for Db2 資料庫執行個體上啟用資料庫,請呼叫 rdsadmin.activate_database 預存程序。
根據預設,當您在 RDS for Db2 資料庫執行個體上建立資料庫時,Amazon RDS 會啟用資料庫。您可以停用不常使用的資料庫來節省記憶體資源,然後在稍後將已停用的資料庫啟用。
啟用資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.activate_database來啟用資料庫。如需更多詳細資訊,請參閱 rdsadmin.activate_database。db2 "call rdsadmin.activate_database( ?, 'database_name')"
重新建立資料庫
若要在複本來源 RDS for Db2 資料庫執行個體上重新啟用資料庫,請呼叫 rdsadmin.reactivate_database 預存程序。變更資料庫組態之後,您可能需要在 RDS for Db2 資料庫執行個體上重新啟用資料庫。若要判斷是否需要重新啟用資料庫,請連線至資料庫並執行 db2 get db cfg show detail。
您也可以呼叫此預存程序,在對資料庫組態進行變更後,在獨立的 RDS for Db2 資料庫執行個體上重新啟用資料庫。或者,您可以先呼叫 rdsadmin.deactivate_database 預存程序,然後呼叫 rdsadmin.activate_database 預存程序,在獨立的 RDS for Db2 資料庫執行個體上重新啟用資料庫。如需詳細資訊,請參閱停用資料庫及啟用資料庫。
重新啟用資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.reactivate_database來重新啟用資料庫。如需更多詳細資訊,請參閱 rdsadmin.reactivate_database。db2 "call rdsadmin.reactivate_database( ?, 'database_name')"
捨棄資料庫
若要從 RDS for Db2 資料庫執行個體捨棄資料庫,請呼叫 rdsadmin.drop_database 預存程序。如需詳細資訊,請參閱 IBM Db2 文件中的捨棄資料庫
注意
僅在符合特定條件時,您才能呼叫預存程序來捨棄資料庫。如需詳細資訊,請參閱 使用須知 及 rdsadmin.drop_database。
捨棄資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.drop_database來捨棄資料庫。如需更多詳細資訊,請參閱 rdsadmin.drop_database。db2 "call rdsadmin.drop_database('database_name')"
還原資料庫
若要將資料庫從 Amazon S3 儲存貯體移至 RDS for Db2 資料庫執行個體,請呼叫 rdsadmin.restore_database 預存程序。如需詳細資訊,請參閱 IBM Db2 文件中的 RESTORE DATABASE 命令
若要 資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
(選用) 檢查您目前的組態設定,以呼叫
rdsadmin.show_configuration來最佳化還原作業。如需更多詳細資訊,請參閱 rdsadmin.show_configuration。db2 "call rdsadmin.show_configuration('name')" -
透過呼叫
rdsadmin.set_configuration來設定最佳化還原作業的設定。明確設定這些值可在還原具有大量資料的資料庫時改善效能。如需更多詳細資訊,請參閱 rdsadmin.set_configuration。db2 "call rdsadmin.set_configuration( 'name', 'value')" -
呼叫
rdsadmin.restore_database來還原資料庫。如需更多詳細資訊,請參閱 rdsadmin.restore_database。db2 "call rdsadmin.restore_database( ?, 'database_name', 's3_bucket_name', 's3_prefix',restore_timestamp, 'backup_type')" -
(選用) 呼叫
rdsadmin.list_databases並檢查還原的資料庫是否已列出,以確認您的資料庫已還原。如需更多詳細資訊,請參閱 rdsadmin.list_databases。 -
將資料庫恢復上線,並呼叫
rdsadmin.rollforward_database來套用其他交易日誌。如需更多詳細資訊,請參閱 rdsadmin.rollforward_database。db2 "call rdsadmin.rollforward_database( ?, 'database_name', 's3_bucket_name',s3_prefix, 'rollforward_to_option', 'complete_rollforward')" -
(選用) 透過呼叫
rdsadmin.rollforward_database預存程序來檢查 rdsadmin.rollforward_status 預存程序的狀態。 -
如果您在上一個步驟中將
complete_rollforward設定為FALSE,則必須透過呼叫rdsadmin.complete_rollforward來完成將資料庫恢復上線。如需更多詳細資訊,請參閱 rdsadmin.complete_rollforward。db2 "call rdsadmin.complete_rollforward( ?, 'database_name')" -
(選用) 透過呼叫
rdsadmin.complete_rollforward預存程序來檢查 rdsadmin.rollforward_status 預存程序的狀態。
列出資料庫
您可以透過呼叫 rdsadmin.list_databases 使用者定義的函數,列出在 Amazon RDS for Db2 上執行的所有資料庫。
列出您的資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.list_databases來列出您的資料庫。如需更多詳細資訊,請參閱 rdsadmin.list_databases。db2 "select * from table(rdsadmin.list_databases())"
收集資料庫的相關資訊
若要收集 RDS for Db2 資料庫執行個體上的資料庫相關資訊,請呼叫 rdsadmin.db2pd_command 預存程序。此資訊可協助您監控資料庫或故障診斷問題。
收集資料庫的相關資訊
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.db2pd_command來收集資料庫的相關資訊。如需更多詳細資訊,請參閱 rdsadmin.db2pd_command。db2 "call rdsadmin.db2pd_command('db2pd_cmd')"
強制應用程式離開資料庫
若要強制應用程式離開 RDS for Db2 資料庫執行個體上的資料庫,請呼叫 rdsadmin.force_application 預存程序。在對資料庫執行維護之前,請將應用程式強制離開資料庫。
強制應用程式離開資料庫
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至
rdsadmin資料庫。在下列範例中,將master_username和master_password取代為您自己的資訊。db2 "connect to rdsadmin usermaster_usernameusingmaster_password" -
呼叫
rdsadmin.force_application來強制應用程式離開資料庫。如需更多詳細資訊,請參閱 rdsadmin.force_application。db2 "call rdsadmin.force_application( ?, 'applications')"
產生效能報告
您可以使用程序或指令碼來產生效能報告。如需使用程序的相關資訊,請參閱 IBM Db2 文件中的 DBSUMMARY程序 ‐ 產生系統和應用程式效能指標的摘要報告
Db2 在其 ~sqllib/sample/perf 目錄中包含 db2mon.sh 檔案。執行指令碼會產生低成本、廣泛的 SQL 指標報告。若要下載 db2mon.sh 檔案和相關指令碼檔案,請參閱 IBM db2-samples GitHub 儲存庫中的 perf
使用指令碼產生效能報告
-
使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼連線至 Db2 資料庫。在下列範例中,將
master_username和master_password取代為您自己的資訊。db2 connect to rdsadminusermaster_usernameusingmaster_password -
呼叫
rdsadmin.create_bufferpool來建立名為db2monbp且頁面大小為 4096 的緩衝集區。如需更多詳細資訊,請參閱 rdsadmin.create_bufferpool。db2 "call rdsadmin.create_bufferpool('database_name','db2monbp',4096)" -
呼叫
rdsadmin.create_tablespace來建立名為db2montmptbsp的暫存資料表空間,以使用db2monbp緩衝集區。如需更多詳細資訊,請參閱 rdsadmin.create_tablespace。db2 "call rdsadmin.create_tablespace('database_name',\ 'db2montmptbsp','db2monbp',4096,1000,100,'T')" -
開啟
db2mon.sh指令碼,並修改有關連線至資料庫的行。-
移除以下這行。
db2 -v connect to $dbName -
將上一個步驟中的行取代為下列行。在下列範例中,使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼取代
master_username和master_password。db2 -v connect to $dbName usermaster_usernameusingmaster_password -
移除以下這些行。
db2 -v create bufferpool db2monbp db2 -v create user temporary tablespace db2montmptbsp bufferpool db2monbp db2 -v drop tablespace db2montmptbsp db2 -v drop bufferpool db2monbp
-
-
執行
db2mon.sh指令碼以指定的間隔輸出報告。在下列範例中,將absolute_path取代為指令碼檔案的完整路徑、將rds_database_alias取代為您資料庫的名稱,並將seconds取代為報告產生之間的秒數 (0 到 3600)。absolute_path/db2mon.shrds_database_aliasseconds| tee -a db2mon.out範例
下列範例顯示指令碼檔案位於
home目錄下的perf目錄中。/home/db2inst1/sqllib/samples/perf/db2mon.shrds_database_aliasseconds| tee -a db2mon.out -
捨棄為
db2mon.sh檔案建立的緩衝集區和資料表空間。在下列範例中,使用 RDS for Db2 資料庫執行個體的主使用者名稱和主密碼取代master_username和master_password。將database_name取代為您資料庫的名稱。如需詳細資訊,請參閱rdsadmin.drop_tablespace及rdsadmin.drop_bufferpool。db2 connect to rdsadmin usermaster_usernameusingmaster_passworddb2 "call rdsadmin.drop_tablespace('database_name','db2montmptbsp')" db2 "call rdsadmin.drop_bufferpool('database_name','db2monbp')"