How PostgreSQL calculates the size of server configuration parameters

Insert picture description here

Article Directory

Hi everyone, I’m Mr. Tony who only talks about techniques and not cutting hair.

The default configuration parameters of PostgreSQL are usually small and not suitable for production environments. Therefore, we need to modify the configuration parameters of the server after installing the database. The previous article introduced how to set the configuration parameters of the server. Today, I will introduce a method to quickly calculate the size of the main parameters of PostgreSQL.

We can use the PGTune online tool to calculate the recommended configuration of PostgreSQL based on the maximum performance of a given hardware configuration. Its setting interface is as follows:

Homepage
The use of this tool is very simple, the parameters we can enter include:

  • The version of the PostgreSQL database can be viewed through SELECT version();commands.
  • The operating system of the database server host, including Linux, Windows, and OS X.
  • The types of database applications include: Web Application, Online Transaction Processing, Data Warehouse, Desktop application, and Mixed type of application. The right side of the configuration page gives an introduction to different application types.
  • The memory size of the server.
  • The number of CPU cores of the server, an optional parameter.
  • The maximum number of database connections, optional parameters.
  • Types of data storage devices, including SSD, SAN, and mechanical hard disk (HDD).

After entering the required parameters, click the "Generate" button.

setting
PGTune generates recommended configuration parameters on the right side of the page, and provides methods to modify the configuration file postgresql.conf and use the ALTER SYSTEM command to set parameters. For example, the content of the configuration file generated by the hardware parameters we input is as follows:

# WARNING
# this tool not being optimal
# for very high memory systems

# DB Version: 13
# OS Type: linux
# DB Type: oltp
# Total Memory (RAM): 128 GB
# CPUs num: 63
# Connections num: 500
# Data Storage: san

max_connections = 500
shared_buffers = 32GB
effective_cache_size = 96GB
maintenance_work_mem = 2GB
checkpoint_completion_target = 0.9
wal_buffers = 16MB
default_statistics_target = 100
random_page_cost = 1.1
effective_io_concurrency = 300
work_mem = 16777kB
min_wal_size = 2GB
max_wal_size = 8GB
max_worker_processes = 63
max_parallel_workers_per_gather = 4
max_parallel_workers = 63
max_parallel_maintenance_workers = 4

Or, the generated ALTER SYSTEM command is as follows:

# WARNING
# this tool not being optimal
# for very high memory systems

# DB Version: 13
# OS Type: linux
# DB Type: oltp
# Total Memory (RAM): 128 GB
# CPUs num: 63
# Connections num: 500
# Data Storage: san

ALTER SYSTEM SET
 max_connections = '500';
ALTER SYSTEM SET
 shared_buffers = '32GB';
ALTER SYSTEM SET
 effective_cache_size = '96GB';
ALTER SYSTEM SET
 maintenance_work_mem = '2GB';
ALTER SYSTEM SET
 checkpoint_completion_target = '0.9';
ALTER SYSTEM SET
 wal_buffers = '16MB';
ALTER SYSTEM SET
 default_statistics_target = '100';
ALTER SYSTEM SET
 random_page_cost = '1.1';
ALTER SYSTEM SET
 effective_io_concurrency = '300';
ALTER SYSTEM SET
 work_mem = '16777kB';
ALTER SYSTEM SET
 min_wal_size = '2GB';
ALTER SYSTEM SET
 max_wal_size = '8GB';
ALTER SYSTEM SET
 max_worker_processes = '63';
ALTER SYSTEM SET
 max_parallel_workers_per_gather = '4';
ALTER SYSTEM SET
 max_parallel_workers = '63';
ALTER SYSTEM SET
 max_parallel_maintenance_workers = '4';

For the introduction and function of these parameters, you can refer to the official documents .

The optimization of the PostgreSQL database depends not only on the hardware configuration, but also on various factors such as the size of the database, the number of clients, and the complexity of the query, so the recommended value of PGTune is not necessarily the optimal setting. However, we can use it as an initial configuration, and then further optimize according to the actual situation.

PGTune is an open source project, hosted on GitHub , we can download and deploy a version of our own.

Guess you like

Origin blog.csdn.net/horses/article/details/114107936