[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-9892":3},{"id":4,"name":5,"fullName":6,"owner":5,"repo":5,"description":7,"homepage":8,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":22,"topics":24,"createdAt":9,"pushedAt":9,"updatedAt":34,"readmeContent":35,"aiSummary":36,"trendingCount":15,"starSnapshotCount":15,"syncStatus":37,"lastSyncTime":38,"discoverSource":39},9892,"patroni","patroni\u002Fpatroni","A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes","",null,"Python",8518,1009,126,31,0,22,33,104,71,111.51,"MIT License",false,"master",[25,26,27,28,29,30,31,32,33],"consul","etcd","failover","haproxy","high-availability","kubernetes","postgresql","raft","zookeeper","2026-06-12 04:00:47","|Tests Status| |Coverage Status|\n\n.. image:: docs\u002F_static\u002Fpatroni-logo.svg\n   :height: 128px\n   :width: 128px\n\nPatroni: A Template for PostgreSQL HA with ZooKeeper, etcd or Consul\n--------------------------------------------------------------------\n\nYou can find a version of this documentation that is searchable and also easier to navigate at `patroni.readthedocs.io \u003Chttps:\u002F\u002Fpatroni.readthedocs.io>`__.\n\n**Important!**\n  Running Patroni on **memory-restricted systems with Python 3.11+**\n\n----\n\nIf 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:\n\n- Patroni appears healthy\n- PostgreSQL continues to run\n- Patroni **REST API becomes unresponsive**\n- The operating system reports that Patroni is listening on the REST API port\n- Patroni logs look normal; however, following messages may appear once: ``Exception ignored in thread started by: \u003Cobject repr() failed>``, ``MemoryError``\n- Kernel logs may contain messages such as   ``not enough memory for the allocation``\n\nThis behavior is caused by a `bug in Python 3.11+ \u003Chttps:\u002F\u002Fgithub.com\u002Fpython\u002Fcpython\u002Fissues\u002F140746>`__.\nUnder strict memory conditions, starting a new thread may hang indefinitely when there is not enough free memory.\n\nRecommended solution\n--------------------\n\nRecent 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.\n\nAdditional recommendations (Linux, glibc)\n-----------------------------------------\n\nWhen running with ``vm.overcommit_memory=2`` (recommended for PostgreSQL), we also recommend starting Patroni with the following environment variables configured:\n\n- ``MALLOC_ARENA_MAX=1`` - reduces the amount of virtual memory allocated by glibc for multi-threaded\n  applications\n- ``PG_MALLOC_ARENA_MAX=`` - resets the value of ``MALLOC_ARENA_MAX`` for PostgreSQL processes started by Patroni.\n\nIn addition, you may tune the following Patroni configuration parameters:\n\n- ``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.\n- ``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.\n- ``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.\n\n----\n\nPostgreSQL High Availability and Patroni\n----------------------------------------\n\nThere are many ways to run high availability with PostgreSQL; for a list, see the `PostgreSQL Documentation \u003Chttps:\u002F\u002Fwiki.postgresql.org\u002Fwiki\u002FReplication,_Clustering,_and_Connection_Pooling>`__.\n\nPatroni is a template for high availability (HA) PostgreSQL solutions using Python. For maximum accessibility, Patroni supports a variety of distributed configuration stores like `ZooKeeper \u003Chttps:\u002F\u002Fzookeeper.apache.org\u002F>`__, `etcd \u003Chttps:\u002F\u002Fgithub.com\u002Fcoreos\u002Fetcd>`__, `Consul \u003Chttps:\u002F\u002Fgithub.com\u002Fhashicorp\u002Fconsul>`__ or `Kubernetes \u003Chttps:\u002F\u002Fkubernetes.io>`__. Database engineers, DBAs, DevOps engineers, and SREs who are looking to quickly deploy HA PostgreSQL in datacenters - or anywhere else - will hopefully find it useful.\n\nWe call Patroni a \"template\" because it is far from being a one-size-fits-all or plug-and-play replication system. It will have its own caveats. Use wisely.\n\nCurrently supported PostgreSQL versions: 9.3 to 18.\n\n**Note to Citus users**: Starting from 3.0 Patroni nicely integrates with the `Citus \u003Chttps:\u002F\u002Fgithub.com\u002Fcitusdata\u002Fcitus>`__ database extension to Postgres. Please check the `Citus support page \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002Fcitus.rst>`__ in the Patroni documentation for more info about how to use Patroni high availability together with a Citus distributed cluster.\n\n**Note to Kubernetes users**: Patroni can run natively on top of Kubernetes. Take a look at the `Kubernetes \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002Fkubernetes.rst>`__ chapter of the Patroni documentation.\n\n.. contents::\n    :local:\n    :depth: 1\n    :backlinks: none\n\n=================\nHow Patroni Works\n=================\n\nPatroni (formerly known as Zalando's Patroni) originated as a fork of `Governor \u003Chttps:\u002F\u002Fgithub.com\u002Fcompose\u002Fgovernor>`__, the project from Compose. It includes plenty of new features.\n\nFor additional background info, see:\n\n* `Elephants on Automatic: HA Clustered PostgreSQL with Helm \u003Chttps:\u002F\u002Fwww.youtube.com\u002Fwatch?v=CftcVhFMGSY>`_, talk by Josh Berkus and Oleksii Kliukin at KubeCon Berlin 2017\n* `PostgreSQL HA with Kubernetes and Patroni \u003Chttps:\u002F\u002Fwww.youtube.com\u002Fwatch?v=iruaCgeG7qs>`__, talk by Josh Berkus at KubeCon 2016 (video)\n* `Feb. 2016 Zalando Tech blog post \u003Chttps:\u002F\u002Fengineering.zalando.com\u002Fposts\u002F2016\u002F02\u002Fzalandos-patroni-a-template-for-high-availability-postgresql.html>`__\n\n==================\nDevelopment Status\n==================\n\nPatroni is in active development and accepts contributions. See our `Contributing \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002Fcontributing_guidelines.rst>`__ section below for more details.\n\nWe report new releases information `here \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Freleases>`__.\n\n=========\nCommunity\n=========\n\nThere are two places to connect with the Patroni community: `on github \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni>`__, via Issues and PRs, and on channel `#patroni \u003Chttps:\u002F\u002Fpostgresteam.slack.com\u002Farchives\u002FC9XPYG92A>`__ in the `PostgreSQL Slack \u003Chttps:\u002F\u002Fpgtreats.info\u002Fslack-invite>`__.  If you're using Patroni, or just interested, please join us.\n\n===================================\nTechnical Requirements\u002FInstallation\n===================================\n\n**Pre-requirements for Mac OS**\n\nTo install requirements on a Mac, run the following:\n\n::\n\n    brew install postgresql etcd haproxy libyaml python\n\n**Psycopg**\n\nStarting from `psycopg2-2.8 \u003Chttp:\u002F\u002Finitd.org\u002Fpsycopg\u002Farticles\u002F2019\u002F04\u002F04\u002Fpsycopg-28-released\u002F>`__ the binary version of psycopg2 will no longer be installed by default. Installing it from the source code requires C compiler and postgres+python dev packages.\nSince in the python world it is not possible to specify dependency as ``psycopg2 OR psycopg2-binary`` you will have to decide how to install it.\n\nThere are a few options available:\n\n1. Use the package manager from your distro\n\n::\n\n    sudo apt-get install python3-psycopg2  # install psycopg2 module on Debian\u002FUbuntu\n    sudo yum install python3-psycopg2      # install psycopg2 on RedHat\u002FFedora\u002FCentOS\n\n2. Specify one of `psycopg`, `psycopg2`, or `psycopg2-binary` in the list of dependencies when installing Patroni with pip (see below).\n\n\n**General installation for pip**\n\nPatroni can be installed with pip:\n\n::\n\n    pip install patroni[dependencies]\n\nwhere dependencies can be either empty, or consist of one or more of the following:\n\netcd or etcd3\n    `python-etcd` module in order to use Etcd as DCS\nconsul\n    `py-consul` module in order to use Consul as DCS\nzookeeper\n    `kazoo` module in order to use Zookeeper as DCS\nexhibitor\n    `kazoo` module in order to use Exhibitor as DCS (same dependencies as for Zookeeper)\nkubernetes\n    `kubernetes` module in order to use Kubernetes as DCS in Patroni\nraft\n    `pysyncobj` module in order to use python Raft implementation as DCS\naws\n    `boto3` in order to use AWS callbacks\nsystemd\n    `systemd-python` in order to use sd_notify integration\nall\n    all of the above (except psycopg family)\npsycopg3\n    `psycopg[binary]>=3.0.0` module\npsycopg2\n    `psycopg2>=2.5.4` module\npsycopg2-binary\n    `psycopg2-binary` module\n\nFor example, the command in order to install Patroni together with psycopg3, dependencies for Etcd as a DCS, and AWS callbacks is:\n\n::\n\n    pip install patroni[psycopg3,etcd3,aws]\n\nNote that external tools to call in the replica creation or custom bootstrap scripts (i.e. WAL-E) should be installed independently of Patroni.\n\n=======================\nRunning and Configuring\n=======================\n\nTo get started, do the following from different terminals:\n::\n\n    > etcd --data-dir=data\u002Fetcd --enable-v2=true\n    > .\u002Fpatroni.py postgres0.yml\n    > .\u002Fpatroni.py postgres1.yml\n\nYou will then see a high-availability cluster start up. Test different settings in the YAML files to see how the cluster's behavior changes. Kill some of the components to see how the system behaves.\n\nAdd more ``postgres*.yml`` files to create an even larger cluster.\n\nPatroni provides an `HAProxy \u003Chttp:\u002F\u002Fwww.haproxy.org\u002F>`__ configuration, which will give your application a single endpoint for connecting to the cluster's leader. To configure,\nrun:\n\n::\n\n    > haproxy -f haproxy.cfg\n\n::\n\n    > psql --host 127.0.0.1 --port 5000 postgres\n\n==================\nYAML Configuration\n==================\n\nGo `here \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002Fdynamic_configuration.rst>`__ for comprehensive information about settings for etcd, consul, and ZooKeeper. And for an example, see `postgres0.yml \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fpostgres0.yml>`__.\n\n=========================\nEnvironment Configuration\n=========================\n\nGo `here \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002FENVIRONMENT.rst>`__ for comprehensive information about configuring(overriding) settings via environment variables.\n\n===================\nReplication Choices\n===================\n\nPatroni uses Postgres' streaming replication, which is asynchronous by default. Patroni's asynchronous replication configuration allows for ``maximum_lag_on_failover`` settings. This setting ensures failover will not occur if a follower is more than a certain number of bytes behind the leader. This setting should be increased or decreased based on business requirements. It's also possible to use synchronous replication for better durability guarantees. See `replication modes documentation \u003Chttps:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Fblob\u002Fmaster\u002Fdocs\u002Freplication_modes.rst>`__ for details.\n\n======================================\nApplications Should Not Use Superusers\n======================================\n\nWhen connecting from an application, always use a non-superuser. Patroni requires access to the database to function properly. By using a superuser from an application, you can potentially use the entire connection pool, including the connections reserved for superusers, with the ``superuser_reserved_connections`` setting. If Patroni cannot access the Primary because the connection pool is full, behavior will be undesirable.\n\n.. |Tests Status| image:: https:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Factions\u002Fworkflows\u002Ftests.yaml\u002Fbadge.svg\n   :target: https:\u002F\u002Fgithub.com\u002Fpatroni\u002Fpatroni\u002Factions\u002Fworkflows\u002Ftests.yaml?query=branch%3Amaster\n.. |Coverage Status| image:: https:\u002F\u002Fcodecov.io\u002Fgh\u002Fpatroni\u002Fpatroni\u002Fgraph\u002Fbadge.svg?token=qWNJyFTeul \n   :target: https:\u002F\u002Fcodecov.io\u002Fgh\u002Fpatroni\u002Fpatroni\n","Patroni 是一个用于构建基于 PostgreSQL 的高可用性集群的模板，支持使用 Etcd、Consul、ZooKeeper 或 Kubernetes 作为协调服务。其核心功能包括自动故障转移、负载均衡以及通过 REST API 进行管理与监控。Patroni 使用 Python 编写，能够有效应对内存受限环境下的运行挑战，并且提供了针对特定场景（如在设置 vm.overcommit_memory=2 的系统上运行）的优化建议。该项目适用于需要保证数据库高可用性和可靠性的企业级应用或云原生环境中。",2,"2026-06-11 03:25:16","top_topic"]