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
You can find a version of this documentation that is searchable and also easier to navigate at `patroni.readthedocs.io <https://patroni.readthedocs.io>`__.
7
11
12
+
**Important!**
13
+
Running Patroni on **memory-restricted systems with Python 3.11+**
14
+
15
+
----
16
+
17
+
If you run Patroni on a system with strict memory limits, for example with ``vm.overcommit_memory=2`` (recommended for PostgreSQL), and use Python 3.11 or newer, you may observe unexpected behavior:
18
+
19
+
- Patroni appears healthy
20
+
- PostgreSQL continues to run
21
+
- Patroni **REST API becomes unresponsive**
22
+
- The operating system reports that Patroni is listening on the REST API port
23
+
- Patroni logs look normal; however, following messages may appear once: ``Exception ignored in thread started by: <object repr() failed>``, ``MemoryError``
24
+
- Kernel logs may contain messages such as ``not enough memory for the allocation``
25
+
26
+
This behavior is caused by a `bug in Python 3.11+ <https://github.com/python/cpython/issues/140746>`__.
27
+
Under strict memory conditions, starting a new thread may hang indefinitely when there is not enough free memory.
28
+
29
+
Recommended solution
30
+
--------------------
31
+
32
+
Recent Patroni releases (4.1.1+, 4.0.8+) reduce the impact of this issue by starting all required threads early during startup, before the system is under memory pressure.
33
+
34
+
Additional recommendations (Linux, glibc)
35
+
-----------------------------------------
36
+
37
+
When running with ``vm.overcommit_memory=2`` (recommended for PostgreSQL), we also recommend starting Patroni with the following environment variables configured:
38
+
39
+
- ``MALLOC_ARENA_MAX=1`` - reduces the amount of virtual memory allocated by glibc for multi-threaded
40
+
applications
41
+
- ``PG_MALLOC_ARENA_MAX=`` - resets the value of ``MALLOC_ARENA_MAX`` for PostgreSQL processes started by Patroni.
42
+
43
+
In addition, you may tune the following Patroni configuration parameters:
44
+
45
+
- ``thread_stack_size`` - stack size used for threads started by Patroni. Lowering this value reduces memory usage of the Patroni process. The default value set by Patroni is ``512kB``. Increase ``thread_stack_size`` if Patroni experience stack-related crashes; otherwise the default value is sufficient.
46
+
- ``thread_pool_size`` - size of the thread pool used by Patroni for asynchronous tasks and REST API communication with other members during leader race or failsafe checks. The default value is ``5``, which is sufficient for three-node clusters.
47
+
- ``restapi.thread_pool_size`` - size of the thread pool used to process REST API requests. The default value is ``5``, allowing up to five parallel REST API requests. Note that requests involving SQL queries are effectively serialized because a single database connection is used, so increasing this value typically provides no benefit.
48
+
49
+
----
50
+
51
+
PostgreSQL High Availability and Patroni
52
+
----------------------------------------
8
53
9
54
There are many ways to run high availability with PostgreSQL; for a list, see the `PostgreSQL Documentation <https://wiki.postgresql.org/wiki/Replication,_Clustering,_and_Connection_Pooling>`__.
10
55
@@ -173,5 +218,5 @@ When connecting from an application, always use a non-superuser. Patroni require
Copy file name to clipboardExpand all lines: docs/ENVIRONMENT.rst
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,12 @@ It is possible to override some of the configuration parameters defined in the P
8
8
Global/Universal
9
9
----------------
10
10
- **PATRONI\_CONFIGURATION**: it is possible to set the entire configuration for the Patroni via ``PATRONI_CONFIGURATION`` environment variable. In this case any other environment variables will not be considered!
11
+
- **PATRONI\_THREAD\_POOL\_SIZE**: size of thread pool used by Patroni to execute asynchronous tasks and communicate via REST API with other members during leader race or failsafe checks. Minimal value is ``5``, default value is ``5``.
12
+
- **PATRONI\_THREAD\_STACK\_SIZE**: specifies the stack size to be used for threads started by Patroni. Value must be aligned by ``64kB``. Minimal value is ``64kB``, default value (set by Patroni) is ``512kB``.
11
13
- **PATRONI\_NAME**: name of the node where the current instance of Patroni is running. Must be unique for the cluster.
12
14
- **PATRONI\_NAMESPACE**: path within the configuration store where Patroni will keep information about the cluster. Default value: "/service"
13
15
- **PATRONI\_SCOPE**: cluster name
16
+
- **PG\_MALLOC\_ARENA\_MAX**: custom value for ``MALLOC_ARENA_MAX`` environment variable for ``postmaster`` process. If not set, ``postmaster`` will inherit ``MALLOC_ARENA_MAX`` value.
14
17
15
18
Log
16
19
---
@@ -193,6 +196,7 @@ PostgreSQL
193
196
194
197
REST API
195
198
--------
199
+
- **PATRONI\_RESTAPI\_THREAD\_POOL\_SIZE**: size of thread pool used by Patroni to process REST API requests. Minimal value is ``5``, default value is ``5``.
196
200
- **PATRONI\_RESTAPI\_CONNECT\_ADDRESS**: IP address and port to access the REST API.
197
201
- **PATRONI\_RESTAPI\_LISTEN**: IP address and port that Patroni will listen to, to provide health-check information for HAProxy.
198
202
- **PATRONI\_RESTAPI\_USERNAME**: Basic-auth username to protect unsafe REST API endpoints.
Copy file name to clipboardExpand all lines: docs/existing_data.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,7 @@ You can find below an overview of steps for converting an existing Postgres clus
38
38
39
39
#. Create a YAML configuration file for Patroni. You can use :ref:`Patroni configuration generation and validation tooling <validate_generate_config>` for that.
40
40
41
-
* **Note (specific for the primary node):** If you have replication slots being used for replication between cluster members, then it is recommended that you enable ``use_slots`` and configure the existing replication slots as permanent via the ``slots`` configuration item. Be aware that Patroni automatically creates replication slots for replication between members, and drops replication slots that it does not recognize, when ``use_slots`` is enabled. The idea of using permanent slots here is to allow your existing slots to persist while the migration to Patroni is in progress. See :ref:`YAML Configuration Settings <yaml_configuration>` for details.
41
+
* **Note (specific for the primary node):** If you have replication slots being used for replication between cluster members, then it is recommended that you enable ``use_slots`` and configure the existing replication slots as permanent via the ``slots`` configuration item. Be aware that Patroni automatically creates replication slots for replication between members, and drops replication slots that it does not recognize, when ``use_slots`` is enabled. The idea of using permanent slots here is to allow your existing slots to persist while the migration to Patroni is in progress. See :ref:`Dynamic Configuration Settings <dynamic_configuration>` for details.
42
42
43
43
#. Start Patroni using the ``patroni`` systemd service unit. It automatically detects that Postgres is already running and starts monitoring the instance.
44
44
@@ -47,7 +47,7 @@ You can find below an overview of steps for converting an existing Postgres clus
47
47
#. Immediate restart of the standby nodes.
48
48
#. Scheduled restart of the primary node within a maintenance window.
49
49
50
-
#. If you configured permanent slots in step ``1.2.``, then you should remove them from ``slots`` configuration through :ref:`patronictl edit-config cluster-name member-name <patronictl_edit_config_parameters>` command once the ``restart_lsn`` of the slots created by Patroni is able to catch up with the ``restart_lsn`` of the original slots for the corresponding members. By removing the slots from ``slots`` configuration you will allow Patroni to drop the original slots from your cluster once they are not needed anymore. You can find below an example query to check the ``restart_lsn`` of a couple slots, so you can compare them:
50
+
#. If you configured permanent slots in step ``1.2.``, then you should remove them from ``slots`` configuration through :ref:`patronictl edit-config cluster-name <patronictl_edit_config_parameters>` command once the ``restart_lsn`` of the slots created by Patroni is able to catch up with the ``restart_lsn`` of the original slots for the corresponding members. By removing the slots from ``slots`` configuration you will allow Patroni to drop the original slots from your cluster once they are not needed anymore. You can find below an example query to check the ``restart_lsn`` of a couple slots, so you can compare them:
You can set it either in the Patroni YAML file (:ref:`log_settings`) or with
165
+
``PATRONI_LOG_DEDUPLICATE_HEARTBEAT_LOGS=true``.
166
+
167
+
Keep in mind this reduces log volume by suppressing repeated heartbeat messages, but you also lose per-loop
168
+
heartbeat visibility that can help during failover diagnostics.
169
+
160
170
What occurs if I change a Postgres GUC that requires a reload?
161
171
When you change the dynamic or the local configuration as explained in the previous questions, Patroni will take care of reloading the Postgres configuration for you.
Copy file name to clipboardExpand all lines: docs/ha_multi_dc.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@
4
4
HA multi datacenter
5
5
===================
6
6
7
-
The high availability of a PostgreSQL cluster deployed in multiple data centers is based on replication, which can be synchronous or asynchronous (`replication_modes <replication_modes.rst>`_).
7
+
The high availability of a PostgreSQL cluster deployed in multiple data centers is based on replication, which can be synchronous or asynchronous (see :ref:`replication modes <replication_modes>`).
8
8
9
9
In both cases, it is important to be clear about the following concepts:
0 commit comments