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

Add support target_session_attrs #757

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AlexanderSabirov
Copy link

@AlexanderSabirov AlexanderSabirov commented Jan 29, 2025

Problem

When specifying multiple hosts in a PostgreSQL cluster, it is possible to connect to the server in read-only mode.

Solution

When specifying multiple hosts in a PostgreSQL cluster, it is necessary to pass the parameter target_session_attrs. This PR adds support for that parameter.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX

@AlexanderSabirov AlexanderSabirov requested a review from a team as a code owner January 29, 2025 08:05
@cla-bot cla-bot bot added the cla:yes The PR author has signed the CLA label Jan 29, 2025
@cla-bot cla-bot bot temporarily deployed to dbt-bigquery January 29, 2025 08:08 Inactive
colin-rogers-dbt pushed a commit that referenced this pull request Feb 3, 2025
@AlexanderSabirov
Copy link
Author

Hello everyone!

I wanted to share a note about connecting to the PostgreSQL cluster. Because of our architecture, we can’t use a VIP or a load balancer for this.

Right now, if we list all the cluster hosts like host = server1,server2,server3, the connection will go to the first available server, even if it’s in read-only mode.

To fix this, I’ve added the target_session_attrs=read-write parameter in the Merge Request. This ensures that the connection only goes to a server that can handle read-write operations. You can find more details in the PostgreSQL docs: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS.

@mikealfare
@colin-rogers-dbt
Could you please review the Merge Request when you have a moment?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes The PR author has signed the CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant