Repository: incubator-airflow Updated Branches: refs/heads/v1-9-test cbf7add7a -> f2bb77d00
[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 (cherry picked from commit 05bdd74131177ea135ed217e23d9f44a6fa1aa10) Signed-off-by: Bolke de Bruin <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/f2bb77d0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/f2bb77d0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/f2bb77d0 Branch: refs/heads/v1-9-test Commit: f2bb77d00bf2171b26e17ac842c678c0ae929013 Parents: cbf7add Author: Bolke de Bruin <[email protected]> Authored: Mon Oct 2 17:12:27 2017 +0200 Committer: Bolke de Bruin <[email protected]> Committed: Mon Oct 2 17:12:42 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/f2bb77d0/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
