Обсуждение: vacuumdb causes memory drain.

Поиск
Список
Период
Сортировка

vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:

Hello Gurus, 


Looking for some help, and  if anybody has come across this type of scenario. 


Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
the process is over, memory is not released, is it normal or something needs to be 
changed ? also other processes start running slow afterwards due to low memory.  

O/S: Ubuntu VERSION="16.04.4 LTS (Xenial Xerus)"
PG : PostgreSQL 9.5.12 
CPUs: 2
Memory:4GB
Swap:4GB

max_connections = 10
shared_buffers = 1GB
effective_cache_size = 3GB
maintenance_work_mem = 256MB
min_wal_size = 2GB
max_wal_size = 4GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 4
effective_io_concurrency = 2
max_worker_processes = 2
work_mem = 104857kB


Thanks,
Sushil...

Re: vacuumdb causes memory drain.

От
Don Seiler
Дата:
On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:


Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
the process is over, memory is not released, is it normal or something needs to be 
changed ? also other processes start running slow afterwards due to low memory.  

How are you measuring free memory? Memory might be listed in cached/buffers instead of free but is still available. Although that wouldn't then explain other processes being slow.

--
Don Seiler
www.seiler.us

Re: vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:

I have put some small script which runs in a loop with "free -h" command, 

while I am running "vacuumdb".  Once I clear by "sync" or bounce PG, 

everything runs normal afterward.




From: Don Seiler <don@seiler.us>
Sent: Thursday, April 26, 2018 11:33 AM
To: Sushil Shirodkar
Cc: pgsql-admin@postgresql.org
Subject: Re: vacuumdb causes memory drain.
 
On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:


Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
the process is over, memory is not released, is it normal or something needs to be 
changed ? also other processes start running slow afterwards due to low memory.  

How are you measuring free memory? Memory might be listed in cached/buffers instead of free but is still available. Although that wouldn't then explain other processes being slow.

--
Don Seiler
www.seiler.us

Re: vacuumdb causes memory drain.

От
Laurenz Albe
Дата:
Sushil Shirodkar wrote:

> > On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
> > > Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
> > > noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
> > > the process is over, memory is not released, is it normal or something needs to be 
> > > changed ? also other processes start running slow afterwards due to low memory.  
> >
> > How are you measuring free memory? Memory might be listed in cached/buffers instead of
> > free but is still available. Although that wouldn't then explain other processes being slow.
>
> I have put some small script which runs in a loop with "free -h" command,
> while I am running "vacuumdb".  Once I clear by "sync" or bounce PG,
> everything runs normal afterward.

Then I would say everything is fine.
It is normal for a Linux system to have almost no free memory; the memory is used
for the file system cache.

Do you experience any problems, like reduced performance or high I/O?

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


Re: vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:
Performance issue.

Can I restrict memory usage at session level in the script where I run
Vacuum DB ?

> On Apr 27, 2018, at 2:06 AM, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> Sushil Shirodkar wrote:
>
>>>> On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
>>>> Running "vacuumdb -a -z -v" from the cron on one of our test environment, and
>>>> noticed that memory of the server goes down from 3.4GB free to 150MB.  Once
>>>> the process is over, memory is not released, is it normal or something needs to be
>>>> changed ? also other processes start running slow afterwards due to low memory.
>>>
>>> How are you measuring free memory? Memory might be listed in cached/buffers instead of
>>> free but is still available. Although that wouldn't then explain other processes being slow.
>>
>> I have put some small script which runs in a loop with "free -h" command,
>> while I am running "vacuumdb".  Once I clear by "sync" or bounce PG,
>> everything runs normal afterward.
>
> Then I would say everything is fine.
> It is normal for a Linux system to have almost no free memory; the memory is used
> for the file system cache.
>
> Do you experience any problems, like reduced performance or high I/O?
>
> Yours,
> Laurenz Albe
> --
> Cybertec | https://www.cybertec-postgresql.com


Re: vacuumdb causes memory drain.

От
Laurenz Albe
Дата:
Sushil Shirodkar wrote:
> > > > > On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
> > > > > Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
> > > > > noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
> > > > > the process is over, memory is not released, is it normal or something needs to be 
> > > > > changed ? also other processes start running slow afterwards due to low memory.  
> > > > 
> > > > How are you measuring free memory? Memory might be listed in cached/buffers instead of
> > > > free but is still available. Although that wouldn't then explain other processes being slow.
> > > 
> > > I have put some small script which runs in a loop with "free -h" command,
> > > while I am running "vacuumdb".  Once I clear by "sync" or bounce PG,
> > > everything runs normal afterward.
> > 
> > Then I would say everything is fine.
> > It is normal for a Linux system to have almost no free memory; the memory is used
> > for the file system cache.
> > 
> > Do you experience any problems, like reduced performance or high I/O?
> > 
> Performance issue.
> 
> Can I restrict memory usage at session level in the script where I run
> Vacuum DB ?  

Could you please bottom-post?

Once vacuumdb is done, the associated backend process is gone too, so
it cannot consume any memory.

Try to figure out which process consumes your memory.

What do you get for free -h?

How did you configure shared_buffers and maintenance_work_mem?

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


Re: vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:
> On Apr 27, 2018, at 8:39 AM, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
>
> Sushil Shirodkar wrote:
>>>>>> On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
>>>>>> Running "vacuumdb -a -z -v" from the cron on one of our test environment, and
>>>>>> noticed that memory of the server goes down from 3.4GB free to 150MB.  Once
>>>>>> the process is over, memory is not released, is it normal or something needs to be
>>>>>> changed ? also other processes start running slow afterwards due to low memory.
>>>>>
>>>>> How are you measuring free memory? Memory might be listed in cached/buffers instead of
>>>>> free but is still available. Although that wouldn't then explain other processes being slow.
>>>>
>>>> I have put some small script which runs in a loop with "free -h" command,
>>>> while I am running "vacuumdb".  Once I clear by "sync" or bounce PG,
>>>> everything runs normal afterward.
>>>
>>> Then I would say everything is fine.
>>> It is normal for a Linux system to have almost no free memory; the memory is used
>>> for the file system cache.
>>>
>>> Do you experience any problems, like reduced performance or high I/O?
>>>
>> Performance issue.
>>
>> Can I restrict memory usage at session level in the script where I run
>> Vacuum DB ?
>
> Could you please bottom-post?
>
> Once vacuumdb is done, the associated backend process is gone too, so
> it cannot consume any memory.
>
> Try to figure out which process consumes your memory.
>
> What do you get for free -h?
>
> How did you configure shared_buffers and maintenance_work_mem?
>
> Yours,
> Laurenz Albe
> --
> Cybertec | https://www.cybertec-postgresql.com

Sorry for the delayed response.

Process which was running close to 99% memory was
 "/usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c
config_file=/etc/postgresql/9.5/main/postgresql.conf"

free -h - was showing between 100-150 mb free.

shared_buffers = 1GB
maintenance_work_mem = 256MB



Re: vacuumdb causes memory drain.

От
Laurenz Albe
Дата:
Sushil Shirodkar wrote:
> > > > > > > On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
> > > > > > > Running "vacuumdb -a -z -v" from the cron on one of our test environment, and 
> > > > > > > noticed that memory of the server goes down from 3.4GB free to 150MB.  Once 
> > > > > > > the process is over, memory is not released, is it normal or something needs to be 
> > > > > > > changed ? also other processes start running slow afterwards due to low memory.  
>
> Process which was running close to 99% memory was
>  "/usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c
config_file=/etc/postgresql/9.5/main/postgresql.conf"
> 
> free -h - was showing between 100-150 mb free. 
> 
> shared_buffers = 1GB
> maintenance_work_mem = 256MB

Can you share the "free -h" output?

What do you get for
ps -p <postmaster PID> -o rss,trs,drs,vsz,%mem
if you substitute the postmaster's process ID?

If you say that "sync" restored normal behavior, are you implying that there
was a high I/O load?

Still trying to figure out what exactly you are experiencing.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


Re: vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:





From: Laurenz Albe <laurenz.albe@cybertec.at>
Sent: Monday, April 30, 2018 1:43 AM
To: Sushil Shirodkar
Cc: don@seiler.us; pgsql-admin@postgresql.org
Subject: Re: vacuumdb causes memory drain.
 
Sushil Shirodkar wrote:
> > > > > > > On Thu, Apr 26, 2018 at 10:31 AM, Sushil Shirodkar <sushilps@hotmail.com> wrote:
> > > > > > > Running "vacuumdb -a -z -v" from the cron on one of our test environment, and
> > > > > > > noticed that memory of the server goes down from 3.4GB free to 150MB.  Once
> > > > > > > the process is over, memory is not released, is it normal or something needs to be
> > > > > > > changed ? also other processes start running slow afterwards due to low memory. 
>
> Process which was running close to 99% memory was
>  "/usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.conf"
>
> free -h - was showing between 100-150 mb free.
>
> shared_buffers = 1GB
> maintenance_work_mem = 256MB

Can you share the "free -h" output?

What do you get for
ps -p <postmaster PID> -o rss,trs,drs,vsz,%mem
if you substitute the postmaster's process ID?

If you say that "sync" restored normal behavior, are you implying that there
was a high I/O load?

Still trying to figure out what exactly you are experiencing.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com
Hi Laurenz,

After reboot of Linux server this morning, we couldn't reproduce the issue.  Not sure if this will come up 
again, and if it is good news or not,  will monitor and update forum if it reoccurs.  

Pl. see the output below which I had captured earlier from  "free -h" before and after
running of  "vacuumdb".

              total                 used         free          shared     buff/cache   available
Mem:           3.7G        158M        3.2G         62M        385M             3.3G
Swap:          3.9G          0B             3.9G

                     total        used           free           shared      buff/cache   available
Mem:           3.7G        169M        138M        117M        3.4G              3.2G
Swap:           3.9G          0B            3.9G


Was running the following command when slowness was observed.  The only issue I would see is memory
getting close to full,  after running the following  our application performance would get back to normal.  

sync;  echo 1 > /proc/sys/vm/drop_caches

Let us know if we should run any other commands to capture the output,  if it reoccurs. 

Thanks to you and Don for your input and help on this issue. 


Rgs, 
Sushil Shirodkar...




Re: vacuumdb causes memory drain.

От
Laurenz Albe
Дата:
Sushil Shirodkar wrote:
> After reboot of Linux server this morning, we couldn't reproduce the issue.  Not sure if this will come up 
> again, and if it is good news or not,  will monitor and update forum if it reoccurs.  
> 
> Pl. see the output below which I had captured earlier from  "free -h" before and after
> running of  "vacuumdb".
> 
>               total                 used         free          shared     buff/cache   available
> Mem:           3.7G        158M        3.2G         62M        385M             3.3G
> Swap:          3.9G          0B             3.9G
> 
>                      total        used           free           shared      buff/cache   available
> Mem:           3.7G        169M        138M        117M        3.4G              3.2G
> Swap:           3.9G          0B            3.9G
> 
> 
> Was running the following command when slowness was observed.  The only issue I would see is memory
> getting close to full

That is totally normal.

You can observe that in the second output all the memory is shown as "buff/cache",
that is, it is used for the file system cache rather than remaining unused.
This memory is available, there is no shortage.

This is the normal state for a Linux system with buffered I/O activity.

> after running the following  our application performance would get back to normal.
> 
> sync;  echo 1 > /proc/sys/vm/drop_caches

Now that is surprising.

Sure, after running this command  your memory will show up as "free" again,
but I'd expect performance to get worse because no more files are cached.

Next time you run into trouble, try the following commands:

vmstat 1
iostat -mNx 1

These should show you how your overall CPU, memory and I/O situation is.
Maybe you can find your performance bottleneck that way.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com


Re: vacuumdb causes memory drain.

От
Tim Cross
Дата:


On 1 May 2018 at 13:05, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
Sushil Shirodkar wrote:
> After reboot of Linux server this morning, we couldn't reproduce the issue.  Not sure if this will come up
> again, and if it is good news or not,  will monitor and update forum if it reoccurs. 
>
> Pl. see the output below which I had captured earlier from  "free -h" before and after
> running of  "vacuumdb".
>
>               total                 used         free          shared     buff/cache   available
> Mem:           3.7G        158M        3.2G         62M        385M             3.3G
> Swap:          3.9G          0B             3.9G
>
>                      total        used           free           shared      buff/cache   available
> Mem:           3.7G        169M        138M        117M        3.4G              3.2G
> Swap:           3.9G          0B            3.9G
>
>
> Was running the following command when slowness was observed.  The only issue I would see is memory
> getting close to full

That is totally normal.

You can observe that in the second output all the memory is shown as "buff/cache",
that is, it is used for the file system cache rather than remaining unused.
This memory is available, there is no shortage.

This is the normal state for a Linux system with buffered I/O activity.

> after running the following  our application performance would get back to normal.
>
> sync;  echo 1 > /proc/sys/vm/drop_caches

Now that is surprising.

Sure, after running this command  your memory will show up as "free" again,
but I'd expect performance to get worse because no more files are cached.

Next time you run into trouble, try the following commands:

vmstat 1
iostat -mNx 1

These should show you how your overall CPU, memory and I/O situation is.
Maybe you can find your performance bottleneck that way.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com


as another indicator that your not low on memory look at the 'swap' line. The kernel has not swapped anything out of main memory, so while the 'free' value might look low, there has been no demand for memory which exceeds what you have available. 

I too find the fact clearing out caches seems to improve performance - that seems counter to what I'd expect too.  What filesystem type is the server using for PG?

--
regards,

Tim

--
Tim Cross

Re: vacuumdb causes memory drain.

От
Sushil Shirodkar
Дата:





From: Tim Cross <theophilusx@gmail.com>
Sent: Monday, April 30, 2018 11:59 PM
To: Laurenz Albe
Cc: Sushil Shirodkar; don@seiler.us; pgsql-admin@postgresql.org
Subject: Re: vacuumdb causes memory drain.
 


On 1 May 2018 at 13:05, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
Sushil Shirodkar wrote:
> After reboot of Linux server this morning, we couldn't reproduce the issue.  Not sure if this will come up
> again, and if it is good news or not,  will monitor and update forum if it reoccurs. 
>
> Pl. see the output below which I had captured earlier from  "free -h" before and after
> running of  "vacuumdb".
>
>               total                 used         free          shared     buff/cache   available
> Mem:           3.7G        158M        3.2G         62M        385M             3.3G
> Swap:          3.9G          0B             3.9G
>
>                      total        used           free           shared      buff/cache   available
> Mem:           3.7G        169M        138M        117M        3.4G              3.2G
> Swap:           3.9G          0B            3.9G
>
>
> Was running the following command when slowness was observed.  The only issue I would see is memory
> getting close to full

That is totally normal.

You can observe that in the second output all the memory is shown as "buff/cache",
that is, it is used for the file system cache rather than remaining unused.
This memory is available, there is no shortage.

This is the normal state for a Linux system with buffered I/O activity.

> after running the following  our application performance would get back to normal.
>
> sync;  echo 1 > /proc/sys/vm/drop_caches

Now that is surprising.

Sure, after running this command  your memory will show up as "free" again,
but I'd expect performance to get worse because no more files are cached.

Next time you run into trouble, try the following commands:

vmstat 1
iostat -mNx 1

These should show you how your overall CPU, memory and I/O situation is.
Maybe you can find your performance bottleneck that way.

Yours,
Laurenz Albe
--
Cybertec | https://www.cybertec-postgresql.com


as another indicator that your not low on memory look at the 'swap' line. The kernel has not swapped anything out of main memory, so while the 'free' value might look low, there has been no demand for memory which exceeds what you have available. 

I too find the fact clearing out caches seems to improve performance - that seems counter to what I'd expect too.  What filesystem type is the server using for PG?

--
regards,

Tim

--
Tim Cross



Laurenz -  So far no issue seen after reboot,  will capture the outputs you recommended if this reoccurs. 

Tim - We are using ext4 filesystem on this server. 
 

Thanks both for your help. 


Rgs,
Sushil...




Thanks both for your help.