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

Use the PID to terminate the session #568

Merged
merged 9 commits into from
Oct 11, 2023
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230807-174409.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Use the PID to terminate the session
time: 2023-08-07T17:44:09.15097-06:00
custom:
Author: dbeatty10
Issue: "553"
8 changes: 4 additions & 4 deletions dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ class RedshiftConnectionManager(SQLConnectionManager):
def _get_backend_pid(self):
sql = "select pg_backend_pid()"
_, cursor = self.add_query(sql)

res = cursor.fetchone()
return res
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
return res[0]

def cancel(self, connection: Connection):
try:
Expand All @@ -253,9 +254,8 @@ def cancel(self, connection: Connection):
raise

sql = f"select pg_terminate_backend({pid})"
_, cursor = self.add_query(sql)
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
res = cursor.fetchone()
logger.debug(f"Cancel query '{connection.name}': {res}")
cursor = connection.handle.cursor()
cursor.execute(sql)
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def get_response(cls, cursor: redshift_connector.Cursor) -> AdapterResponse:
Expand Down
Loading