Skip to content

Commit c8e251f

Browse files
authored
Merge pull request #2317 from jsrz/postgresql_tune_updated
PostgreSQL Tune: Updated page cache guidance
2 parents 668116b + 3d965da commit c8e251f

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

content/learning-paths/servers-and-cloud-computing/postgresql_tune/kernel_comp_lib.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ layout: "learningpathall"
1212

1313
The underlying storage technology and the file system format can impact performance significantly. In general, locally attached SSD storage will perform best. However, network based storage systems can perform well. As always, performance is dependent on the request profile coming from clients. You should spend some time studying and experimenting with different storage technologies and configuration options.
1414

15-
Aside from the storage technology, it is also worth testing different file system formats with `PostgreSQL`. The `xfs` file system is a good starting point. The `ext4` file system is another good alternative.
15+
Aside from the storage technology, it is also worth testing different file system formats with `PostgreSQL`. The `xfs` file system is a good starting point. The `ext4` file system is another good alternative.
1616

1717
## Kernel configuration
1818

1919
`PostgreSQL` can benefit from adjustments to kernel parameters. Below is a list of kernel related settings that can have a positive impact on performance.
2020

2121
### Linux-PAM limits
2222

23-
Linux-PAM limits can be changed in the `/etc/security/limits.conf` file, or by using the `ulimit` command.
23+
Linux-PAM limits can be changed in the `/etc/security/limits.conf` file, or by using the `ulimit` command.
2424

2525
If you want more information about how to display and modify parameters check the documentation of the `ulimit` command.
2626

@@ -41,9 +41,9 @@ Some of the key settings that can affect performance are:
4141

4242
### Linux virtual memory subsystem
4343

44-
Making changes to the Linux Virtual Memory subsystem can also improve performance.
44+
Making changes to the Linux Virtual Memory subsystem can also improve performance.
4545

46-
These settings can be changed in the `/etc/sysctl.conf` file, or by using the `sysctl` command.
46+
These settings can be changed in the `/etc/sysctl.conf` file, or by using the `sysctl` command.
4747

4848
If you want more information about how to display and modify virtual memory parameters check the documentation of the `sysctl` command.
4949

@@ -57,9 +57,9 @@ sudo sysctl -a
5757

5858
### Overcommit memory
5959

60-
The overcommit policy is set via the sysctl `vm.overcommit_memory' setting.
60+
The overcommit policy is set via the sysctl `vm.overcommit_memory' setting.
6161

62-
The recommended setting for `vm.overcommit_memory` is 2 according to the [PostgreSQL documentation](https://www.postgresql.org/docs/15/kernel-resources.html).
62+
The recommended setting for `vm.overcommit_memory` is 2 according to the [PostgreSQL documentation](https://www.postgresql.org/docs/15/kernel-resources.html).
6363

6464
To set the overcommit_memory parameter to 2 temporarily, run the following command:
6565

@@ -75,7 +75,7 @@ This tells Linux to never over commit memory. Setting `vm.overcommit_memory` to
7575

7676
### Huge memory pages
7777

78-
`PostgreSQL` benefits from using huge memory pages. Huge pages reduce how often virtual memory pages are mapped to physical memory.
78+
`PostgreSQL` benefits from using huge memory pages. Huge pages reduce how often virtual memory pages are mapped to physical memory.
7979

8080
To see the current memory page configuration, run the following command on the host:
8181

@@ -94,9 +94,9 @@ Hugepagesize: 2048 kB
9494
Hugetlb: 0 kB
9595
```
9696

97-
Huge pages are not being used if `HugePages_Total` is 0 (this is the default).
97+
Huge pages are not being used if `HugePages_Total` is 0 (this is the default).
9898

99-
Also note that `Hugepagesize` is 2MB which is the typical default for huge pages on Linux.
99+
Also note that `Hugepagesize` is 2MB which is the typical default for huge pages on Linux.
100100

101101
You can modify the huge page values.
102102

@@ -106,9 +106,9 @@ The setting that enables huge pages is shown below:
106106
vm.nr_hugepages
107107
```
108108

109-
This parameter sets the number of huge pages you want the kernel to make available to applications.
109+
This parameter sets the number of huge pages you want the kernel to make available to applications.
110110

111-
The total amount of memory that will be used for huge pages will be this number (defaulted to 0) times the `Hugepagesize`.
111+
The total amount of memory that will be used for huge pages will be this number (defaulted to 0) times the `Hugepagesize`.
112112

113113
As an example, if you want a total of 1GB of huge page space, then you should set `vm.nr_hugepages` to 500 (500x2MB=1GB).
114114

@@ -124,7 +124,7 @@ sudo sh -c 'echo "vm.nr_hugepages=500" >> /etc/sysctl.conf'
124124

125125
### Selecting the number of huge pages to use
126126

127-
You should set `vm.nr_hugepages` to a value that gives a total huge page space slightly bigger than the `PostgreSQL` shared buffer size (discussed later).
127+
You should set `vm.nr_hugepages` to a value that gives a total huge page space slightly bigger than the `PostgreSQL` shared buffer size (discussed later).
128128

129129
Make it slightly larger than the shared buffer because `PostgreSQL` will use additional memory for things like connection management.
130130

@@ -135,19 +135,15 @@ More information on the different parameters that affect the configuration of hu
135135
`PostgreSQL` writes data to files like any Linux process does. The behavior of the page cache can affect performance. There are two sysctl that parameters control how often the kernel flushes the page cache data to disk.
136136

137137
- `vm.dirty_background_ratio=5`
138-
- `vm.dirty_ratio=80`
138+
- `vm.dirty_ratio=20`
139139

140-
The `vm.dirty_background_ratio` sets the percentage of the page cache that needs to be dirty in order for a flush to disk to start in the background.
140+
The `vm.dirty_background_ratio` sets the percentage of the page cache that needs to be dirty in order for a flush to disk to start in the background.
141141

142-
Setting this value to lower than the default (typically 10) helps write heavy workloads. This is because by lowering this threshold, you are spreading writes to storage over time. This reduces the probability of saturating storage.
142+
Setting this value to lower than the default (typically 10) helps write heavy workloads. This is because by lowering this threshold, you are spreading writes to storage over time. This reduces the probability of saturating storage performance. Setting this value to 5 can improve performance.
143143

144-
Setting this value to 5 can improve performance.
144+
The `vm.dirty_ratio` sets the percentage of the page cache that needs to be dirty in order for threads that are writing to storage to be paused to allow flushing to catch up.
145145

146-
The `vm.dirty_ratio` sets the percentage of the page cache that needs to be dirty in order for threads that are writing to storage to be paused to allow flushing to catch up.
147-
148-
Setting this value higher than default (typically 10-20) helps performance when disk writes are bursty. A higher value gives the background flusher (controlled by `vm.dirty_background_ratio`) more time to catch up.
149-
150-
Setting this as high as 80 can improve performance.
146+
This should be set higher than `vm.dirty_background_ratio`. The OS default is typically around 20 which is usually good. In some cases it may be beneficial to set this value to be higher, it gives the background flusher (controlled by `vm.dirty_background_ratio`) more time to catch up if disk writes are very bursty. In general, you can leave this to the OS default, but it may be worth experimenting with higher values on specific workload profiles.
151147

152148
## Compiler Considerations
153149

0 commit comments

Comments
 (0)