opengauss客户端工具连接实践【华为根技术】
openGauss是一款提供面向多核的极致性能、全链路的业务和数据安全,基于AI的调优和高效运维的能力,全面友好开放,携手伙伴共同打造全球领先的企业级开源关系型数据库,采用木兰宽松许可证v2发行。openGauss深度融合华为在数据库领域多年的研发经验,结合企业级场景需求,持续构建竞争力特性。多种存储模式支持复合业务场景,新引入提供原地更新存储引擎axos一致性日志复制协议,主备模式.
复习
gs_ctl start -D /home/gauss/openGauss/data
gs_ctl stop-D /home/gauss/openGauss/data
gs_ctl restart -D /home/gauss/openGauss/data
gsql -d postgres -p 5432
gitee源码: https://gitcode.com/opengauss/DataStudio
Data Studio 下载链接:https://opengauss.obs.cn-south-1.myhuaweicloud.com/1.0.1/DataStudio_win_64.zip
可能出现的错误界面如下图所示:
①bug修复
powershell下执行,不依赖telnet
Test-NetConnection 192.168.85.133 -Port 5432
cmd下执行,需要telnet,控制面板-->程序和功能-->启动和关闭windows功能,勾选telnet,确定即可。
telnet 192.168.85.133 5432
嵌套的错误:
AI搜索解决方案
#服务已经在运行了
ss -lntup|grep 5432
[gauss@localhost root]$ gs_ctl status -D /home/gauss/openGauss/data
[2025-05-13 16:15:17.068][24099][][gs_ctl]: gs_ctl status,datadir is /home/gauss/openGauss/data
gs_ctl: server is running (PID: 11885)
/home/gauss/openGauss/install/bin/gaussdb "-D" "/home/gauss/openGauss/data"
默认情况下,opengauss 只接收本机的连接请求。如果需要通过远程客户端进行连接,可以执行以下两个步骤(使用 用户操作):
-
修改 postgresql.conf 文件中的监听地址,该文件位于数据目录(/home/gauss/openGauss/data/)中。
找到以下内容:
#listen_addresses = 'localhost' # what IP address(es) to listen on;
将‘localhost’修改为服务器的 IP 地址或者‘*’:
listen_addresses = '0.0.0.0'
port = 5432
#上面的port原来有注释,去掉注释即可,73行。
2.修改 pg_hba.conf 文件中的客户端认证配置,该文件位于数据目录(/home/gauss/openGauss/data/)
中。增加以下内容,允许所有客户端 IP 访问:
host all all 0.0.0.0/0 sha256
重启服务即可(使用 root 用户操作):
gs_ctl restart -D /home/gauss/openGauss/data
②修改:
改pg_hba.conf文件的访问控制规则,用于定义客户端如何通过身份验证连接到数据库。允许来自 IP 范围 192.168.85.0/24
的客户端通过 TCP/IP 协议连接到数据库的所有数据库和所有用户,并强制使用 SHA256/md5 加密方式进行密码验证。
最后一行
host all all 192.168.85.0/24 sha256
host all all 192.168.85.0/24 md5
如果出现下图界面,取消SSL这个对钩即可。
#下面的操作暂时可以不用修改。
修改:postgresql.conf
#89行注释去掉
[gauss@server2 data]$ grep ssl postgresql.conf -n 89:ssl = off # (change requires restart)
#暂时不用修改
上述完毕后,都需要重启!
下面的这个bug是不能使用创建opengauss的时候默认账户(我们这里是guass)
再次使用PowerShell连接openGauss服务器
这个时候表示已经成功连接;接下来使用DataStudio连接测试:
③修复bug
需要用到下一次讲的内容,创建一个用户/角色。
首先,以gauss登录,
gsql -d postgres -p 5432
opengauss# create role admin login createdb createrole password 'Tony8888';
用户admin
密码Tony8888
进入到下面的界面表示:Data Studio已经连接openGauss服务器成功!
Pgadmin4
pgAdmin,一个设计,维护和管理 Postgres 数据库用的通用工具。
官网:https://www.pgadmin.org
- pgAdmin 4 is a rewrite of pgAdmin III (see below) in Python/Javascript. It isable to be run either in it’s own C++ based Desktop Runtime, or as a webapplication for multiple users.

配置连接串
创建数据库类型时选择 pg 即可。
bug
pgAdmin4 默认使用 PostgreSQL 的驱动连接数据库,而 openGauss 的认证机制(如 scram-sha-256
或 SASL)可能与 pgAdmin4 不完全兼容,导致错误。
修复bug
①
#默认是2,修改成1,表示支持md5和sha256,两种秘钥方式
[gauss@localhost data]$ grep password_enc postgresql.conf -n
110:#password_encryption_type = 2 #Password storage type, 0 is md5 for PG, 1 is sha256 + md5, 2 is sha256 only
vim postgresql.conf
到110行修改即可
110:#password_encryption_type = 1
重启opengauss
[gauss@localhost data]$ gs_ctl restart -D /home/gauss/openGauss/data
②
重新修改admin这个用户的密码,因为之前是sha256秘钥验证方式,现在pgAdmin是md5,必须md5方式。
先以gauss用户登录,修改admin的密码
ALTER USER admin WITH PASSWORD 'Admin8888';
#创建一个角色tony,密码Tony8888
CREATE ROLE tony WITH LOGIN PASSWORD 'Tony8888' ;
#\du 去查看角色或者
select rolname from pg_roles;
使用刚才你创建的角色/用户,去登录opengauss
#rlwrap:我这里的写法,大家可以不写
#-h:远程ip
#-p:端口号
#-U:用户
#postgres:默认的数据库
rlwrap gsql -h 192.168.85.135 -p 5432 -U tony postgres
Password for user tony:
#链接到数据库
openGauss=> \c
Password for user tony:
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "postgres" as user "tony".
创建一个独立的角色/用户
openGauss=# create role admin createdb createrole password 'Tony8888';
CREATE ROLE
openGauss=# \du
List of roles
Role name | Attributes | Member of
admin | Create role, Create DB, Cannot login
openGauss=# alter role admin login;
ALTER ROLE
openGauss=# \du
List of roles
Role name | Attributes | Member of
admin | Create role, Create DB
总结
本文介绍了 openGauss 6.0 的客户端工具连接openGauss服务器的流程,具体包配置以及常见问题的解决方案。通过本文,伙伴们可以顺利完成 openGauss客户端工具DataStudio和pgAdmin4的连接,快速上手使用。
- 点赞
- 收藏
- 关注作者
评论(0)