Common tasks for databases
You can create, drop, or restore databases on your RDS for Db2 DB instance. Creating,
dropping, or restoring databases requires higher-level SYSADM
authority, which
isn't available to the master user. Instead, use Amazon RDS stored procedures.
You can also perform common management tasks such as monitoring, maintenance, and the collection of information about your databases.
Topics
Creating a database
To create a database on your RDS for Db2 DB instance, call the
rdsadmin.create_database
stored procedure. For more information, see
CREATE DATABASE command
Note
You can create a database by calling the stored procedure if you didn't specify
the name of the database when you created your RDS for Db2 DB instance by using either
the Amazon RDS console or the AWS CLI. For more information, see Usage notes for
rdsadmin.create_database
.
To create a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_user
usingmaster_password
" -
Create a database by calling
rdsadmin.create_database
. For more information, see rdsadmin.create_database.db2 "call rdsadmin.create_database('
database_name
')"
Configuring settings for a database
To configure the settings for a database on your RDS for Db2 DB instance, call the
rdsadmin.set_configuration
stored procedure. For example, you could
configure the number of buffers or buffer manipulators to create during a restore
operation.
To configure settings for a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_user
usingmaster_password
" -
(Optional) Check your current configuration settings by calling
rdsadmin.show_configuration
. For more information, see rdsadmin.show_configuration.db2 "call rdsadmin.show_configuration('
name
')" -
Configure the settings for the database by calling
rdsadmin.set_configuration
. For more information, see rdsadmin.set_configuration.db2 "call rdsadmin.set_configuration( '
name
', 'value
')"
Modifying database parameters
Amazon RDS for Db2 uses three types of parameters: database manager configuration parameters, registry variables, and database configuration parameters. You can update the first two types through parameter groups and the last type through the rdsadmin.update_db_param stored procedure.
Note
You can only modify the values of existing parameters. You can't add new parameters that RDS for Db2 doesn't support.
For more information these parameters and how to modify their values, see Amazon RDS for Db2 parameters.
Configuring log retention
To configure how long Amazon RDS retains log files for your RDS for Db2 database, call the
rdsadmin.set_archive_log_retention
stored procedure.
To configure log retention for a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_user
usingmaster_password
" -
(Optional) Check your current configuration for log retention by calling
rdsadmin.show_archive_log_retention
. For more information, see rdsadmin.show_archive_log_retention.db2 "call rdsadmin.show_archive_log_retention( ?, '
database_name
')" -
Configure log retention for the database by calling
rdsadmin.set_archive_log_retention
. For more information, see rdsadmin.set_archive_log_retention.db2 "call rdsadmin.set_archive_log_retention( ?, '
database_name
', 'archive_log_retention_hours
')"
Dropping a database
To drop a database from your RDS for Db2 DB instance, call the
rdsadmin.drop_database
stored procedure. For more information, see
Dropping
databases
Note
You can drop a database by calling the stored procedure only if certain conditions
are met. For more information, see Usage notes for rdsadmin.drop_database
.
To drop a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_user
usingmaster_password
" -
Drop a database by calling
rdsadmin.drop_database
. For more information, see rdsadmin.drop_database.db2 "call rdsadmin.drop_database('
database_name
')"
Restoring a database
To restore a database on your RDS for Db2 DB instance, call the
rdsadmin.restore_database
stored procedure. For more information, see
RESTORE DATABASE command
Note
You can restore a database by calling the stored procedure if you didn't specify
the name of the database when you created your RDS for Db2 DB instance by using either
the Amazon RDS console or the AWS CLI. For more information, see Usage notes for
rdsadmin.restore_database
.
To restore a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_user
usingmaster_password
" -
(Optional) Check your current configuration settings to optimize the restore operation by calling
rdsadmin.show_configuration
. For more information, see rdsadmin.show_configuration.db2 "call rdsadmin.show_configuration('
name
')" -
Configure the settings to optimize the restore operation by calling
rdsadmin.set_configuration
. Explicitly setting these values can improve the performance when restoring databases with large volumes of data. For more information, see rdsadmin.set_configuration.db2 "call rdsadmin.set_configuration( '
name
', 'value
')" -
Restore the database by calling
rdsadmin.restore_database
. For more information, see rdsadmin.restore_database.db2 "call rdsadmin.restore_database( ?, '
database_name
', 's3_bucket_name
', 's3_prefix
',restore_timestamp
, 'backup_type
')" -
Bring the database back online and apply additional transaction logs by calling
rdsadmin.rollforward_database
. For more information, see rdsadmin.rollforward_database.db2 "call rdsadmin.rollforward_database( ?, '
database_name
', 's3_bucket_name
',s3_prefix
, 'rollfoward_to_option
', 'complete_rollforward
')" -
If you set
complete_rollforward
toFALSE
in the previous step, then you must finish bringing the database back online by callingrdsadmin.complete_rollforward
. For more information, see rdsadmin.complete_rollforward.db2 "call rdsadmin.complete_rollforward( ?, '
database_name
')"
Collecting information about databases
To collect information about your databases, call the
rdsadmin.db2pd_command
stored procedure. This information can help with
monitoring your databases or troubleshooting issues.
To collect information about a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_username
usingmaster_password
" -
Collect information about the database by calling
rdsadmin.db2pd_command
. For more information, see rdsadmin.db2pd_command.db2 "call rdsadmin.db2pd_command('
db2pd_cmd
')"
Forcing applications off of databases
To force applications off of your RDS for Db2 databases, call the
rdsadmin.force_application
stored procedure. Before you perform
maintenance on your databases, force applications off of your databases.
To force applications off of a database
-
Connect to the
rdsadmin
database using the master username and master password for your RDS for Db2 DB instance. In the following example, replacemaster_username
andmaster_password
with your own information.db2 "connect to rdsadmin user
master_username
usingmaster_password
" -
Force applications off of a database by calling
rdsadmin.force_application
. For more information, see rdsadmin.force_application.db2 "call rdsadmin.force_application( ?, '
applications
')"
Generating performance reports
You can generate performance reports with a procedure or a script. For information about
using a procedure, see DBSUMMARY procedure ‐ Generate a summary report of system and
application performance metrics
Db2 includes a db2mon.sh
file in its ~sqllib/sample/perf
directory. Running the script produces a low-cost, extensive SQL metrics report. To download
the db2mon.sh
file and related script files, see the perf
To generate performance reports with the script
-
Connect to your Db2 database using the master username and master password for your RDS for Db2 DB instance. In the following example, replace
master_username
andmaster_password
with your own information.db2 connect to rdsadmin
master_username
usingmaster_password
-
Create a buffer pool named
db2monbp
with a page size of 4096 by callingrdsadmin.create_bufferpool
. For more information, see rdsadmin.create_bufferpool.db2 "call rdsadmin.create_bufferpool('
database_name
','db2monbp',4096)" -
Create a temporary tablespace named
db2montmptbsp
that uses thedb2monbp
buffer pool by callingrdsadmin.create_tablespace
. For more information, see rdsadmin.create_tablespace.db2 "call rdsadmin.create_tablespace('database_name',\ 'db2montmptbsp','db2monbp',4096,1000,100,'T')"
-
Open the
db2mon.sh
script, and modify the line about connecting to a database.-
Remove the following line.
db2 -v connect to $dbName
-
Replace the line in the previous step with the following line. In the following example, replace
master_username
andmaster_password
with the master username and master password for your RDS for Db2 DB instance.db2 -v connect to $dbName user
master_username
usingmaster_password
-
Remove the following lines.
db2 -v create bufferpool db2monbp db2 -v create user temporary tablespace db2montmptbsp bufferpool db2monbp db2 -v drop tablespace db2montmptbsp db2 -v drop bufferpool db2monbp
-
-
Run the
db2mon.sh
script to output a report at specified intervals. In the following example, replaceabsolute_path
with the complete path to the script file,rds_database_alias
with the name of your database, andseconds
with the number of seconds (0 to 3600) between report generation.absolute_path
/db2mon.shrds_database_alias
seconds
| tee -a db2mon.outExamples
The following example shows that the script file is located in the
perf
directory under thehome
directory./home/db2inst1/sqllib/samples/perf/db2mon.sh
rds_database_alias
seconds
| tee -a db2mon.out -
Drop the buffer pool and the tablespace that were created for the
db2mon.sh
file. In the following example, replacemaster_username
andmaster_password
with the master username and master password for your RDS for Db2 DB instance. Replacedatabase_name
with the name of your database.db2 connect to rdsadmin user
master_username
usingmaster_password
db2 "call rdsadmin.drop_tablespace('database_name
','db2montmptbsp')" db2 "call rdsadmin.drop_bufferpool('database_name
','db2monbp')"