mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Differentiate between connection address and listen address
For example you can listen on 0.0.0.0 but provide service on some didicated ip. This should cover all possible use-cases when you are running behind firewall, load balancer or inside for example docker.
This commit is contained in:
@@ -38,7 +38,7 @@ class Postgresql:
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.connection_string = 'postgres://{username}:{password}@{listen}/postgres'.format(
|
self.connection_string = 'postgres://{username}:{password}@{listen}/postgres'.format(
|
||||||
listen=self.config['listen'], **self.replication)
|
listen=self.config['connection_address'], **self.replication)
|
||||||
|
|
||||||
self.conn = None
|
self.conn = None
|
||||||
self.cursor_holder = None
|
self.cursor_holder = None
|
||||||
@@ -46,7 +46,7 @@ class Postgresql:
|
|||||||
|
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
if not self.cursor_holder:
|
if not self.cursor_holder:
|
||||||
self.conn = psycopg2.connect('postgres://{}/postgres'.format(self.config['listen']))
|
self.conn = psycopg2.connect('postgres://{}/postgres'.format(self.config['connection_address']))
|
||||||
self.conn.autocommit = True
|
self.conn.autocommit = True
|
||||||
self.cursor_holder = self.conn.cursor()
|
self.cursor_holder = self.conn.cursor()
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ etcd:
|
|||||||
postgresql:
|
postgresql:
|
||||||
name: postgresql0
|
name: postgresql0
|
||||||
listen: 127.0.0.1:5432
|
listen: 127.0.0.1:5432
|
||||||
|
connection_address: 127.0.0.1:5432
|
||||||
data_dir: data/postgresql0
|
data_dir: data/postgresql0
|
||||||
maximum_lag_on_failover: 1048576 # 1 megabyte in bytes
|
maximum_lag_on_failover: 1048576 # 1 megabyte in bytes
|
||||||
replication:
|
replication:
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ etcd:
|
|||||||
postgresql:
|
postgresql:
|
||||||
name: postgresql1
|
name: postgresql1
|
||||||
listen: 127.0.0.1:5433
|
listen: 127.0.0.1:5433
|
||||||
|
connection_address: 127.0.0.1:5433
|
||||||
data_dir: data/postgresql1
|
data_dir: data/postgresql1
|
||||||
maximum_lag_on_failover: 1048576 # 1 megabyte in bytes
|
maximum_lag_on_failover: 1048576 # 1 megabyte in bytes
|
||||||
replication:
|
replication:
|
||||||
|
|||||||
Reference in New Issue
Block a user