Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve connection params for postgres connector #530

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions flow/connectors/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)

// create a separate connection pool for non-replication queries as replication connections cannot
// be used for extended query protocol, i.e. prepared statements
pool, err := pgxpool.New(ctx, connectionString)
connConfig, err := pgxpool.ParseConfig(connectionString)
if err != nil {
return nil, fmt.Errorf("failed to parse connection string: %w", err)
}

runtimeParams := connConfig.ConnConfig.RuntimeParams
runtimeParams["application_name"] = "peerdb_query_executor"
runtimeParams["idle_in_transaction_session_timeout"] = "0"
runtimeParams["statement_timeout"] = "0"

pool, err := pgxpool.NewWithConfig(ctx, connConfig)
if err != nil {
return nil, fmt.Errorf("failed to create connection pool: %w", err)
}
Expand All @@ -63,16 +73,16 @@ func NewPostgresConnector(ctx context.Context, pgConfig *protos.PostgresConfig)
}

// ensure that replication is set to database
connConfig, err := pgxpool.ParseConfig(connectionString)
replConnConfig, err := pgxpool.ParseConfig(connectionString)
if err != nil {
return nil, fmt.Errorf("failed to parse connection string: %w", err)
}

connConfig.ConnConfig.RuntimeParams["replication"] = "database"
connConfig.ConnConfig.RuntimeParams["bytea_output"] = "hex"
connConfig.MaxConns = 1
replConnConfig.ConnConfig.RuntimeParams["replication"] = "database"
replConnConfig.ConnConfig.RuntimeParams["bytea_output"] = "hex"
replConnConfig.MaxConns = 1

replPool, err := pgxpool.NewWithConfig(ctx, connConfig)
replPool, err := pgxpool.NewWithConfig(ctx, replConnConfig)
if err != nil {
return nil, fmt.Errorf("failed to create connection pool: %w", err)
}
Expand Down
Loading