Skip to content

Commit

Permalink
explicitly set client_encoding to UTF8 (#1236)
Browse files Browse the repository at this point in the history
A couple of our queries [`getTableSchemaForTable` and
`getChildToParentRelIDMap`] use the simple query protocol (why is this
needed? not sure). pgx requires `client_encoding` to be set to `UTF8`
for using the simple query protocol, but it won't be set if the database
we are connecting to doesn't use the `UTF8` encoding, which isn't very
likely but still possible.

Fixed by explicitly mentioning `client_encoding` in the connection
string. Also moving `application_name` there.
  • Loading branch information
heavycrystal authored Feb 9, 2024
1 parent ec4ce9a commit 68e9ef1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 3 deletions.
2 changes: 0 additions & 2 deletions flow/connectors/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)
}

runtimeParams := connConfig.Config.RuntimeParams
runtimeParams["application_name"] = "peerdb"
runtimeParams["idle_in_transaction_session_timeout"] = "0"
runtimeParams["statement_timeout"] = "0"

Expand All @@ -67,7 +66,6 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)
}

// ensure that replication is set to database
replConfig.Config.RuntimeParams["application_name"] = "peerdb"
replConfig.Config.RuntimeParams["replication"] = "database"
replConfig.Config.RuntimeParams["bytea_output"] = "hex"

Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/utils/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetPGConnectionString(pgConfig *protos.PostgresConfig) string {
passwordEscaped := url.QueryEscape(pgConfig.Password)
// for a url like postgres://user:password@host:port/dbname
connString := fmt.Sprintf(
"postgres://%s:%s@%s:%d/%s",
"postgres://%s:%s@%s:%d/%s?application_name=peerdb&client_encoding=UTF8",
pgConfig.User,
passwordEscaped,
pgConfig.Host,
Expand Down

0 comments on commit 68e9ef1

Please sign in to comment.