使用psqlodbc连接到Linux服务器上的Redshift

时间:2019-01-03 16:49:04

标签: python sql odbc

我目前使用SQLAlechemy和Psycopg2成功连接到Redshift,如下所示:

HOST = "host"
PORT = "5439"
DATABASE = "db"
USER = "user"
PASSWORD = "pass"

server = "redshift+psycopg2://%s:%s@%s:%s/%s" % (USER,PASSWORD,HOST,str(PORT),DATABASE)
engine = sa.create_engine(server, connect_args={'sslmode': 'verify-ca'})
conn = engine.raw_connection()

我正在尝试利用ODBC(尤其是根据Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBCfast_executemany解决方案),因此,我尝试通过PyODBC和psqlODBC驱动程序重新编写它,因为它可用通过conda安装(与Redshift ODBC不同),例如:

conn = pyodbc.connect(
    Driver='{/usr/local/anaconda/envs/jupyter-atp/lib/psqlodbcw.so}', 
    Server='host', 
    Port='5439',
    Database='db', 
    UID='user', 
    PWD='pass',
    sslmode='verify-ca'
    )

我也按照https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/ssl/尝试了sslmode='require',但仍然得到以下信息:Error: ('28000', '[28000] FATAL: no pg_hba.conf entry for host "::ffff:10.5.135.13", user "user", database "db", SSL off (210) (SQLDriverConnect)')。我在SQLAlchemy上遇到了类似的错误,但是sslmode='verify-ca'修复了它。.

有人建议我如何向PyODBC添加连接参数以打开SSL?

0 个答案:

没有答案