Projekt

Allgemein

Profil

710 Datenbankeinstellungen und Tuning (postgresql conf) » Historie » Version 86

[E] Rocco Kreutz, 16.12.2025 12:19

1 74 [S] Dominik G
h1. Datenbankeinstellungen und Tuning (postgresql.conf)
2 1 [X] Daniel S
3 26 [S] Philipp K
4 23 [E] Oleg G
@postgresql.conf@ ([[PostgreSQL Netzwerkkonfiguration (pg_hba.conf)]])
5 1 [X] Daniel S
6 56 [S] Dominik G
Datei-Pfad: *..\PostgreSQL\9.6\data\pg96\postgresql.conf*
7 25 [E] Oleg G
8 58 [S] Philipp K
h2. Prüfen der wichtigsten Postgreseinstellungen mittels Datenbankfunktion
9
10 65 [E] Frank S
Die Funktionen heißen @TSystem.database_settings__initialize()@ und @TSystem.database_settings__validate()@ und muss bei Neuerungen entsprechend angepasst oder erweitert werden.
11 54 [S] Philipp K
12 1 [X] Daniel S
h2. Konfiguration PostgreSQL (Beachte Betriebssystem) ab Version 9.3 
13 54 [S] Philipp K
14 51 [X] Daniel S
Beachte Programm-Start-Prüfung PRODAT: #9933
15 60 [S] Philipp K
Für ein 16GB RAM System
16 1 [X] Daniel S
17 69 [X] Richard H
|_.° |_. param                |_. value    |_. Bemerkung |
18 85 [X] Jens M
|   | shared_buffers (2023) | 4GB     | Daumenregel: ca 1/4 des RAMs den Rest für effective_cache_size. Große Datenbanken mehr! https://distributedsystemsauthority.com/optimizing-postgresql-shared-buffers/ *wird ab 2023 geprüft in startroutine siehe code @database_settings__validate@*
19
%{color:red}ACHTUNG: nur positive ganzzahlige GB angeben!!% |
20 69 [X] Richard H
|   | temp_buffers           | 8MB        ||
21 80 [X] Daniel S
|   | work_mem (2023) | 128MB| nicht zu hoch, da je sort bzw. hash Operation, auch mehrfach bei komplexen queries » https://www.citusdata.com/blog/2018/06/12/configuring-work-mem-on-postgres/ 
22
https://www.pgmustard.com/blog/work-mem 
23
@alepaes My understanding is that the memory is only allocated as it's used rather than in a big up-front allocation. *So effectively the work_mem value is the maximum, while the minimum is always zero.*
24
Bruce Momjian: That is correct.|
25 69 [X] Richard H
|   | maintenance_work_mem       | 512MB | für VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY, außerdem für restore dumps |
26
|   | dynamic_shared_memory_type | windows ||
27
|   | max_worker_processes | 8 | Default ist 8 (keine Änderung nötig). Je nach Unternehmensgröße mehr |
28
| ° | max_parallel_workers_per_gather | 4 ||
29 1 [X] Daniel S
|   | fsync| on ||
30
|   | synchronous_commit| off ||
31
| ° | max_locks_per_transaction | 1024 | https://redmine.prodat-sql.de/issues/12311 |
32
|   | effective_cache_size | 12288MB | Beachte, wenn Server nur für PRODAT dann 3/4 des Arbeitsspeichers, wenn auch andere Programme dort laufen dann 1/2 Arbeitsspeicher. Gibt an wieviel RAM-Cache Postgressql erwarten kann, für Indizies usw |
33 69 [X] Richard H
|   | default_statistics_target | 1000 ||
34 79 [X] Daniel S
| ° | seq_page_cost (2023) | 2.0 | Mache sequentielle Scans "teurer": Der Planer ist eher geneigt, den Index zu nutzen |
35
| ° | random_page_cost (2023) | 4.0 | ssds vs hdds |
36
| ° | cursor_tuple_fraction (2023) | 0.75 | (siehe #6436) (Steuert, dass das CURSOR-FETCH (F2-Fenster) anders errechnet wird und es Blöcke früher zurückgibt) |
37 69 [X] Richard H
|   | log_destination | 'eventlog' | (unter Windows) |
38 1 [X] Daniel S
|   | log_checkpoints | off | auf Default setzen |
39 77 [X] Daniel S
|   | checkpoint_timeout |30min | https://www.2ndquadrant.com/en/blog/basics-of-tuning-checkpoints/ |
40 79 [X] Daniel S
|   | max_wal_size (2023) | 10GB | https://www.2ndquadrant.com/en/blog/basics-of-tuning-checkpoints/ https://www.2ndquadrant.com/en/blog/tpc-h-performance-since-postgresql-8-3/ |
41 1 [X] Daniel S
|   | log_line_prefix | '<%u@@@%d-%t> ' ||
42 79 [X] Daniel S
|   | vacuum_cost_limit (2023) | 1500 | https://www.2ndquadrant.com/en/blog/autovacuum-tuning-basics/ |
43 73 [X] Richard H
| ° | log_autovacuum_min_duration | 3s | # default -1@ (auf Default setzen) > alles was länger 3s dauert loggen und bei Gelegnheit prüfen|
44 69 [X] Richard H
|   | search_path | '"$user",public,TSystem,prodat_languages,Z_99_Deprecated' ||
45
|   | datestyle | 'iso, dmy' ||
46
|   | standard_conforming_strings | off | siehe #4860 |
47
|   | lc_messages | 'en_US.UTF-8' | (Das muß sein, da wir die Fehlermeldungen teilweise parsen und somit auf die Fehler-Strings gehen.) |
48
|   | lc_monetary | 'German_Germany.1252' | (Lokale je nach Land) |
49
|   | lc_numeric | 'German_Germany.1252' | |
50
|   | lc_time | 'German_Germany.1252' | |
51 86 [E] Rocco Kreutz
|   | | | |
52
|   | ssl | on | |
53
|   | ssl_cert_file | 'ssl/pgserver.chain' | |
54
|   | ssl_key_file | 'ssl/pgserver.chain' | |
55
|   | ssl_min_protocol_version | 'TLSv1.2' | |
56
|   | ssl_max_protocol_version | 'TLSv1.2' | |
57
|   | ssl_ciphers | 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:!aNULL:!eNULL:!MD5:!RC4:!3DES' | |
58
|   | ssl_prefer_server_ciphers | on | |
59
|   | | | |
60
61 56 [S] Dominik G
62
{{collapse(Alte Versionen:)
63 1 [X] Daniel S
@checkpoint_segments = 64 # in 9.6 nicht supported@
64 66 [E] Frank S
° @statement_timeout = 120000@ Bis Prodat 11.5.3@ wird clientseitig im Prodat gesetzt (480000 und für AppServer/Admins 1200000)
65 49 [S] Philipp K
}}
66 66 [E] Frank S
67 67 [E] Frank S
!!! ° = *Für einige Werte gibt es Vorgaben und Prüfungen, in den Client-Sessions.*
68 66 [E] Frank S
!!! siehe @TSystem.database_settings__initialize@ und @TSystem.database_settings__validate@ (PSQL\0050 System\010 Functions TSystem.sql)
69 1 [X] Daniel S
70 57 [S] Dominik G
h2. Reload
71
72 83 [X] Jens M
* Konfiguration im laufenden Betrieb neu laden.
73 84 [X] Jens M
** @SELECT pg_reload_conf()@
74
** @..\PostgreSQL\pg96\bin\pg_ctl reload -D ..\PostgreSQL\data\pg96@
75
** @..\PostgreSQL\13\bin\pg_ctl reload -D ..\PostgreSQL\13\data@
76 34 [X] Daniel S
77
h2. Linux 
78
79
{{collapse(Linux)
80
81
h3. Betriebssystem - Speichereinstellungen mind. 3GiB Arbeitsspeicher!
82
83
* standard:
84
sysctl kernel.shmmax
85
kernel.shmmax = 33554432
86
87
* umsetzen auf 280437720 (256MB, Mindestens, LOLL steht auf 1024MB (8GB Ram)) (On Windows the useful range is 64MB to 512MB)
88
/etc/sysctl.conf  -> zeile aufnehmen: kernel.shmmax=280437720
89
reboot
90
91
h3. Nur auf Systemen mit 3GiB+ RAM anzuwenden
92
93
@$ free -m@
94
<pre>
95
             total       used       free     shared    buffers     cached
96
Mem:          3018       1516       1501          0        208       1113
97
-/+ buffers/cache:        194       2823
98
Swap:         1023          0       1023
99
</pre>
100
101
102
h3. Weiteres
103
104
Unter Linux ist noch die shmmax-Option aus der 99-postgresql.conf via sysctl zu setzen, sonst klappert das da.
105
http://www.postgresql.org/docs/8.2/static/kernel-resources.html
106
107
}}
108 1 [X] Daniel S
109 19 [S] Dominik G
110 14 [S] Dominik G
Könnte durchaus noch weiter getrieben werden, indem man Sie auf die Prodat-DB abstimmt:
111 13 [S] Dominik G
* http://wiki.postgresql.org/wiki/Tuning_Your_PostgreSQL_Server
112 11 [X] Daniel S
* http://www.postgresql.org/docs/current/static/performance-tips.html
113 13 [S] Dominik G
* "five_steps_perform_2009.pdf":http://www.prodat-sql.de/redmine/attachments/download/2528/five_steps_perform_2009.pdf Dokument über Einstellungen etc
114
115 19 [S] Dominik G
116
*Hinweis:* Fehler im PgAdmin/Server-Status: ungültige Byte-Sequenz für Kodierung "UTF8" ... durch SELECT pg_file_read('pg_log/... kann ignoriert werden, da wir ja ins eventlog schreiben.
117
Die Anzeige vom Log hier einfach schließen. Liegt an LC_MESSAGES und mehrsprachigen Systemen, vermutlich ein Bug, Workaround LC_MESSAGES='C' (evtl. nicht mit Prodat kompatibel)
118 11 [X] Daniel S
119 12 [X] Daniel S
120 13 [S] Dominik G
h2. Virtualisierung
121 12 [X] Daniel S
122 13 [S] Dominik G
"Database_Virtualization_PG_China.pdf":http://www.prodat-sql.de/redmine/attachments/download/2568/Database_Virtualization_PG_China.pdf