You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by bo...@apache.org on 2017/10/02 15:12:33 UTC

incubator-airflow git commit: [AIRFLOW-1668] Expose keepalives_idle for Postgres connections

Repository: incubator-airflow
Updated Branches:
  refs/heads/master c61726288 -> 05bdd7413


[AIRFLOW-1668] Expose keepalives_idle for Postgres connections

Controls the number of seconds of inactivity after
which TCP
should send a keepalive message to the server.
A value of zero uses the system default.

Important for Redshift which requires a setting
lower than 300.

Closes #2650 from bolkedebruin/AIRFLOW-1688


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/05bdd741
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/05bdd741
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/05bdd741

Branch: refs/heads/master
Commit: 05bdd74131177ea135ed217e23d9f44a6fa1aa10
Parents: c617262
Author: Bolke de Bruin <bo...@xs4all.nl>
Authored: Mon Oct 2 17:12:27 2017 +0200
Committer: Bolke de Bruin <bo...@xs4all.nl>
Committed: Mon Oct 2 17:12:27 2017 +0200

----------------------------------------------------------------------
 airflow/hooks/postgres_hook.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/05bdd741/airflow/hooks/postgres_hook.py
----------------------------------------------------------------------
diff --git a/airflow/hooks/postgres_hook.py b/airflow/hooks/postgres_hook.py
index c8de85b..e47f8e3 100644
--- a/airflow/hooks/postgres_hook.py
+++ b/airflow/hooks/postgres_hook.py
@@ -23,6 +23,9 @@ class PostgresHook(DbApiHook):
     Interact with Postgres.
     You can specify ssl parameters in the extra field of your connection
     as ``{"sslmode": "require", "sslcert": "/path/to/cert.pem", etc}``.
+
+    Note: For Redshift, use keepalives_idle in the extra connection parameters
+    and set it to less than 300 seconds.
     """
     conn_name_attr = 'postgres_conn_id'
     default_conn_name = 'postgres_default'
@@ -42,8 +45,11 @@ class PostgresHook(DbApiHook):
             port=conn.port)
         # check for ssl parameters in conn.extra
         for arg_name, arg_val in conn.extra_dejson.items():
-            if arg_name in ['sslmode', 'sslcert', 'sslkey', 'sslrootcert', 'sslcrl', 'application_name']:
+            if arg_name in ['sslmode', 'sslcert', 'sslkey',
+                            'sslrootcert', 'sslcrl', 'application_name',
+                            'keepalives_idle']:
                 conn_args[arg_name] = arg_val
+
         psycopg2_conn = psycopg2.connect(**conn_args)
         return psycopg2_conn
 
@@ -52,8 +58,8 @@ class PostgresHook(DbApiHook):
         """
         Postgresql will adapt all arguments to the execute() method internally,
         hence we return cell without any conversion.
-        
-        See http://initd.org/psycopg/docs/advanced.html#adapting-new-types for 
+
+        See http://initd.org/psycopg/docs/advanced.html#adapting-new-types for
         more information.
 
         :param cell: The cell to insert into the table