apache-kafka

How to Delete All Kafka Topics at Once Using kafka-topics.sh on macOS


I'm trying to delete all Kafka topics at once using the kafka-topics.sh command-line tool on my Mac. I understand that the --delete flag is used for this purpose, but I'm unsure about the correct syntax and usage, particularly when using a regular expression pattern to match all topics.

Environment Details:

What I've Tried:

kafka-topics.sh --delete --zookeeper localhost:2181 --topic

kafka-topics.sh --delete --zookeeper localhost:2181 --topic '.*'

However, this command did not work as expected.

Questions:

  1. What is the correct syntax to delete all Kafka topics at once using the kafka-topics.sh command-line tool with a regular expression pattern?
  2. Are there any precautions or considerations I should be aware of when deleting all topics in Kafka?

If any more information is needed or if there are additional considerations, please let me know. Thank you!


Solution

  • Simply use this command. It will delete all topics in your Kafka cluster:

    ./bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic '.*'