How to find whether retention.ms is disabled for topics (ie - retention.ms=-1)
Last updated: August 11, 2026
- To check a topic’s configurations, run
rpk topic describe - To change a value of retention.ms, run
rpk topic alter-config --setretention.ms=
If you would like to list all topics that have retention.ms=-1, run the following command.
Please note that the following example sets a broker IP address to 192.168.64.82. You should change this IP address for your environment.
OPTIONS="--brokers 192.168.64.82:9092"; for T in $(rpk topic list $(echo $OPTIONS) | grep -v NAME | awk '{print $1}' ) ; do echo -n "${T}: "; rpk topic describe ${T} $(echo $OPTIONS) | grep retention.ms ; done | grep -- "-1"
You should modify the
OPTIONS variable for your environment based on whether you use SASL:- If you you do not have SASL enabled:
rpk topic describe test-topic --brokers 192.168.64.77:9092update the OPTIONS variable;OPTIONS="--brokers 192.168.64.77:9092"
- If you have SASL enabled:
rpk topic describe test-topic --brokers 192.168.64.77:9092 --user admin --password --sasl-mechanism SCRAM-SHA-256
update the OPTIONS variable:OPTIONS="--brokers 192.168.64.77:9092 --user admin --password --sasl-mechanism SCRAM-SHA-256"
Example output:
$ OPTIONS="--brokers 192.168.64.82:9092"; for T in $(rpk topic list $(echo $OPTIONS) | grep -v NAME | awk '{print $1}' ) ; do echo -n "${T}: "; rpk topic describe ${T} $(echo $OPTIONS) | grep "retention.ms" ; done | grep -- "-1"
my_005: retention.ms -1 DYNAMIC_TOPIC_CONFIG
my_008: retention.ms -1 DYNAMIC_TOPIC_CONFIG
You can list all topics by removing the last section of the command (
| grep -- "-1") $ OPTIONS="--brokers 192.168.64.82:9092"; for T in $(rpk topic list $(echo $OPTIONS) | grep -v NAME | awk '{print $1}' ) ; do echo -n "${T}: "; rpk topic describe ${T} $(echo $OPTIONS) | grep "retention.ms" ; done
RP_001: retention.ms 604800000 DEFAULT_CONFIG
RP_002: retention.ms 604800000 DEFAULT_CONFIG
RP_003: retention.ms 604800000 DEFAULT_CONFIG
my_001: retention.ms 604800000 DEFAULT_CONFIG
my_002: retention.ms 604800000 DEFAULT_CONFIG
my_003: retention.ms 604800000 DEFAULT_CONFIG
my_004: retention.ms 604800000 DEFAULT_CONFIG
my_005: retention.ms -1 DYNAMIC_TOPIC_CONFIG
my_006: retention.ms 604800000 DEFAULT_CONFIG
my_007: retention.ms 604800000 DEFAULT_CONFIG
my_008: retention.ms -1 DYNAMIC_TOPIC_CONFIG
my_009: retention.ms 604800000 DEFAULT_CONFIG
my_010: retention.ms 604800000 DEFAULT_CONFIG
To change the value to three years (1095 days : 315360000003 ms), run the following command:
rpk topic alter-config --set retention.ms=315360000003