This topic describes how to use Terraform to modify parameters and query parameter modification logs of an ApsaraDB RDS for PostgreSQL instance.
Prerequisites
An RDS instance is created. For more information, see Create an RDS instance.
The RDS instance is in the Running state. You can use one of the following methods to check whether the RDS instance is in the Running state:
Check whether the value of the status parameter is Running by following the instructions provided in Query the details of an RDS instance. If yes, the RDS instance is in the Running state.
Log on to the ApsaraDB RDS console, switch to the required region, find the RDS instance, and then check the instance status.
Modify parameters
The modification of some parameters triggers a restart of your RDS instance. After you modify the parameters, your RDS instance immediately restarts. To check whether the modification of a parameter triggers a restart, you need to log on to the ApsaraDB RDS console, go to the Editable Parameters tab, and then view the value in the Force Restart column of the parameter. If the value is Yes, the modification of the parameter triggers a restart. If the value is No, the modification of the parameter does not trigger a restart. If the RDS instance restarts, your application is disconnected from the RDS instance. Make sure that your application is configured to reconnect to your RDS instance. To minimize the impacts, we recommend that you arrange your business before the restart of the RDS instance. Proceed with caution.
This section describes how to change the value of the authentication_timeout
parameter to 120
.
In the terraform.tf file, add the
parameters
field to theresource "alicloud_db_instance" "instance" {}
configuration item and configure the field based on the following code snippet:... resource "alicloud_db_instance" "instance" { ... parameters { name = "authentication_timeout" value = "120" } }
Run the
terraform apply
command.After the following information appears, confirm the information and enter yes to modify the parameter:
alicloud_db_instance.instance: Refreshing state... [id=pgm-****] alicloud_db_backup_policy.instance: Refreshing state... [id=pgm-****] Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: ~ update in-place Terraform will perform the following actions: # alicloud_db_instance.instance will be updated in-place ~ resource "alicloud_db_instance" "instance" { id = "pgm-****" # (43 unchanged attributes hidden) + parameters { + name = "authentication_timeout" + value = "120" } # (1 unchanged block hidden) } Plan: 0 to add, 1 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value:
If the following logs appear, the operation is successful:
alicloud_db_instance.instance: Modifying... [id=pgm-****] alicloud_db_instance.instance: Still modifying... [id=pgm-****, 10s elapsed] ... alicloud_db_instance.instance: Still modifying... [id=pgm-****, 3m10s elapsed] alicloud_db_instance.instance: Modifications complete after 3m10s [id=pgm-****] Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
View the result.
Run the
terraform show
command to check whether the parameter is modified.# alicloud_db_instance.instance: resource "alicloud_db_instance" "instance" { acl = "prefer" ca_type = "aliyun" client_ca_enabled = 0 client_crl_enabled = 0 connection_string = "pgm-****.pg.rds.aliyuncs.com" connection_string_prefix = "pgm-****" db_instance_storage_type = "cloud_essd" db_time_zone = "Asia/Shanghai" deletion_protection = false engine = "PostgreSQL" engine_version = "13.0" force_restart = false ha_config = "Manual" id = "pgm-****" instance_charge_type = "Postpaid" instance_name = "terraformtest" instance_storage = 50 instance_type = "pg.n2.2c.2m" maintain_time = "05:00Z-06:00Z" manual_ha_time = "2022-09-30T09:00:00Z" monitoring_period = 300 period = 0 port = "5432" private_ip_address = "192.168.XX.XX" replication_acl = "prefer" resource_group_id = "rg-****" security_group_id = "sg-****" security_group_ids = [ "sg-bp1h9iqx6mxan5tcouwc", ] security_ip_mode = "normal" security_ips = [ "0.0.0.0/0", ] server_cert = <<-EOT -----BEGIN CERTIFICATE----- MIIE7jCCA****xuq/yfM4ALgBJ2 N9xwKlPQ65q/kux0yErtwhAD -----END CERTIFICATE----- EOT server_key = <<-EOT -----BEGIN RSA PRIVATE KEY----- MIIJKQIB****4Y1K34yE+e+VAdGp -----END RSA PRIVATE KEY----- EOT sql_collector_config_value = 30 sql_collector_status = "Disabled" ssl_action = "Open" ssl_status = "0" storage_auto_scale = "Enable" storage_threshold = 30 storage_upper_bound = 100 target_minor_version = "rds_postgres_1300_20220830" tcp_connection_type = "SHORT" vpc_id = "vpc-****" vswitch_id = "vsw-****" zone_id = "cn-hangzhou-h" parameters { name = "authentication_timeout" value = "120" } pg_hba_conf { address = "127.0.0.1" database = "all" method = "md5" priority_id = 1 type = "host" user = "all" } }
Log on to the ApsaraDB RDS console to check whether the parameter is modified.
Query parameter modification logs
In the terraform.tf file, add the
data "alicloud_rds_modify_parameter_logs" "querylogs"
configuration item and configure the configuration item based on the following snippet:... data "alicloud_rds_modify_parameter_logs" "querylogs" { db_instance_id = alicloud_db_instance.instance.id start_time = "2022-09-29T00:00Z" end_time = "2022-09-29T23:59Z" }
Run the
terraform apply
command to query the parameter modification logs of the RDS instance.If the following logs appear, the query is successful:
alicloud_db_instance.instance: Refreshing state... [id=pgm-****] data.alicloud_rds_modify_parameter_logs.querylogs: Reading... alicloud_db_backup_policy.instance: Refreshing state... [id=pgm-****] data.alicloud_rds_modify_parameter_logs.querylogs: Read complete after 0s [id=6335****] No changes. Your infrastructure matches the configuration. Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed. Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Run the
terraform show
command to view the parameter modification logs of the RDS instance.# data.alicloud_rds_modify_parameter_logs.querylogs: data "alicloud_rds_modify_parameter_logs" "querylogs" { db_instance_id = "pgm-****" end_time = "2022-09-29T23:59Z" id = "63353bb6" logs = [ { modify_time = "1664423171000" new_parameter_value = "all" old_parameter_value = "ddl" parameter_name = "log_statement" status = "Applied" }, { modify_time = "1664424162000" new_parameter_value = "ddl" old_parameter_value = "all" parameter_name = "log_statement" status = "Applied" }, { modify_time = "1664432729000" new_parameter_value = "120" old_parameter_value = "60" parameter_name = "authentication_timeout" status = "Applied" }, ] start_time = "2022-09-29T00:00Z" }