Score:0

postfix mail consumes too much memory of ubuntu server

cn flag

I had an issue, that the mail server always crashes. after investigations i found out, that it is a system memory issue. server had 8GB Ram and i've increased it to 16GB. it is now much better but still consuming too much memory.

following is top processes in my server:

top

top - 15:36:40 up  7:58,  1 user,  load average: 91.59, 92.19, 91.31
Tasks: 455 total,  92 running, 306 sleeping,   0 stopped,   0 zombie
%Cpu(s): 96.4 us,  1.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  2.6 st
KiB Mem : 16424716 total,  2802776 free, 12251708 used,  1370232 buff/cache
KiB Swap:   924356 total,   924356 free,        0 used.  3784484 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                
  964 clamav    20   0 1645784 1.273g  32748 S   0.0  8.1   4:18.12 clamd                                                                                                                                  
 1553 gdm       20   0 4443620 208048  95508 S   0.0  1.3   2:05.02 gnome-shell                                                                                                                            
 3413 amavis    20   0  356716 154252   9072 S   0.0  0.9   0:07.12 /usr/sbin/amavi                                                                                                                        
 3040 amavis    20   0  347712 149016  11156 S   0.0  0.9   0:08.39 /usr/sbin/amavi                                                                                                                        
 5892 root      20   0  370164 136068  25584 S   0.0  0.8   2:13.00 python                                                                                                                                 
 4493 root      20   0  370336 135972  25132 S   0.0  0.8   2:13.02 python                                                                                                                                 
 8301 root      20   0  368636 134792  25836 S   0.0  0.8   2:00.70 python                                                                                                                                 
 7144 root      20   0  368792 134440  25144 S   0.0  0.8   2:07.06 python                                                                                                                                 
 9649 root      20   0  368120 134328  25884 S   0.0  0.8   1:56.14 python                                                                                                                                 
10783 root      20   0  367268 133152  25420 S   0.0  0.8   1:53.38 python                                                                                                                                 
13154 root      20   0  367348 132748  25648 S   0.0  0.8   1:36.12 python                                                                                                                                 
11919 root      20   0  366560 132388  25444 S   0.0  0.8   1:43.54 python                                                                                                                                 
14346 root      20   0  367096 131868  25016 S   2.6  0.8   1:31.55 python                                                                                                                                 
19062 root      20   0  366328 131736  25652 S   0.3  0.8   1:19.97 python                                                                                                                                 
16717 root      20   0  365796 131604  25420 S   0.0  0.8   1:24.49 python                                                                                                                                 
17853 root      20   0  365536 131392  25472 S   0.0  0.8   1:21.33 python                                                                                                                                 
15498 root      20   0  365796 131320  25140 S   0.0  0.8   1:29.81 python                                                                                                                                 
20243 root      20   0  365284 131140  25460 S   0.0  0.8   1:19.88 python                                                                                                                                 
  279 root      19  -1  242048 130968 126460 S   0.3  0.8   1:15.33 systemd-journal                                                                                                                        
26318 root      20   0  364768 130960  25788 S   0.0  0.8   1:09.60 python                                                                                                                                 
32401 root      20   0  365308 130912  25832 S   0.0  0.8   0:59.69 python                                                                                                                                 
22580 root      20   0  366072 130868  25036 S   0.3  0.8   1:08.76 python                                                                                                                                 
21384 root      20   0  365020 130852  25444 S   0.0  0.8   1:17.45 python                                                                                                                                 
27530 root      20   0  364512 130736  25824 S   0.0  0.8   1:07.66 python                                                                                                                                 
28671 root      20   0  364508 130684  25772 S   0.0  0.8   1:04.15 python                                                                                                                                 
29843 root      20   0  364512 130672  25756 S   0.0  0.8   0:59.03 python                                                                                                                                 
25090 root      20   0  364768 130492  25320 S   0.0  0.8   1:05.57 python                                                                                                                                 
23942 root      20   0  364768 130296  25132 S   0.0  0.8   1:12.47 python                                                                                                                                 
 7924 root      20   0  365060 130240  25404 S   0.3  0.8   0:50.47 python                                                                                                                                 
 9111 root      20   0  364788 130236  25668 S   0.0  0.8   0:48.10 python                                                                                                                                 
22928 root      20   0  364536 130160  25836 S   0.0  0.8   0:43.47 python                                                                                                                                 
31206 root      20   0  364256 130100  25460 S   0.3  0.8   0:59.90 python                                                                                                                                 
12915 root      20   0  364796 130000  25420 S   0.0  0.8   0:47.30 python                                                                                                                                 
21741 root      20   0  364536 129984  25656 S   0.0  0.8   0:43.85 python                                                                                                                                 
 6738 root      20   0  364004 129976  25852 S   0.0  0.8   0:51.10 python                                                                                                                                 
30436 root      20   0  364284 129956  25876 S   0.0  0.8   0:39.76 python                                                                                                                                 
 4116 root      20   0  363588 129940  25824 S   0.0  0.8   0:58.51 python                                                                                                                                 
26669 root      20   0  364280 129936  25856 S   0.0  0.8   0:39.85 python                                                                                                                                 
25399 root      20   0  364280 129884  25808 S   0.0  0.8   0:42.84 python                                                                                                                                 
 2866 root      20   0  364000 129864  25744 S   0.0  0.8   0:58.40 python                                                                                                                                 
 1283 root      20   0  364256 129836  25460 S   0.0  0.8   0:57.17 python                                                                                                                                 
29214 root      20   0  364276 129736  25656 S   0.0  0.8   0:39.39 python                                                                                                                                 
12123 root      20   0  364024 129712  25844 S   0.0  0.8   0:17.65 python                                                                                                                                 
32542 root      20   0  364032 129708  25840 S   0.0  0.8   0:22.26 python                                                                                                                                 
16486 root      20   0  364536 129640  25316 S   0.0  0.8   0:48.89 python                                                                                                                                 
29915 root      20   0  364024 129516  25656 S   0.3  0.8   0:22.66 python                                                                                                                                 
 5311 root      20   0  364000 129508  25388 S   0.0  0.8   0:54.04 python                                                                                                                                 
 9457 root      20   0  364020 129484  25620 S   0.0  0.8   0:17.12 python                                                                                                                                 
22049 root      20   0  364024 129480  25604 S   0.0  0.8   0:11.85 python                                                                                                                                 
20229 root      20   0  363488 129400  25776 S   0.0  0.8   0:42.52 python                                                                                                                                 
27892 root      20   0  363228 129324  25840 S   0.0  0.8   0:39.54 python                                                                                                                                 
11732 root      20   0  363744 129308  25428 S   0.0  0.8   0:46.03 python                                                                                                                                 
15344 root      20   0  363748 129284  25400 S   0.0  0.8   0:45.86 python                                                                                                                                 
14216 root      20   0  363740 129184  25320 S   0.0  0.8   0:46.72 python                                                                                                                                 

Also postgredSql reachs max_connections and then closes because of too many requests from postfix.

Following is the log file of mail:

Feb 18 14:17:19 mail postfix/smtp[29560]: D3D5E2466DA: to=<[email protected]>, relay=none, delay=0.11, delays=0.1/0.01/0/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:17:19 mail postfix/qmgr[3350]: D3D5E2466DA: removed
Feb 18 14:18:14 mail dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=80.144.15.182, lip=173.212.211.113, mpid=7829, TLS, session=<OAIlQ/n05+pQkA+2>
Feb 18 14:18:18 mail dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=80.144.15.182, lip=173.212.211.113, mpid=7849, TLS, session=<bwdWQ/n06OpQkA+2>
Feb 18 14:18:20 mail dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=80.144.15.182, lip=173.212.211.113, mpid=7870, TLS, session=<3kR5Q/n06+pQkA+2>
Feb 18 14:18:20 mail postfix/pickup[6431]: 4D4DD246690: uid=132 from=<opendkim>
Feb 18 14:18:20 mail postfix/cleanup[2707]: 4D4DD246690: message-id=<[email protected]>
Feb 18 14:18:20 mail opendkim[1289]: 4D4DD246690: no signing table match for '[email protected]'
Feb 18 14:18:20 mail opendkim[1289]: 4D4DD246690: no signature data
Feb 18 14:18:20 mail postfix/qmgr[3350]: 4D4DD246690: from=<[email protected]>, size=1286, nrcpt=1 (queue active)
Feb 18 14:18:21 mail postfix/pickup[6431]: 67DEC246691: uid=0 from=<root>
Feb 18 14:18:21 mail postfix/cleanup[5432]: 67DEC246691: message-id=<[email protected]>
Feb 18 14:18:21 mail opendkim[1289]: 67DEC246691: no signing table match for '[email protected]'
Feb 18 14:18:21 mail opendkim[1289]: 67DEC246691: no signature data
Feb 18 14:18:21 mail postfix/pickup[6431]: B5152246696: uid=1005 from=<vmail>
Feb 18 14:18:21 mail postfix/cleanup[32236]: B5152246696: message-id=<[email protected]>
Feb 18 14:18:23 mail opendkim[1289]: B5152246696: no signing table match for '[email protected]'
Feb 18 14:18:23 mail opendkim[1289]: B5152246696: no signature data
Feb 18 14:18:25 mail postfix/qmgr[3350]: B5152246696: from=<[email protected]>, size=1261, nrcpt=1 (queue active)
Feb 18 14:18:26 mail postfix/qmgr[3350]: 67DEC246691: from=<[email protected]>, size=1241, nrcpt=1 (queue active)
Feb 18 14:18:27 mail postfix/smtp[27388]: 4D4DD246690: to=<[email protected]>, orig_to=<opendkim>, relay=none, delay=6.7, delays=0.3/6.4/0.08/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:27 mail postfix/smtp[29560]: B5152246696: to=<[email protected]>, orig_to=<vmail>, relay=none, delay=5.3, delays=3.4/1.9/0/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:27 mail postfix/smtp[27388]: 67DEC246691: to=<[email protected]>, orig_to=<root>, relay=none, delay=5.7, delays=5.6/0.08/0/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:27 mail postfix/cleanup[2707]: 23AE42466F3: message-id=<[email protected]>
Feb 18 14:18:27 mail postfix/cleanup[32236]: 397BB24670C: message-id=<[email protected]>
Feb 18 14:18:27 mail postfix/bounce[7904]: 67DEC246691: sender non-delivery notification: 397BB24670C
Feb 18 14:18:27 mail postfix/qmgr[3350]: 397BB24670C: from=<>, size=3318, nrcpt=1 (queue active)
Feb 18 14:18:27 mail postfix/bounce[7903]: B5152246696: sender non-delivery notification: 23AE42466F3
Feb 18 14:18:27 mail postfix/qmgr[3350]: 67DEC246691: removed
Feb 18 14:18:27 mail postfix/qmgr[3350]: B5152246696: removed
Feb 18 14:18:27 mail postfix/qmgr[3350]: 23AE42466F3: from=<>, size=3345, nrcpt=1 (queue active)
Feb 18 14:18:27 mail postfix/smtp[29560]: 397BB24670C: to=<[email protected]>, relay=none, delay=0.81, delays=0.1/0.7/0/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:27 mail postfix/smtp[27388]: 23AE42466F3: to=<[email protected]>, relay=none, delay=0.81, delays=0.8/0.01/0/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:27 mail postfix/qmgr[3350]: 397BB24670C: removed
Feb 18 14:18:27 mail postfix/qmgr[3350]: 23AE42466F3: removed
Feb 18 14:18:28 mail postfix/cleanup[5432]: 0C3EC2466A0: message-id=<[email protected]>
Feb 18 14:18:28 mail postfix/bounce[3449]: 4D4DD246690: sender non-delivery notification: 0C3EC2466A0
Feb 18 14:18:28 mail postfix/qmgr[3350]: 0C3EC2466A0: from=<>, size=3391, nrcpt=1 (queue active)
Feb 18 14:18:28 mail postfix/qmgr[3350]: 4D4DD246690: removed
Feb 18 14:18:28 mail postfix/smtp[7902]: 0C3EC2466A0: to=<[email protected]>, relay=none, delay=1.4, delays=1.3/0.09/0.01/0, dsn=5.4.6, status=bounced (mail for mail.MyDomain.de loops back to myself)
Feb 18 14:18:28 mail postfix/qmgr[3350]: 0C3EC2466A0: removed
Feb 18 14:19:14 mail postfix/pickup[6431]: AFA9B246690: uid=132 from=<opendkim>
Feb 18 14:19:14 mail postfix/cleanup[2707]: AFA9B246690: message-id=<[email protected]>
Feb 18 14:19:14 mail opendkim[1289]: AFA9B246690: no signing table match for '[email protected]'
Feb 18 14:19:14 mail opendkim[1289]: AFA9B246690: no signature data
Feb 18 14:19:14 mail postfix/qmgr[3350]: AFA9B246690: from=<[email protected]>, size=6085, nrcpt=1 (queue active)
Feb 18 14:19:14 mail postfix/pickup[6431]: C90C5246691: uid=1005 from=<vmail>
Feb 18 14:19:14 mail postfix/cleanup[32236]: C90C5246691: message-id=<[email protected]>
Feb 18 14:19:14 mail opendkim[1289]: C90C5246691: no signing table match for '[email protected]'
Feb 18 14:19:14 mail opendkim[1289]: C90C5246691: no signature data
Feb 18 14:19:14 mail postfix/proxymap[7906]: warning: connect to pgsql server 127.0.0.1: FATAL:  remaining connection slots are reserved for non-replication superuser connections?
Feb 18 14:19:14 mail postfix/trivial-rewrite[5409]: warning: virtual_alias_domains: proxy:pgsql:/etc/postfix/sql-domain-aliases.cf: table lookup problem
Feb 18 14:19:14 mail postfix/trivial-rewrite[5409]: warning: virtual_alias_domains lookup failure

as you see, the mail to [email protected] and from [email protected] and to [email protected] are keep running, even in times we did't do anything.

I suppose they are the reason. Is this normal? how can i stop them? As you see the postgredSql is stoped because of them and now the mail server not reachable any more.

I don't know how to handle this or it is just normal. i would be glad for any help!

Nikita Kipriyanov avatar
za flag
Is **clamd** the service that you are concerned with? It's the antivirus tool which needs its signature database in memory. Any antivirus will eat RAM, and clamav is not an exception, and 1.2G is very small compared to other solutions (like Kaspersky who can easily eat tens of gigabytes). Other than that, I see 3.7G of your RAM is free for application use; are there still any problems?
Nikita Kipriyanov avatar
za flag
Also, is this a *server*? What *gdm* process is doing on the machine which is supposed to be a mail server?
El-Salatinie avatar
cn flag
Gdm was for testing. I have disabled it but it didn’t consume too much memory. The problem is, that postgredsql has maximum connections 100. This value was reached and then postfix can’t connect to db. After i restarted postgredsq service, the server was relaxed again and those python processes reduced to just one. There is a process in postfix repeats it self till all connections are busy. @NikitaKipriyanov
anx avatar
fr flag
anx
The clamav installation guide has some guidance on how to limit postfix service count to a maximum effective usage in non-postfix services that will fit your limited memory. I don't see the warning about reaching the limit in your logs. What did you set the limits to?
Nikita Kipriyanov avatar
za flag
I don't see *any* postfix processes in your top. Really, absolutely none of them. Why is it called "postfix consumes too much memory", how you ever came to this (false) conclusion? Clamav memory consumption is quite typical and not to worry about. For limiting and pooling database connection, use Postfix's [proxymap](https://www.postfix.org/proxymap.8.html) service, but this is *not* about postfix memory consumption.
El-Salatinie avatar
cn flag
The problem is now pretty clear to me, why the server consumes too much memory. The postfix is getting in a loop trying to validate domain ( i guess). This is not appearing in this part of the logs. that's why i created a new ticket explaining the problem. https://serverfault.com/questions/1123275/why-postfix-is-trying-to-send-always-a-mail-to-opendkimmail-domain-how-to-prev
El-Salatinie avatar
cn flag
@NikitaKipriyanov all these Python processes are because of postfix. I don’t have any other python code running on the server.
El-Salatinie avatar
cn flag
@NikitaKipriyanov proxap seems to be the right solution for my issue i‘ll let you know if it works. Do you know if it is even normal, that the mail server has too much requests to handle (opendkim, vmail,root) and if it is possible to reduce this amount?
El-Salatinie avatar
cn flag
Hi @anx, the memory consumption issue is shown in the top log. You see that python processes are all over the list. After i increased the ram it is now not an issue for the sercer itself, but the mail server it can’t connect to db cuz of that amount of requests (last 2 rows in the log)
Nikita Kipriyanov avatar
za flag
This can be normal. This is very variable and depends entirely on the mail traffic you have. Everybody has their own. Yes, this is Internet, you can have a huge spike of requests and you should be able to cope with it.
El-Salatinie avatar
cn flag
@NikitaKipriyanov i couldn't configure the proxymap you mentioned before. Do you know how can i set a mapping for virtual_alias, that don't need db connection just like from a local file? And only if not found then it has to go over db. If have such concept, i could have the problem solved!
El-Salatinie avatar
cn flag
@NikitaKipriyanov i could locate the problem. The problem is because of parameter: virtual_alias_maps, which has always to ask db for each request from those 2 senders. do you know how can i just ignore those 2 senders from been checked against database? main config you find in following ticket: https://serverfault.com/questions/1123434/how-to-ignore-sender-from-looking-in-virtual-alias-maps
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.