2
0

Enforce simple protocol on ReplicationConn

This commit is contained in:
Jan Vcelak
2019-03-31 20:29:37 +02:00
parent 2e26d8df03
commit 3e82824ff1
2 changed files with 26 additions and 0 deletions
+1
View File
@@ -163,6 +163,7 @@ func ReplicationConnect(config ConnConfig) (r *ReplicationConn, err error) {
config.RuntimeParams = make(map[string]string)
}
config.RuntimeParams["replication"] = "database"
config.PreferSimpleProtocol = true
c, err := Connect(config)
if err != nil {
+25
View File
@@ -343,3 +343,28 @@ func TestStandbyStatusParsing(t *testing.T) {
t.Errorf("Unexpected write position %d", status.WalWritePosition)
}
}
func TestSimpleProtocolEnforcement(t *testing.T) {
if replicationConnConfig == nil {
t.Skip("Skipping due to undefined replicationConnConfig")
}
replicationConn := mustReplicationConnect(t, *replicationConnConfig)
defer closeReplicationConn(t, replicationConn)
query := "select count(*) from pg_replication_slots"
// Check that the simple query protocol is used by default
rows, err := replicationConn.Query(query)
if err != nil {
t.Fatalf("Query failed: %v", err)
}
rows.Close()
// Check that using the extended query protocol will fail
rows, err = replicationConn.QueryEx(context.Background(), query, &pgx.QueryExOptions{SimpleProtocol: false})
if err == nil {
t.Fatal("Query expected to fail.")
}
rows.Close()
}