Check the size of a Postfix mail queue

Use postqueue to inspect queued messages, count entries, and trace delivery delays before retrying or deleting mail.

Best practices
Illustration of a Linux server and log data

Run postqueue -p to list queued messages and see a summary. Each entry includes a queue ID, message size, arrival time, sender, and recipients still awaiting delivery. When the last attempt failed, the listing can also show the reason.

postqueue -p
postqueue -p | tail -n 1

A nonempty queue ends with a summary such as -- 10 Kbytes in 5 Requests. An empty queue reports Mail queue is empty. The total is a count of queued messages, not a count of log lines or individual delivery attempts.

Count entries for monitoring

Postfix 3.1 and later provide JSON Lines output:

set -o pipefail
postqueue -j | jq -s 'length'

This requires jq; slurping the listing uses memory proportional to queue size. Treat the output as a changing observation, not a transactional snapshot: messages can enter or leave during enumeration, and the manual notes that entries can be missed or repeated. Check the command's exit status so a queue-access failure is not reported as an empty queue.

Find the cause before forcing retries

On systems that write mail logs to files:

tail -n 100 /var/log/mail.log
# A common alternative on RHEL-family systems:
tail -n 100 /var/log/maillog

The actual destination depends on syslog and Postfix logging configuration. Correlate the queue ID with DNS errors, connection timeouts, temporary SMTP rejection, or blocked outbound port 25. A temporary 450 can remain queued for retry; a permanent 550 normally causes a delivery failure and bounce rather than an endless retry of that recipient.

After correcting the cause, request a retry:

postqueue -i A705238B4C
# Or request a flush of the whole queue:
postqueue -f

Repeatedly flushing undeliverable mail can degrade delivery for other messages. Held mail remains held until released.

Hold or delete only the intended messages

These operations change queue state and normally require administrative permission:

sudo postsuper -h A705238B4C
sudo postsuper -H A705238B4C
sudo postsuper -d A705238B4C

-h holds a message, -H releases it, and -d deletes it permanently. postsuper -d ALL deletes all selected queue messages; postsuper -d ALL deferred limits deletion to the deferred queue. Use those broad operations only after confirming the entire scope. Deleting mail does not fix the cause of a growing queue.

Find the configured spool with postconf queue_directory, often /var/spool/postfix. Use Postfix tools rather than deleting files from active, deferred, or hold directly.

Common questions

How long will mail be retried? Check postconf maximal_queue_lifetime bounce_queue_lifetime. The documented defaults are five days, but local settings and message state matter; held messages are not subject to ordinary queue expiration while held.

Why is one sender dominating the queue? Investigate an abused account, compromised local application, or a downstream delivery problem. Hold selected samples and stop the source before clearing the backlog.

How do I release all held messages? postsuper -H ALL is available, but releasing a large held queue can create a surge. Verify why those messages were held first.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting