Click to copy

• Reviewed for ksqlDB 0.29

How to Delete a Stream in ksqlDB

To delete a stream:

DROP STREAM stream_name;

If you also want to delete the underlying topic, add the DELETE TOPIC modifier:

DROP STREAM stream_name DELETE TOPIC;
How to find what’s the underlying topic of a topic.

Streams always have a physical topic

If you created a stream by importing an existing topic, be careful!

If you run a DROP STREAM ... DELETE TOPIC statement, you will be also deleting the underlying topic that existed way before your stream was created. You will lose data that you didn’t produce.

The stream is used by persistent queries

ksqlDB will prevent you from deleting any stream that is being read or written by persistent queries. You will get the error message below:

Cannot drop STREAM_NAME.
The following queries read from this source: [].
The following queries write into this source: [INSERTQUERY_83].
You need to terminate them before dropping STREAM_NAME.

As you can see, the error “Cannot drop stream_name” lists all the queries that are using the stream. To avoid this error, terminate any query that is using the stream you want to delete.

TERMINATE query_id;
You can read about How to describe a query to know more about the queries that are listed in the error, or How to list persistent queries if you need to know about other queries.

The underlying topic is used by other streams

If you try to delete the stream and its underlying topic, you can get the error below:

Refusing to delete topic. Found other data sources (<stream_name>) using topic <topic_name>

The error is telling you that there are other streams using that same topic as its underlying topic. This can happen when you create streams from existing topics. To prevent this error, d elete all the streams except one using DROP STREAM stream_name, and add the DELETE TOPIC modifier when you drop the last stream.

-- Example for 3 streams using the same topic
DROP STREAM stream1;
DROP STREAM stream2;
DROP STREAM stream3 DELETE TOPIC;
Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like