GaussDB 200远程登陆配置

上篇安装完成GaussDB 200之后,本文讲一下如何使用这个环境做些开发测试,特别是使用Data Studio进行远程访问。

01 创建用户、数据库

首先,用管理员登陆,创建测试用户和测试数据库。

$ gsql -d postgres -p 25308
postgres=# CREATE USER testuser WITH PASSWORD "Test@123";                                  
CREATE ROLE
postgres=# CREATE DATABASE testdb;
	CREATE DATABASE

登出管理员之后,尝试使用新建的账号进行登陆

$ gsql -d testdb -p 25308 -U testuser -W Test@123
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

创建测试表

testdb=> create table t1 (c1 varchar(20), c2 int);
NOTICE:  The 'DISTRIBUTE BY' clause is not specified. Using 'c1' as the distribution column by default.
HINT:  Please use 'DISTRIBUTE BY' clause to specify suitable data distribution column.
CREATE TABLE
testdb=> insert into t1 values ('hello', 1);
INSERT 0 1
testdb=> insert into t1 values ('world', 2);            
INSERT 0 1
testdb=> select * from t1;
  c1   | c2 
-------+----
 world |  2
 hello |  1
(2 rows)

02 使用GUI工具远程登陆

方法一、打开访问控制进行远程连接

将需要连接的主机IP添加到监听地址列表。

#	切换到omm用户
# su - omm

# 查看已有的监听地址
$ gs_guc check -Z coordinator -I all -c "listen_addresses"
expected guc information: host0: listen_addresses=NULL: [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
gs_guc check: host0: listen_addresses='localhost,192.168.2.111': [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]

Total GUC values: 1. Failed GUC values: 0.
The value of parameter listen_addresses is same on all instances.
    listen_addresses='localhost,192.168.2.111'

# 添加远程访问机器的IP
gs_guc set -I all -Z coordinator -c "listen_addresses='localhost,192.168.2.111,192.168.2.112'"
expected instance path: [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]
gs_guc set: listen_addresses='localhost,192.168.2.111,192.168.2.112': [/srv/Bigdata/mppdb/data1/coordinator/postgresql.conf]

Total instances: 1. Failed instances: 0.
Success to perform gs_guc!

# 添加密码登陆方式
$ gs_guc set -Z coordinator -N all -I all -h "host all testuser 192.168.1.112/32 sha256"
Begin to perform gs_guc for all coordinators.

Total instances: 1. Failed instances: 0.
Success to perform gs_guc!

# 重启数据库实例使配置生效
$ gs_om -t stop
$ cm_ctl query
$ cm_ctl start
$ gs_om -t start

然后,找一个Windows的终端,解压Data Studio之后按以下信息进行连接配置。

但是在我的小内存情况下,一旦改了以上配置之后,就会造成数据库实例启动不起来,并且日志有There is insufficient memory for the Java Runtime Environment to continue.错误,可能就是增加监听造成了内存不足。

于是考虑不修改配置,尝试使用ssh端口转发的方式进行连接,在远程主机上模拟本地访问。

方式二、使用SSH端口转发GUI连接

首先,使用终端工具连接GaussDB的服务器,并配置端口转发。这里以Putty为例,将本地的25308端口映射到GaussDB主机的25308端口。

然后,在Data Studio配置连接本地的25308端口,让ssh转发到GaussDB主机上。

最后,登陆连接,查询刚才新建的t1表进行测试。

可以看到成功的查询出通过命令行插入的两条数据。

03 总结

  1. 通常情况下,远程连接需要在主机上增加监听IP和登陆控制配置;
  2. 在小内存测试主机上,增加监听可能造成数据库实例无法启动;
  3. 可以通过SSH端口转发的方式,另辟蹊径实现工具的远程访问。

欢迎扫描二维码关注公众号,可以手机访问文章

原文地址:https://www.cnblogs.com/shenfeng/p/GaussDB200_gui_connect.html