当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
15 Star 6 Fork 18

openGauss/openGauss-connector-python-psycopg2
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

通知: openGauss社区已经正式迁移至 Gitcode 平台

openGauss-connector-python-psycopg2

介绍

该仓库为openGauss的python驱动。

打包步骤

  1. 推荐使用python3,请在服务器上装python3和python3-devel

    yum install python3 python3-devel
    
  2. python驱动的打包需要依赖openGauss-server编译的libpq,请参照 openGauss使用命令编译代码

  3. 下载 openGauss-connector-python-psycopg2 仓库代码,进入到根目录下,执行

    sh build.sh -bd /data/compile/openGauss-server/dest/ -v 5.0.0
    

    说明
    -bd: 指定openGauss数据库构建结果目录
    -v: 指定构建包的版本号。不指定则默认为5.0.0

    编译完成后的驱动,在 output 目录下。

软件下载

社区每日构建,提供三套环境已经编译好的驱动包供使用,下载路径如下:

其中 <VERSION> 为当前最新的版本号。

openEuler-aarch64:

https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/arm/openGauss-<VERSION>-openEuler-aarch64-Python.tar.gz

CentOS-x86_64:

https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/x86/openGauss-<VERSION>-CentOS-x86_64-Python.tar.gz

openEuler-x86_64:

https://opengauss.obs.cn-south-1.myhuaweicloud.com/latest/x86_openEuler/openGauss-<VERSION>-openEuler-x86_64-Python.tar.gz

也可以在官网下载页面的openGauss Connectors部分下载各版本已发布的驱动包,下载好之后,需对软件包的完整性进行校验,操作步骤如下:

(1)计算下载包的sha256值(以6.0.1版本发布包为例,其他版本操作相同)

sha256sum openGauss-Python-6.0.1-openEuler22.03-aarch64.tar.gz

(2)在官网下载页面的openGauss Connectors部分中复制对应驱动包的sha256值,与步骤(1)计算出的sha256值做对比,如果一致则可以确认下载下来的包是完整的,否则需要重新下载。

使用说明

安装 psycopg2

解压安装包后,会得到两个目录 libpsycopg2

接下来您需要将 psycopg2 目录拷贝到 Python 解释器的 site-packages 下,让 python 可以索引到

可以通过如下指令来查找 site-packages 目录所在位置:

python -c "from distutils.sysconfig import get_python_lib;print(get_python_lib())"
# output: /usr/lib/python3.6/site-packages

确定 site-packages 的目录位置后,将 psycopg2 文件夹整个拷贝该目录下,并授权便于其他用户使用

cp -r psycopg2 [/path/to/site-packages/] && chmod 755 [/path/to/site-packages/]psycopg2

安装包中的另一个目录 lib 是 psycopg2 依赖的 libpq 等 C 动态库文件。

这个目录中的文件可能会和系统的动态库存在重名冲突的问题,

所以建议将应用程序和 lib 目录存放到单独的一个系统用户下和系统自带库进行隔离,避免影响系统其他工具。

切换到运行用户下,执行如下命令进行设置:

echo "export LD_LIBRARY_PATH=[/path/to/lib]:$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc

这样就安装完成了。

应用连接

import psycopg2

# dsn 格式
conn = psycopg2.connect("postgres://user:password@ip1:port,ip2:port:.../dbname?target_session_attrs=[any|read-write]")
# key-value 格式
conn = psycopg2.connect(host="ip1[,ip2]",
                        port=port1,
                        database=db,
                        user=user,
                        password=password,
                        target_session_attrs="read-write")

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

空文件

发行版 (3)

全部
2年前

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opengauss/openGauss-connector-python-psycopg2.git
git@gitee.com:opengauss/openGauss-connector-python-psycopg2.git
opengauss
openGauss-connector-python-psycopg2
openGauss-connector-python-psycopg2
master

搜索帮助