Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita41b308

Browse files
committed
replication support for different postgres versions
1 parentc10aea1 commita41b308

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name='testgres',
44
packages= ['testgres'],
5-
version='0.1.7',
5+
version='0.1.8',
66
description='Testing utility for postgresql and it''s extensions',
77
author='Ildar Musin',
88
author_email='zildermann@gmail.com',

‎testgres/testgres.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
registered_nodes= []
4646
last_assigned_port=int(random.random()*16384)+49152;
47+
pg_config_data= {}
4748

4849

4950
classClusterException(Exception):pass
@@ -58,8 +59,6 @@ def __init__(self, name, port):
5859
self.base_dir=tempfile.mkdtemp()
5960
os.makedirs(self.logs_dir)
6061
self.working=False
61-
self.config= {}
62-
self.load_pg_config()
6362

6463
@property
6564
defdata_dir(self):
@@ -82,23 +81,13 @@ def connstr(self):
8281
return"port=%s"%self.port
8382
# return "port=%s host=%s" % (self.port, self.host)
8483

85-
defload_pg_config(self):
86-
""" Loads pg_config output into dict """
87-
pg_config=os.environ.get("PG_CONFIG") \
88-
if"PG_CONFIG"inos.environelse"pg_config"
89-
90-
out=subprocess.check_output([pg_config])
91-
forlineinout.split("\n"):
92-
ifline:
93-
key,value=line.split("=",1)
94-
self.config[key.strip()]=value.strip()
95-
9684
defget_bin_path(self,filename):
9785
""" Returns full path to an executable """
98-
ifnot"BINDIR"inself.config:
86+
pg_config=get_config()
87+
ifnot"BINDIR"inpg_config:
9988
returnfilename
10089
else:
101-
return"%s/%s"% (self.config["BINDIR"],filename)
90+
return"%s/%s"% (pg_config.get("BINDIR"),filename)
10291

10392
definit(self,allows_streaming=False):
10493
""" Performs initdb """
@@ -129,15 +118,20 @@ def init(self, allows_streaming=False):
129118
"listen_addresses = '%s'\n"%self.host)
130119

131120
ifallows_streaming:
121+
# TODO: wal_level = hot_standby (9.5)
132122
conf.write(
133-
"wal_level = replica\n"
134123
"max_wal_senders = 5\n"
135124
"wal_keep_segments = 20\n"
136125
"max_wal_size = 128MB\n"
137126
"shared_buffers = 1MB\n"
138127
"wal_log_hints = on\n"
139128
"hot_standby = on\n"
140129
"max_connections = 10\n")
130+
ifget_config().get("VERSION_NUM")<906000:
131+
conf.write("wal_level = hot_standby\n")
132+
else:
133+
conf.write("wal_level = replica\n")
134+
141135
self.set_replication_conf()
142136

143137
definit_from_backup(self,root_node,backup_name,has_streaming=False,hba_permit_replication=True):
@@ -336,6 +330,38 @@ def get_username():
336330
""" Returns current user name """
337331
returnpwd.getpwuid(os.getuid())[0]
338332

333+
defget_config():
334+
globalpg_config_data
335+
336+
ifnotpg_config_data:
337+
pg_config_cmd=os.environ.get("PG_CONFIG") \
338+
if"PG_CONFIG"inos.environelse"pg_config"
339+
340+
out=subprocess.check_output([pg_config_cmd])
341+
forlineinout.split("\n"):
342+
ifline:
343+
key,value=unicode(line).split("=",1)
344+
pg_config_data[key.strip()]=value.strip()
345+
346+
# Numeric version format
347+
version_parts=pg_config_data.get("VERSION").split(" ")
348+
pg_config_data["VERSION_NUM"]=version_to_num(version_parts[-1])
349+
350+
returnpg_config_data
351+
352+
defversion_to_num(version):
353+
"""Converts PostgreSQL version to number for easier comparison"""
354+
importre
355+
356+
ifnotversion:
357+
return0
358+
parts=version.split(".")
359+
whilelen(parts)<3:parts.append("0")
360+
num=0
361+
forpartinparts:
362+
num=num*100+int(re.sub("[^\d]","",part))
363+
returnnum
364+
339365
defget_new_node(name):
340366
globalregistered_nodes
341367
globallast_assigned_port

‎testgres/tests/test_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_backup_and_replication(self):
3939
# Wait until data syncronizes
4040
node.poll_query_until(
4141
'postgres',
42-
'SELECT pg_current_xlog_location() <=write_location '
42+
'SELECT pg_current_xlog_location() <=replay_location '
4343
'FROM pg_stat_replication WHERE application_name =\'%s\''
4444
%replica.name)
4545
# time.sleep(0.5)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp