Skip to content

How to Fix Postfix Queue Flush Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Postfix Queue Flush Error. We cover key concepts, practical examples, and best practices.

Postfix mail is stuck in the queue with status deferred and postqueue -f does not flush them — the mail servers cannot be reached or the queue is corrupted.

The Problem

$ mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
9A1B2C3D4E5F*   1234  Tue Jun 24 10:00:00  sender@example.com
                                           (connect to mx.example.com[10.0.0.1]:25: Connection timed out)

Step-by-Step Fix

Step 1: Check the queue

sudo postqueue -p
# Or use mailq command
mailq

Step 2: View deferred queue details

sudo postcat -q 9A1B2C3D4E5F

Step 3: Flush the queue

sudo postqueue -f

Step 4: Flush specific sender's mail

sudo postqueue -s sender@example.com

Step 5: Force delivery attempt

# Force immediate delivery attempt for deferred messages
sudo postsuper -r 9A1B2C3D4E5F
sudo postqueue -f

Step 6: Delete stuck messages

sudo postsuper -d 9A1B2C3D4E5F
# Delete all deferred messages (caution!)
sudo postsuper -d ALL deferred

Step 7: Check queue management settings

# /etc/postfix/main.cf
maximal_queue_lifetime = 5d
bounce_queue_lifetime = 5d
minimal_backoff_time = 300s
maximal_backoff_time = 4000s
queue_run_delay = 300s

Prevention Tips

  • Monitor queue size with mailq | tail -1
  • Set queue_run_delay to a reasonable interval
  • Configure maximal_queue_lifetime to auto-expire old mail
  • Set up queue monitoring alerts

Common Mistakes with queue flush

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world POSTFIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does my Postfix queue have stuck messages?

Messages are deferred when the destination mail server is unreachable, rejects the connection, or has a temporary error. The queue retries delivery at intervals defined by minimal_backoff_time and maximal_backoff_time.

How do I force Postfix to attempt delivery immediately?

Run sudo postqueue -f to flush the entire queue. For individual messages, use sudo postsuper -r QUEUE_ID to requeue the message, then postqueue -f to trigger immediate delivery attempts.

What is the difference between active and deferred queues?

The active queue contains messages being delivered right now. The deferred queue contains messages that failed temporarily and are waiting for the next retry. Use mailq to see deferred messages and sudo postqueue -p for a detailed view.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro