Project: YDB (App Definition and Development / Database)
File: alter_topic.md

You can use the `ALTER TOPIC` command to change the settings, as well as add, update, or delete its consumers. Here is the general format of the `ALTER TOPIC` command: ```sql ALTER TOPIC topic_path action1, action2, ..., actionN; ``` `action` is one of the alter actions described below. `ADD CONSUMER`: Adds a to a topic. The following example will add a consumer with default settings to the topic. ```sql ALTER TOPIC `mytopic` ADD CONSUMER newconsumer; ``` When adding consumers, you can specify their settings, for example: ```sql ALTER TOPIC `mytopic` ADD CONSUMER newconsumer2 WITH (important = false); ``` `important`: Defines an important consumer. No data will be deleted from the topic until all the important consumers read them. Value type: `boolean`, default value: `false`. `read_from`: Sets up the message write time starting from which the consumer will receive data. Data written beforethis timewill not be read. Value type: `Datetime` OR `Timestamp` OR `integer` (unix-timestamp in the numeric format). Default value: `now`. {% if featuretopiccodecs %} `supported_codecs`: List of supported by the consumer. {% endif %} `DROP CONSUMER`: Deletes the consumer from the topic. ```sql ALTER TOPIC `mytopic` DROP CONSUMER oldconsumer; ``` `ALTER CONSUMER`: Adds a consumer for a topic. Here is the general syntax for `ALTER CONSUMER`: ```sql ALTER TOPIC `topicname` ALTER CONSUMER consumername consumer_action; ``` Supports the following types of `consumer_action`: `SET`: Sets consumer settings {% if featuretopicsettings_reset %} `RESET`: Resets consumer settings to defaults. {% endif %} The following example will assign the `important` parameter to the consumer. ```sql ALTER TOPIC `mytopic` ALTER CONSUMER myconsumer SET (important = true); ``` {% if featuretopicsettings_reset %} This example will reset `read_from` to default. ```sql ALTER TOPIC `mytopic` ALTER CONSUMER myconsumer RESET (read_from); ``` {% endif %} You can specify several `ALTER CONSUMER` statements for a consumer. However, the settings applied by them shouldn't

This is a valid statement: ```sql ALTER TOPIC `my_topic` ALTER CONSUMER my_consumer SET (important = true) ALTER CONSUMER myconsumer SET (readfrom = 0); ``` But this statement will raise an error. ```sql ALTER TOPIC `my_topic` ALTER CONSUMER my_consumer SET (important = true) ALTER CONSUMER my_consumer SET (important = false); ``` Using the `SET (option = value[, ...])` action, you can update your topic settings. The example below will change the retentionperiod for the topic and the writing quota per partition: ```sql ALTER TOPIC `my_topic` SET ( retention_period = Interval('PT36H'), partitionwritespeedbytesper_second = 3000000 ); ``` {% if featuretopicsettings_reset %} The `RESET (option[, option2, ...])` action enables you to reset the topic settings to defaults. Example ```sql ALTER TOPIC `my_topic` RESET ( minactivepartitions, partitioncountlimit ); ``` {% endif %} `minactivepartitions`: Minimum number of topic partitions. During automatic load balancing, the number of active partitions will not decreasebelow this value. Value type: `integer`, default value: `1`. `partitioncountlimit`: Maximum number of active partitions in the topic. `0` is interpreted as unlimited. Value type: `integer`, default value: `0`. `retention_period`: Data retention period in the topic. Value type: `Interval`, default value: `18h`. `retentionstoragemb`: Limit on the maximum disk space occupied by the topic data. When this value is exceeded, the older data is cleared, like under a retention policy. `0` is interpreted as unlimited. Value type: `integer`, default value: `0` `partitionwritespeedbytesper_second`: Maximum allowed write speed per partition. If a write speed for a given partitionexceeds this value, the write speed will be capped. Value type: `integer`, default value: `2097152` (2MB). `partitionwriteburstbytes`: Write quota allocated for write bursts. When set to zero, the actual writeburst value is equalled to the quota value (this allows write bursts ofup to one second). Value type: `integer`, default value: `0`. `meteringmode`: Resource metering mode (`RESERVEDCAPACITY` - based on the allocated resources or `REQUEST_UNITS` - based on actual usage). This option applies to topics in serverless databases. Value type: `String`. {% if featuretopiccodecs %} `supported_codecs`: List of supported by the topic. Value type: `String`. {% endif %}