Jump to Navigation

Postfix Queue Troubleshooting after spam attack

If you run postfix for your mail there may come a time when you need to deal with queue congestion that leads to a marked degradation of service with mail not being received or delivered. Usually this is your first indication that something is wrong.

To check the status of the postfix queue you need to run the "qshape" command. The queue to check is normally the deferred queue. I.E. "qshape deferred". This will give you a summary of whats in the queue. Unfortunately the command is less useful when you have a huge backlog of mail, as it takes long to process. As far as I can tell there is no summary option. So if the command is taking long to complete you can assume the queue is flooded and proceed to the steps set out below to clean our the queue.

Now that you know there is a problems with the queues you need to delete the spam messages form the queue you use the "postsuper"  command for this.The steps to follow are as follows:

  1. Put all suspected mail on hold by running "postsuper -h deferred" ,
  2. Analyse the hold queue with "qshape hold",
  3. Decide which mails need to be deleted from the queue and run the command:
     mailq | tail +2 | awk  ´BEGIN { RS = "" }
                      # $7=sender, $8=recipient1, $9=recipient2
                      { if ($8 == "user@example.com" && $9 == "")
                            print $1 }
                  ´ | tr -d ’*!’ | postsuper -d -
    I got this command from the postsuper man pages. As per the comment above $7= sender addres, $8= recipient address and $9=recipient2. You can thus filter on what criteria is the most appropriate.
  4. Now that the queue is clean out you can resubmit the remaining messages. First check the queue again with "qshape hold" and see if it looks reasonable then run "postsuper -r ALL" . This will resubmit all mail for delivery.

It seems that postscript queue tools are only really performant if the queue are not that big. If the queues are massive then don't be surprised if you can write "war and peace" in the time it takes to complete the commands :)

Open Source: 


by Dr. Radut.