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

Commit308fd97

Browse files
committed
keeper: disable synchronous_commit for pg_basebackup.
Like done for pg_rewind also pg_basebackup should create sessions on themaster with synchronous_commit disabled.
1 parente90771a commit308fd97

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

‎pkg/postgresql/connstring.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,33 @@ import (
2626

2727
typeConnParamsmap[string]string
2828

29-
func (pConnParams)Set(k,vstring) {
30-
p[k]=v
29+
func (cpConnParams)Set(k,vstring) {
30+
cp[k]=v
3131
}
3232

33-
func (pConnParams)Get(kstring) (vstring) {
34-
returnp[k]
33+
func (cpConnParams)Get(kstring) (vstring) {
34+
returncp[k]
3535
}
3636

37-
func (pConnParams)Isset(kstring)bool {
38-
_,ok:=p[k]
37+
func (cpConnParams)Del(kstring) {
38+
delete(cp,k)
39+
}
40+
41+
func (cpConnParams)Isset(kstring)bool {
42+
_,ok:=cp[k]
3943
returnok
4044
}
4145

42-
func (pConnParams)Equals(cpConnParams)bool {
43-
returnreflect.DeepEqual(p,cp)
46+
func (cpConnParams)Equals(cp2ConnParams)bool {
47+
returnreflect.DeepEqual(cp,cp2)
48+
}
49+
50+
func (cpConnParams)Copy()ConnParams {
51+
ncp:=ConnParams{}
52+
fork,v:=rangecp {
53+
ncp[k]=v
54+
}
55+
returnncp
4456
}
4557

4658
// scanner implements a tokenizer for libpq-style option strings.

‎pkg/postgresql/postgresql.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ func (p *Manager) SyncFromFollowedPGRewind(followedConnParams ConnParams, passwo
504504
user:=followedConnParams.Get("user")
505505
pgpass.WriteString(fmt.Sprintf("%s:%s:*:%s:%s\n",host,port,user,password))
506506

507-
// Disablesyncronous replication. pg_rewind needs to create a
507+
// Disablesynchronous commits. pg_rewind needs to create a
508508
// temporary table on the master but if synchronous replication is
509509
// enabled and there're no active standbys it will hang.
510510
followedConnParams.Set("options","-c synchronous_commit=off")
@@ -524,6 +524,8 @@ func (p *Manager) SyncFromFollowedPGRewind(followedConnParams ConnParams, passwo
524524
}
525525

526526
func (p*Manager)SyncFromFollowed(followedConnParamsConnParams)error {
527+
fcp:=followedConnParams.Copy()
528+
527529
// ioutil.Tempfile already creates files with 0600 permissions
528530
pgpass,err:=ioutil.TempFile("","pgpass")
529531
iferr!=nil {
@@ -532,15 +534,24 @@ func (p *Manager) SyncFromFollowed(followedConnParams ConnParams) error {
532534
deferos.Remove(pgpass.Name())
533535
deferpgpass.Close()
534536

535-
host:=followedConnParams.Get("host")
536-
port:=followedConnParams.Get("port")
537-
user:=followedConnParams.Get("user")
538-
password:=followedConnParams.Get("password")
537+
host:=fcp.Get("host")
538+
port:=fcp.Get("port")
539+
user:=fcp.Get("user")
540+
password:=fcp.Get("password")
539541
pgpass.WriteString(fmt.Sprintf("%s:%s:*:%s:%s\n",host,port,user,password))
540542

543+
// Remove password from the params passed to pg_basebackup
544+
fcp.Del("password")
545+
546+
// Disable synchronous commits. pg_basebackup calls
547+
// pg_start_backup()/pg_stop_backup() on the master but if synchronous
548+
// replication is enabled and there're no active standbys they will hang.
549+
fcp.Set("options","-c synchronous_commit=off")
550+
followedConnString:=fcp.ConnString()
551+
541552
log.Info("running pg_basebackup")
542553
name:=filepath.Join(p.pgBinPath,"pg_basebackup")
543-
cmd:=exec.Command(name,"-R","-D",p.dataDir,"--host="+host,"--port="+port,"-U",user)
554+
cmd:=exec.Command(name,"-R","-D",p.dataDir,"-d",followedConnString)
544555
cmd.Env=append(cmd.Env,fmt.Sprintf("PGPASSFILE=%s",pgpass.Name()))
545556
log.Debug("execing cmd",zap.Object("cmd",cmd))
546557
ifout,err:=cmd.CombinedOutput();err!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp