How to Check Postfix Mail Queue Size: Equivalent to `sendmail -bp` Command


3 views

When working with Postfix mail servers, monitoring the queue is crucial for troubleshooting email delivery issues. The sendmail -bp command was traditionally used in Sendmail to display queue information, but Postfix has its own set of commands for queue management.

The primary command to check Postfix queue size is:

postqueue -p

This command provides a detailed listing of all messages currently in the queue, showing:

  • Queue ID
  • Message size
  • Arrival time
  • Sender address
  • Recipient addresses

For a quick count of messages in the queue:

mailq | wc -l

Note: This will return the count plus 1 (for the header line), so you might want to adjust accordingly:

echo $(($(mailq | wc -l) - 1))

For more detailed queue analysis, you can use:

postqueue -j

This outputs JSON format queue information, useful for programmatic processing.

Here's a simple bash script to monitor queue size and alert when it exceeds a threshold:

#!/bin/bash
QUEUE_SIZE=$(postqueue -p | tail -n 1 | awk '{print $5}')
THRESHOLD=100
if [ "$QUEUE_SIZE" -gt "$THRESHOLD" ]; then
    echo "Warning: Postfix queue size ($QUEUE_SIZE) exceeds threshold ($THRESHOLD)"
    # Add notification logic here
fi

To specifically check the deferred queue:

postqueue -p | grep -c "^[A-F0-9]\+.*deferred"

For busy mail servers, avoid running queue inspection commands too frequently as they:

  • Can impact server performance
  • May lock queue files temporarily
  • Generate considerable I/O load

When working with Postfix mail servers, checking the queue size is a common administrative task. Unlike Sendmail's sendmail -bp command, Postfix has its own set of tools for queue management.

The main command to view the Postfix queue is:

postqueue -p

This provides a formatted list of all messages in the queue, similar to sendmail -bp output. For just the count:

mailq | wc -l

For more detailed queue statistics:

postqueue -p | grep -c "^[A-F0-9]"

This counts active queue entries while excluding summary lines. For specific queue types:

qshape active
qshape deferred

Create a monitoring script:

#!/bin/bash
QUEUE_SIZE=$(mailq | grep -c "^[A-F0-9]")
echo "Postfix queue size: $QUEUE_SIZE"
if [ $QUEUE_SIZE -gt 100 ]; then
    echo "Warning: Large queue detected" >&2
    exit 1
fi

For high-volume servers, these alternatives are more efficient:

postcat -q | wc -l
find /var/spool/postfix/{active,deferred} -type f | wc -l