openGauss-connector-go-pq:基于Go数据库/sql包的openGauss驱动项目

用户可使用此项目通过Go语言连接openGauss数据库,支持SHA256/SM3密码认证、多host定义、SSL配置及坏连接处理,兼容libpq特性,确保安全高效连接。【此简介由AI生成】

分支2Tags12
文件最后提交记录最后更新时间
fix go link11 个月前
fix go link11 个月前
完善资料说明9 个月前
fix go link11 个月前
fix go link11 个月前
style: remove Useless comments4 年前
feat: support blob type4 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
style: add gitignore file4 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
feat: Support login authentication protocol AUTH_REQ_MD5_SHA256=114 年前
完善资料说明9 个月前
完善资料说明9 个月前
完善资料说明9 个月前
完善资料说明9 个月前
完善资料说明9 个月前
fix: Keep track of (context cancelled) error on connection4 年前
feat: support blob type4 年前
fix go link11 个月前
fix go link11 个月前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
fix go link11 个月前
feat: support blob type4 年前
fix go link11 个月前
feat: support blob type4 年前
完善资料说明9 个月前
feat: support blob type4 年前
fix: Connection timeout problem under master-slave multi-node connection1 年前
fix go link11 个月前
feat: add custom tls4 年前
feat: add CopyData method3 年前
style: remove Useless comments4 年前
feat: support blob type4 年前
feat: support blob type4 年前
fix go link11 个月前
fix go link11 个月前
fix go link11 个月前
feat: error add SQLState3 年前
fix go link11 个月前
feat: support blob type4 年前
feat: error add SQLState3 年前
fix: enable_thread_pool=on kill session issue3 年前
feat: support blob type4 年前
fix go link11 个月前
add connect Parameter target_session_attrs4 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
fix go link11 个月前
feat: add custom tls4 年前
feat: adds support for kubernetes mounted private keys3 年前
feat: add custom tls4 年前
修复多向量查询中向量解析失败+多连接限制问题9 个月前
feat: adapt openGauss SM3 password authentication4 年前
feat: adapt openGauss SM3 password authentication4 年前
fix go link11 个月前
fix go link11 个月前
feat: support blob type4 年前
feat: adds support for kubernetes mounted private keys3 年前
feat: adds support for kubernetes mounted private keys3 年前
完善资料说明9 个月前
fix: Keep track of (context cancelled) error on connection4 年前
feat: support blob type4 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
fix: Keep track of (context cancelled) error on connection4 年前
fix: Keep track of (context cancelled) error on connection4 年前
modify tests.md postgres to openGauss5 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前
fork from github/lib/pq. Adapt openGauss SHA256 password authentication5 年前

pq - 用于Go数据库/sql包的Go openGauss驱动程序

fork from github/lib/pq

安装

go get gitcode.com/opengauss/openGauss-connector-go-pq

openGauss版libpq差异

使用原生libpq go驱动程序访问openGauss时,会报以下错误。

pq: Invalid username/password,login denied.

因为openGauss默认的用户连接密码认证方法是sha256,这是唯一的加密方法。 openGauss配置经以下几种方法修改后支持原生libpq连接。

  1. 设置openGauss初始化参数password_encryption_type。

    alter system set password_encryption_type=0;
    
  2. 设置pg_hba.conf以允许md5密码验证:host all test 0.0.0.0/0 md5。

  3. 在数据库中创建新用户,然后通过此用户连接。

不过,我们仍然更倾向使用像sha256这样更安全的加密方法,修改后的libpq可以直接兼容sha256。

特性

  • 适配openGauss SHA256/SM3 密码认证
  • 支持连接字符串多host定义
  • SSL
    • sslmode
    • sslrootcert
    • sslcert
    • sslkey
    • sslinline 指定sslkey/sslcert是字符串,而不是文件名
    • sslpassword 指定sslkey密码短语
  • 处理database/sql坏连接
  • 正确扫描time.Time(即timestamp[tz], time[tz], date
  • 正确扫描二进制Blob(即bytea
  • 支持hstore软件包
  • 支持COPY FROM
  • pq.ParseURL用于将URL转换为sql.Open的连接字符串。
  • libpq兼容的环境变量
  • 支持Unix套接字
  • 通知:LISTEN/NOTIFY
  • 支持pgpass
  • GSS(Kerberos)验证

Multiple Hosts

示例multi_ip

postgres 介绍文档LIBPQ-MULTIPLE-HOSTS

  • 支持同时定义主从地址,自动选择主库连接,当发生切换事自动连接新当主库.
  • 连接字符中target_session_attrs参数暂时只能定义read-write(默认配置),配置为read-only存在问题
  • target_session_attrs
    • any (default)
    • read-write
    • read-only
    • primary
    • standby
    • prefer-standby
postgres://gaussdb:secret@foo,bar,baz/mydb?sslmode=prefer&target_session_attrs=primary&connect_timeout=1
postgres://gaussdb:secret@foo:1,bar:2,baz:3/mydb?sslmode=prefer&target_session_attrs=primary&connect_timeout=1
user=gaussdb password=secret host=foo,bar,baz port=5432 dbname=mydb sslmode=prefer target_session_attrs=primary connect_timeout=1
user=gaussdb password=secret host=foo,bar,baz port=5432,5432,5433 dbname=mydb sslmode=prefer target_session_attrs=primary connect_timeout=1

示例

import (
 "database/sql"

 _ "gitcode.com/opengauss/openGauss-connector-go-pq"
)

func main() {
 connStr := "host=127.0.0.1 port=5432 user=gaussdb password=****** dbname=postgres sslmode=prefer"
 db, err := sql.Open("opengauss", connStr)
 if err != nil {
  log.Fatal(err)
 }
 var date string
 err = db.QueryRow("select current_date ").Scan(&date)
 if err != nil {
  log.Fatal(err)
 }
 fmt.Println(date)
}

注意:该仓库中所有资料和测试文件(copy_test.go, encode_test.go等)使用的密码及sslmode=disable仅为示例,在使用时,请根据实际情况配置正确的密码、使用安全的sslmode(默认值prefer)。

测试

go test适用于测试。 有关更多详细信息,请参见测试.md

项目介绍

用户可使用此项目通过Go语言连接openGauss数据库,支持SHA256/SM3密码认证、多host定义、SSL配置及坏连接处理,兼容libpq特性,确保安全高效连接。【此简介由AI生成】

定制我的领域