mirror of https://github.com/jackc/pgx.git
Fix syntax error in replication protocol message issued by StartReplication()
According to https://www.postgresql.org/docs/9.6/static/protocol-replication.html pluginArguments should be separated by commas and surrounded by parantheses.pull/389/head
parent
8cf92b683d
commit
cba88a4b7d
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -401,15 +402,14 @@ func (rc *ReplicationConn) TimelineHistory(timeline int) (r *Rows, err error) {
|
||||||
// This function assumes that slotName has already been created. In order to omit the timeline argument
|
// This function assumes that slotName has already been created. In order to omit the timeline argument
|
||||||
// pass a -1 for the timeline to get the server default behavior.
|
// pass a -1 for the timeline to get the server default behavior.
|
||||||
func (rc *ReplicationConn) StartReplication(slotName string, startLsn uint64, timeline int64, pluginArguments ...string) (err error) {
|
func (rc *ReplicationConn) StartReplication(slotName string, startLsn uint64, timeline int64, pluginArguments ...string) (err error) {
|
||||||
var queryString string
|
queryString := fmt.Sprintf("START_REPLICATION SLOT %s LOGICAL %s", slotName, FormatLSN(startLsn))
|
||||||
if timeline >= 0 {
|
if timeline >= 0 {
|
||||||
queryString = fmt.Sprintf("START_REPLICATION SLOT %s LOGICAL %s TIMELINE %d", slotName, FormatLSN(startLsn), timeline)
|
timelineOption := fmt.Sprintf("TIMELINE %d", timeline)
|
||||||
} else {
|
pluginArguments = append(pluginArguments, timelineOption)
|
||||||
queryString = fmt.Sprintf("START_REPLICATION SLOT %s LOGICAL %s", slotName, FormatLSN(startLsn))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range pluginArguments {
|
if len(pluginArguments) > 0 {
|
||||||
queryString += fmt.Sprintf(" %s", arg)
|
queryString += fmt.Sprintf(" ( %s )", strings.Join(pluginArguments, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = rc.c.sendQuery(queryString); err != nil {
|
if err = rc.c.sendQuery(queryString); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue