You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/postgresql_tune/kernel_comp_lib.md
+17-21Lines changed: 17 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,15 +12,15 @@ layout: "learningpathall"
12
12
13
13
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.
14
14
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.
16
16
17
17
## Kernel configuration
18
18
19
19
`PostgreSQL` can benefit from adjustments to kernel parameters. Below is a list of kernel related settings that can have a positive impact on performance.
20
20
21
21
### Linux-PAM limits
22
22
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.
24
24
25
25
If you want more information about how to display and modify parameters check the documentation of the `ulimit` command.
26
26
@@ -41,9 +41,9 @@ Some of the key settings that can affect performance are:
41
41
42
42
### Linux virtual memory subsystem
43
43
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.
45
45
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.
47
47
48
48
If you want more information about how to display and modify virtual memory parameters check the documentation of the `sysctl` command.
49
49
@@ -57,9 +57,9 @@ sudo sysctl -a
57
57
58
58
### Overcommit memory
59
59
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.
61
61
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).
63
63
64
64
To set the overcommit_memory parameter to 2 temporarily, run the following command:
65
65
@@ -75,7 +75,7 @@ This tells Linux to never over commit memory. Setting `vm.overcommit_memory` to
75
75
76
76
### Huge memory pages
77
77
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.
79
79
80
80
To see the current memory page configuration, run the following command on the host:
81
81
@@ -94,9 +94,9 @@ Hugepagesize: 2048 kB
94
94
Hugetlb: 0 kB
95
95
```
96
96
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).
98
98
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.
100
100
101
101
You can modify the huge page values.
102
102
@@ -106,9 +106,9 @@ The setting that enables huge pages is shown below:
106
106
vm.nr_hugepages
107
107
```
108
108
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.
110
110
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`.
112
112
113
113
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).
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).
128
128
129
129
Make it slightly larger than the shared buffer because `PostgreSQL` will use additional memory for things like connection management.
130
130
@@ -135,19 +135,15 @@ More information on the different parameters that affect the configuration of hu
135
135
`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.
136
136
137
137
-`vm.dirty_background_ratio=5`
138
-
-`vm.dirty_ratio=80`
138
+
-`vm.dirty_ratio=20`
139
139
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.
141
141
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.
143
143
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.
145
145
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.
0 commit comments