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

Commita0fa95e

Browse files
committed
take better care of pg_hba.conf
1 parenta4fcaa2 commita0fa95e

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

‎testgres/testgres.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,18 @@ def init(self, allow_streaming=False, fsync=False, initdb_params=[]):
517517

518518
returnself
519519

520-
defdefault_conf(self,allow_streaming=False,fsync=False,log_statement='all'):
520+
defdefault_conf(self,
521+
allow_streaming=False,
522+
fsync=False,
523+
log_statement='all'):
521524
"""
522525
Apply default settings to this node.
523526
524527
Args:
525528
allow_streaming: should this node add a hba entry for replication?
526529
fsync: should this node use fsync to keep data safe?
527530
log_statement: one of ('all', 'off', 'mod', 'ddl'), look at
528-
postgresql docs for more information
531+
PostgreSQL docs for more information
529532
530533
Returns:
531534
This instance of PostgresNode.
@@ -534,18 +537,33 @@ def default_conf(self, allow_streaming=False, fsync=False, log_statement='all'):
534537
postgres_conf=os.path.join(self.data_dir,"postgresql.conf")
535538
hba_conf=os.path.join(self.data_dir,"pg_hba.conf")
536539

537-
# add parameters to hba file
538-
withopen(hba_conf,"w")asconf:
539-
conf.write("# TYPE\tDATABASE\tUSER\tADDRESS\t\tMETHOD\n"
540-
"local\tall\t\tall\t\t\ttrust\n"
541-
"host\tall\t\tall\t127.0.0.1/32\ttrust\n"
542-
"host\tall\t\tall\t::1/128\t\ttrust\n"
543-
# replication
544-
"local\treplication\tall\t\t\ttrust\n"
545-
"host\treplication\tall\t127.0.0.1/32\ttrust\n"
546-
"host\treplication\tall\t::1/128\t\ttrust\n")
547-
548-
# add parameters to config file
540+
# filter lines in hba file
541+
withopen(hba_conf,"r+")asconf:
542+
# get rid of comments and blank lines
543+
lines= [
544+
sforsinconf.readlines()
545+
iflen(s.strip())>0andnots.startswith('#')
546+
]
547+
548+
# write filtered lines
549+
conf.seek(0)
550+
conf.truncate()
551+
conf.writelines(lines)
552+
553+
# replication-related settings
554+
ifallow_streaming:
555+
new_lines= [
556+
"local\treplication\tall\t\t\ttrust\n",
557+
"host\treplication\tall\t127.0.0.1/32\ttrust\n",
558+
"host\treplication\tall\t::1/128\t\ttrust\n"
559+
]
560+
561+
# write missing lines
562+
forlineinnew_lines:
563+
iflinenotinlines:
564+
conf.write(line)
565+
566+
# overwrite postgresql.conf file
549567
withopen(postgres_conf,"w")asconf:
550568
ifnotfsync:
551569
conf.write("fsync = off\n")
@@ -556,17 +574,22 @@ def default_conf(self, allow_streaming=False, fsync=False, log_statement='all'):
556574
self.host,
557575
self.port))
558576

577+
# replication-related settings
559578
ifallow_streaming:
560579
cur_ver=LooseVersion(get_pg_version())
561580
min_ver=LooseVersion('9.6')
562581

563582
# select a proper wal_level for PostgreSQL
564583
wal_level="hot_standby"ifcur_ver<min_verelse"replica"
565584

566-
conf.write("max_wal_senders = 5\n"
567-
"wal_keep_segments = 20\n"
568-
"hot_standby = on\n"
569-
"wal_level = {}\n".format(wal_level))
585+
max_wal_senders=5
586+
wal_keep_segments=20
587+
conf.write("hot_standby = on\n"
588+
"max_wal_senders = {}\n"
589+
"wal_keep_segments = {}\n"
590+
"wal_level = {}\n".format(max_wal_senders,
591+
wal_keep_segments,
592+
wal_level))
570593

571594
returnself
572595

‎tests/test_simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_backup_exhaust(self):
248248
pass
249249

250250
deftest_backup_and_replication(self):
251-
withget_new_node('node')asnode,get_new_node('repl')asreplica:
251+
withget_new_node('node')asnode:
252252
node.init(allow_streaming=True)
253253
node.start()
254254
node.psql('postgres','create table abc(a int, b int)')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp