Introduction to Postfix Queue Internals
Postfix stores incoming and outgoing email messages within its queue structure while they await delivery. The queue acts as a transient holding area, keeping mail data on disk until it can be safely transmitted to the next destination.
Understanding how Postfix organizes and processes the queue is key to administering the mail system and troubleshooting issues.
Postfix Architecture Overview
The Postfix mail transport agent is structured as a group of small, specialized daemon processes for efficiently routing high volumes of email. Incoming messages get divided amongst different queues as they traverse Postfix subsystems:

The central queue manager oversees mail delivery, determining the next hop destination and handing off to the appropriate daemon like SMTP, local delivery etc. The queue provides persistence, ensuring mail gets retried in case of temporary failures.
Postfix Queue Structure on Disk
Postfix stores the mail queue as files in structured directories on disk, typically under /var/spool/postfix. This allows messages to persist through daemon or server restarts. The main queue types get their own subfolder:
/var/spool/postfix/ - incoming/ - active/ - deferred/ - hold/
This is separate from user mailboxes located under /var/mail.
Queue Lifecycle States
As messages get processed, they transition between the different Postfix queues:
- Incoming: Landing area for new messages Postfix accepts
- Active: Messages being actively delivered to their destinations
- Deferred: Failed deliveries postponed for later retries
- Hold: Administratively held messages e.g. suspected spam
Understanding what leads messages getting "stuck" in each state is key for troubleshooting issues…
Checking Postfix Queue Status
Postfix provides several informational commands for checking queue status:
postqueue -p
Viewing the queue with postqueue -p shows key metadata on current messages:
[root@mail ~]# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient--------
9D153B42426* 12024 Tue Jan 5 11:22:44 john@example.com
jane@example.net
This prints the message size, arrival timestamp, sender, recipient address and unique queue ID. The ID maps the message back to the file on disk under the queue directories.
mailq
The mailq command provides a simpler queue listing, omitting details like size and queue ID. Typically you‘d pipe mailq to a pager for readability:
mailq | more
postcat -q
To view the contents of a specific queued message, use postcat passing the queue ID from postqueue output:
postcat -q 9D153B42426 > message.txt
This saves the full message including headers and body to a file for inspection.
Queue Size Statistics and Trends
Keeping tabs on queue levels over time is important to spot issues proactively. Here are typical queue size averages to maintain for good mail flow:
- Incoming queue: < 50 messages
- Active queue: < 100 messages
- Deferred queue: < 10 messages
Graphing historical statistics helps visualize trends:

Look for gradual ramp-ups indicating capacity issues before queues grow out of control.
Queue Monitoring Tools
Consider using automation tools for collecting queue stats and establishing warning thresholds, including:
- postqueue_mailq_stats.pl – Reporting script providing graphs
- Monitorix – System dashboard with mail queue levels
- Nagios – Alerting when queues exceed set limits
Proactive monitoring is crucial for managing queue issues.
Managing the Queue Lifecycle
Now let‘s explore some of the key techniques around managing queued Postfix messages…
Retrying Failed Messages
If messages end up deferred due to transient errors, prompt Postfix to reattempt delivery with:
postqueue -f
This reschedules all messages in the deferred queue for fresh delivery attempts.
Placing Messages On Hold
To remove a message from active queues without bouncing, administratively place it on hold:
postsuper -h 9D153B42426
Held high-volume mail may indicate compromised accounts sending spam. Investigate before releasing hold.
Deleting Messages
Removing messages permanently from the mail queue uses the postsuper command. For example deleting by queue ID:
postsuper -d 9D153B42426
Use caution – deleted messages are gone for good!
You can also delete entire queue classes like deferred.
Troubleshooting Postfix Queue Issues
Here is an overview workflow when facing mail delivery problems:
Inspect Message Headers
Check message headers in the queue for honing in on issues:
postcat -q 9D153B42426 | more
Look for:
- SMTP response codes like
450indicating rejections - Deferred status flags
- Spam filter analysis headers e.g X-Spam-Status if using SpamAssassin
Check Mail Logs
/var/log/maillog records delivery statuses, deferral reasons, and spam detection outcomes driving queue behavior. Graph queue sizes against log entries to correlate.
Verify DNS Settings
Improper DNS configurations like missing MX records for target domains can lead to freezing messages in active queues. Validate with tools like dig, host, nslookup.
Check Reputation Listings
Third-party DNS blocklists like Spamhaus or DNSBL can cause silent drops from destination servers. Query RBLs to detect if your IPs have poor reputation.
Methodically gather data until the root cause emerges.
Tuning Postfix Performance
Adjust Postfix settings to handle heavy loads gracefully, including:
- minimal_backoff_time – Lower for faster redeliveries
- maximal_queue_lifetime – Extend from 5d default to avoid bounces
- bounce_queue_limit – Increase for more processing capacity
Strike a balance between delivery performance and overloading recipients.
External Postfix Content Checkers
Implementing additional policy checks external to Postfix can improve mail quality:
Spam Checks
SpamAssassin examines messages and adds X-Header ratings allowing Postfix to defer likely spam using content_filter policies:
spam checks = reject_spam_threshold=10
This blocks messages scoring over 10 points on SpamAssassin‘s 0-5 scale.
Malware Scanning
Integrate virus scanning tools like ClamAV to intercept malware payloads in messages:
incoming_mail_filter = clamd
Detected threats can be automatically dropped from queues maintaining system integrity.
Architecting For High Volume Mail
For large environments, apply best practices like:
- Distribute services across servers – Dedicate separate VMs for incoming vs outbound traffic
- Scale horizontally – Add more Postfix instances behind load balancer
- Sharded directories – Partitions queue across spindles for I/O concurrency
Compare to alternatives like Sendmail or Exim when evaluating beyond basic workloads.
Conclusion
We‘ve explored various techniques around monitoring, managing and troubleshooting the Postfix mail queue.smooth mail flow depends on keeping your queues tuned.
Watch queue levels closely for early warning signs of issues. Take a methodical approach when diagnosing delivery problems. And optimize Postfix configuration to gracefully handle target volumes.
Following these industry best practices for Postfix queue management will keep your mail pipeline operating reliably!


