<@U078Y59KC3B> how can I purge all retained messag...
# ask-ai
s
@RunLLM how can I purge all retained messages for a topic?
r
It seems likely that to purge all retained messages for a topic in Pulsar, you should use the truncate operation. Truncating a topic moves all cursors to the end and deletes all inactive ledgers, effectively removing all retained messages for that topic. This can be done via the Pulsar admin CLI with the command:
Copy code
pulsar-admin topics truncate persistent://tenant/namespace/topic
This operation is also available via the Java admin API as
admin.topics().truncate(topic)
. Note that the latest ledger cannot be deleted, but all previous data is removed. Would you like more detail on how this affects subscriptions or on alternative approaches? Sources: - CmdTopics.java (truncate) 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.