PG-Memory parameter configuration standard

Reference: https://blog.csdn.net/kmblack1/article/details/81002316

 

The default value of wal_buffers is -1. At this time, wal_buffers is allocated from shared_buffers. The size of wal_buffers is 1/32 of shared_buffers. The
default value of autovacuum_work_mem is -1, and the value of maintenance_work_mem is used.
The physical memory of the PG server is 32G.

 

1 Do not use wal_buffers, autovacuum_work_mem

The calculation formula for PG to occupy memory is:
max_connections*work_mem + max_connections*temp_buffers +shared_buffers+(autovacuum_max_workers * maintenance_work_mem)

Assume that the configuration of PostgreSQL is as follows:

max_connections = 100
temp_buffers=32MB
work_mem=32MB
shared_buffers=19GB
autovacuum_max_workers = 3 
maintenance_work_mem = 1GB #default value 64MB

Memory usage calculation

select(
    (100*(32*1024*1024)::bigint)
    + (100*(32*1024*1024)::bigint)
    + (19*(1024*1024*1024)::bigint)
    + (3 * (1024*1024*1024)::bigint )
)::float8 / 1024 / 1024 / 1024;

- Output 
28.25

- # At this time, the maximum load of pg is 28.25GB memory, and 3.75GB memory is used by the operating system

 

2 Use wal_buffers, not autovacuum_work_mem

The calculation formula for PG to occupy memory is:
max_connections*work_mem + max_connections*temp_buffers +shared_buffers+wal_buffers+(autovacuum_max_workers * autovacuum_work_mem)

Assume that the configuration of PostgreSQL is as follows:

max_connections = 100
temp_buffers=32MB
work_mem=32MB
shared_buffers=19GB    
wal_buffers = 16MB # -with - wal- segsize default value
autovacuum_max_workers = 3    
maintenance_work_mem=1GB

Memory usage calculation

select(
    (100*(32*1024*1024)::bigint)
    + (100*(32*1024*1024)::bigint)
    + (19*(1024*1024*1024)::bigint)
    + (16*1024*1024)::bigint
    + (3 * (1024*1024*1024)::bigint )
)::float8  / 1024 / 1024 / 1024;

- Output 
28.26

- # At this time, the maximum load of pg is 28.5GB of memory, and 3.5GB of memory is used by the operating system

 

3 Use wal_buffers and autovacuum_work_mem at the same time [ recommended ]

The calculation formula for PG to occupy memory is:
max_connections*work_mem + max_connections*temp_buffers +shared_buffers+wal_buffers+(autovacuum_max_workers * autovacuum_work_mem)+ maintenance_work_mem

Assume that the configuration of PostgreSQL is as follows:

max_connections = 100
temp_buffers=32MB
work_mem=32MB
shared_buffers=19GB    
wal_buffers=262143kb
autovacuum_max_workers = 3
autovacuum_work_mem=256MB
maintenance_work_mem=2GB

Memory usage calculation

select(
    (100*(32*1024*1024)::bigint)
    + (100*(32*1024*1024)::bigint)
    + (19*(1024*1024*1024)::bigint)
    + (262143*1024)::bigint
    + (3 * (256*1024*1024)::bigint )
    + ( 2 * (1024*1024*1024)::bigint )
) :: float8   /  1024  /  1024  /  1024 ;
 - Output 
28.01

- # At this time, the maximum load of pg is 28.25GB of memory, and 3.75GB of memory is used by the operating system. It is recommended that all memory consumption be based on the hardware configuration, that is, use this configuration

 

Guess you like

Origin www.cnblogs.com/binliubiao/p/12684705.html