气流initdb上的sql alchemy连接终止

时间:2020-01-19 16:06:28

标签: python macos sqlalchemy python-3.5 airflow

我将Airflow v1.9.0Python 3.5.2一起使用。
我有一个可以正常运行的暂存和生产环境。
我还在本地运行良好的本地Ubuntu机器上本地使用它。
最近,我从原来的MacOS 10.15.2转到了Ubuntu 18

问题

当我执行$airflow initdb$airflow upgradedb时,出现此混乱的SQL Alchemy错误。

Traceback (most recent call last):
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/bin/airflow", line 27, in <module>
    args.func(args)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/airflow/bin/cli.py", line 897, in initdb
    db_utils.initdb()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/airflow/utils/db.py", line 103, in initdb
    upgradedb()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/airflow/utils/db.py", line 320, in upgradedb
    command.upgrade(config, 'heads')
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/alembic/command.py", line 174, in upgrade
    script.run_env()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/alembic/script/base.py", line 416, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/alembic/util/pyfiles.py", line 93, in load_python_file
    module = load_module_py(module_id, path)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/alembic/util/compat.py", line 68, in load_module_py
    module_id, path).load_module(module_id)
  File "<frozen importlib._bootstrap_external>", line 388, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 809, in load_module
  File "<frozen importlib._bootstrap_external>", line 668, in load_module
  File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/airflow/migrations/env.py", line 86, in <module>
    run_migrations_online()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/airflow/migrations/env.py", line 73, in run_migrations_online
    with connectable.connect() as connection:
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 2102, in connect
    return self._connection_cls(self, **kwargs)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 90, in __init__
    if connection is not None else engine.raw_connection()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 2188, in raw_connection
    self.pool.unique_connection, _connection)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 2162, in _wrap_pool_connect
    e, dialect, self)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 1476, in _handle_dbapi_exception_noconnection
    exc_info
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 265, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 248, in reraise
    raise value.with_traceback(tb)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/base.py", line 2158, in _wrap_pool_connect
    return fn()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 342, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 788, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 529, in checkout
    rec = pool._do_get()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 1193, in _do_get
    self._dec_overflow()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 249, in reraise
    raise value
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 1190, in _do_get
    return self._create_connection()
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 347, in _create_connection
    return _ConnectionRecord(self)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 474, in __init__
    self.__connect(first_connect_check=True)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/pool.py", line 671, in __connect
    connection = pool._invoke_creator(self)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py", line 106, in connect
    return dialect.connect(*cargs, **cparams)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/sqlalchemy/engine/default.py", line 412, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/Users/userabc/.pyenv/versions/3.5.2/envs/vmds/lib/python3.5/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
 (Background on this error at: http://sqlalche.me/e/e3q8)

配置

我这样做

$ grep sql_alchemy_conn $AIRFLOW_HOME/airflow.cfg

我可以在终端上看到此输出

sql_alchemy_conn=postgresql://airflow-user:airflow-pwd@localhost/airflow-db

使用DataGrip,甚至可以给定连接字符串中提到的凭据来连接到该数据库。

已检查

我做了

$brew services list | grep postgres

我可以看到该服务运行正常

postgresql started saadali /Users/userabc/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

即使正在运行,也要仔细检查,这就是为什么我能够通过Datagrip进行连接的原因。 我究竟做错了什么? MacOS有什么不同吗?

注意:2/3天前,我在同事的MacOS上以相同的设置设置了气流,尽管我不确定他的MacOS版本是什么,但没有发生此类错误。 。

1 个答案:

答案 0 :(得分:0)

我运行的防病毒程序阻止了该端口。关闭防火墙对我有用。