云服务器内容精选

  • 背景信息 很多用户在使用JDBC连接集群时只连接集群的一个CN,这就导致单个CN压力较大并且别的CN资源浪费,并且这种方式还有单点故障导致连接不可用的风险。 用户可使用JDBC连接多个CN避免以上问题。主要有以下两种方式: 使用ELB连接集群:弹性负载均衡(ELB)是将访问流量根据转发策略分发到后端多台弹性云服务器的流量分发控制服务,可以通过流量分发扩展应用系统对外的服务能力,提高应用程序的容错能力。 使用multi-host方式连接集群:使用JDBC配置多个节点的方式,也能实现类似ELB的效果。
  • 创建逻辑集群关联用户并跨逻辑集群查询数据 以系统管理员dbadmin连接数据库,执行以下SQL语句查看逻辑集群创建成功。 1 SELECT group_name FROM PGXC_GROUP; 创建两个用户u1和u2,分别关联逻辑集群lc1和逻辑集群lc2。 1 2 CREATE USER u1 NODE GROUP "lc1" password '{password}'; CREATE USER u2 NODE GROUP "lc2" password '{password}'; 切换到用户u1,创建表t1,并插入数据。 1 2 3 SET ROLE u1 PASSWORD '{password}'; CREATE TABLE u1.t1 (id int); INSERT INTO u1.t1 VALUES (1),(2); 切换到用户u2,创建表t2,并插入数据。 1 2 3 SET ROLE u2 PASSWORD '{password}'; CREATE TABLE u2.t2 (id int); INSERT INTO u2.t2 VALUES (1),(2); 同时使用u2查询u1.t1表。返回结果提示没有权限。 1 SELECT * FROM u1.t1; 切换回系统管理员dbadmin,查询表u1.t1和u2.t2分别创建到了集群lc1和lc2中,分别对应企业的两块业务,实现了基于逻辑集群的数据隔离。 1 2 3 SET ROLE dbadmin PASSWORD '{password}'; SELECT p.oid,relname,pgroup,nodeoids FROM pg_class p LEFT JOIN pgxc_class pg ON p.oid = pg.pcrelid WHERE p.relname = 't1'; SELECT p.oid,relname,pgroup,nodeoids FROM pg_class p LEFT JOIN pgxc_class pg ON p.oid = pg.pcrelid WHERE p.relname = 't2'; 将逻辑集群lc1的访问权限授予用户u2,同时将SCHEMA u1访问权限、表u1.t1访问权限授予用户u2。 1 2 3 GRANT usage ON NODE GROUP lc1 TO u2; GRANT usage ON SCHEMA u1 TO u2; GRANT select ON TABLE u1.t1 TO u2; 划分逻辑集群后,相当于在原来物理集群的基础上,再增加一层逻辑集群(NODE GROUP)的权限隔离。所以跨逻辑集群访问数据,首先要授权用户有逻辑集群(NODE GROUP层)权限,其次是SCHEMA权限,最后是单张表TABLE权限。如果没有授予逻辑集群的权限,会提示类似permission denied for node group xx的错误信息。 再次切换到u2用户,查询u1.t1表,查询成功,逻辑集群既实现了数据隔离,又可以在用户授权后进行跨逻辑集群访问。 1 2 SET ROLE u2 PASSWORD '{password}'; SELECT * FROM u1.t1;
  • 在Linux环境使用PyGreSQL第三方库连接集群 以root用户登录Linux环境。 执行以下命令创建python_dws.py文件。 1 vi python_dws.py 请复制粘贴以下内容放入python_dws.py文件中: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 #!/usr/bin/env python3 # _*_ encoding:utf-8 _*_ from __future__ import print_function import pg def create_table(connection): print("Begin to create table") try: connection.query("drop table if exists test;" "create table test(id int, name text);") except pg.InternalError as e: print(e) else: print("Table created successfully") def insert_data(connection): print("Begin to insert data") try: connection.query("insert into test values(1,'number1');") connection.query("insert into test values(2,'number2');") connection.query("insert into test values(3,'number3');") except pg.InternalError as e: print(e) else: print("Insert data successfully") def update_data(connection): print("Begin to update data") try: result = connection.query("update test set name = 'numberupdated' where id=1;") print("Total number of rows updated :", result) result = connection.query("select * from test order by 1;") rows = result.getresult() for row in rows: print("id = ", row[0]) print("name = ", row[1], "\n") except pg.InternalError as e: print(e) else: print("After Update, Operation done successfully") def delete_data(connection): print("Begin to delete data") try: result = connection.query("delete from test where id=3;") print("Total number of rows deleted :", result) result = connection.query("select * from test order by 1;") rows = result.getresult() for row in rows: print("id = ", row[0]) print("name = ", row[1], "\n") except pg.InternalError as e: print(e) else: print("After Delete,Operation done successfully") def select_data(connection): print("Begin to select data") try: result = connection.query("select * from test order by 1;") rows = result.getresult() for row in rows: print("id = ", row[0]) print("name = ", row[1]) except pg.InternalError as e: print(e) print("select failed") else: print("Operation done successfully") if __name__ == '__main__': try: conn = pg.DB(host='10.154.70.231', port=8000, dbname='gaussdb', # 需要连接的database user='dbadmin', passwd='password') # 数据库用户密码 except pg.InternalError as ex: print(ex) print("Connect database failed") else: print("Opened database successfully") create_table(conn) insert_data(conn) select_data(conn) update_data(conn) delete_data(conn) conn.close() 或使用dbapi接口实现: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 #!/usr/bin/python # -*- coding: UTF-8 -*- from __future__ import print_function import pg import pgdb def create_table(connection): print("Begin to create table") try: cursor = connection.cursor() cursor.execute("drop table if exists test;" "create table test(id int, name text);") connection.commit() except pg.InternalError as e: print(e) else: print("Table created successfully") cursor.close() def insert_data(connection): print("Begin to insert data") try: cursor = connection.cursor() cursor.execute("insert into test values(1,'number1');") cursor.execute("insert into test values(2,'number2');") cursor.execute("insert into test values(3,'number3');") connection.commit() except pg.InternalError as e: print(e) else: print("Insert data successfully") cursor.close() def update_data(connection): print("Begin to update data") try: cursor = connection.cursor() cursor.execute("update test set name = 'numberupdated' where id=1;") connection.commit() print("Total number of rows updated :", cursor.rowcount) cursor.execute("select * from test;") rows = cursor.fetchall() for row in rows: print("id = ", row[0]) print("name = ", row[1], "\n") except pg.InternalError as e: print(e) else: print("After Update, Operation done successfully") def delete_data(connection): print("Begin to delete data") try: cursor = connection.cursor() cursor.execute("delete from test where id=3;") connection.commit() print("Total number of rows deleted :", cursor.rowcount) cursor.execute("select * from test;") rows = cursor.fetchall() for row in rows: print("id = ", row[0]) print("name = ", row[1], "\n") except pg.InternalError as e: print(e) else: print("After Delete,Operation done successfully") def select_data(connection): print("Begin to select data") try: cursor = connection.cursor() cursor.execute("select * from test;") rows = cursor.fetchall() for row in rows: print("id = ", row[0]) print("name = ", row[1], "\n") except pg.InternalError as e: print(e) print("select failed") else: print("Operation done successfully") cursor.close() if __name__ == '__main__': try: conn = pgdb.connect(host='10.154.70.231', port='8000', database='gaussdb', # 需要连接的database user='dbadmin', password='password') # 数据库用户密码 except pg.InternalError as ex: print(ex) print("Connect database failed") else: print("Opened database successfully") create_table(conn) insert_data(conn) select_data(conn) update_data(conn) delete_data(conn) conn.close() 按照实际集群信息,修改python_dws.py文件中的集群公网访问地址、集群端口号、数据库名称、数据库用户名、数据库密码。 PyGreSQL接口不提供重试连接的能力,您需要在业务代码中实现重试处理。 1 2 3 4 5 conn = pgdb.connect(host='10.154.70.231', port='8000', database='gaussdb', # 需要连接的database user='dbadmin', password='password') # 数据库用户密码 执行以下命令,使用PyGreSQL第三方库连接集群。 1 python python_dws.py
  • 使用约束 由于PyGreSQL是基于PostgreSQL的客户端接口,它的功能GaussDB(DWS)并不能完全支持。具体支持情况请见下表。 以下接口支持情况是基于Python 3.8.5及PyGreSQL 5.2.4版本。 表1 DWS对PyGreSQL主要接口支持情况 PyGreSQL 支持 备注 Module functions and constants connect – Open a PostgreSQL connection Y - get_pqlib_version – get the version of libpq Y - get/set_defhost – default server host [DV] Y - get/set_defport – default server port [DV] Y - get/set_defopt – default connection options [DV] Y - get/set_defbase – default database name [DV] Y - get/set_defuser – default database user [DV] Y - get/set_defpasswd – default database password [DV] Y - escape_string – escape a string for use within SQL Y - escape_bytea – escape binary data for use within SQL Y - unescape_bytea – unescape data that has been retrieved as text Y - get/set_namedresult – conversion to named tuples Y - get/set_decimal – decimal type to be used for numeric values Y - get/set_decimal_point – decimal mark used for monetary values Y - get/set_bool – whether boolean values are returned as bool objects Y - get/set_array – whether arrays are returned as list objects Y - get/set_bytea_escaped – whether bytea data is returned escaped Y - get/set_jsondecode – decoding JSON format Y - get/set_cast_hook – fallback typecast function Y - get/set_datestyle – assume a fixed date style Y - get/set_typecast – custom typecasting Y - cast_array/record – fast parsers for arrays and records Y - Type helpers Y - Module constants Y - Connection – The connection object query – execute a SQL command string Y - send_query - executes a SQL command string asynchronously Y - query_prepared – execute a prepared statement Y - prepare – create a prepared statement Y - describe_prepared – describe a prepared statement Y - reset – reset the connection Y - poll - completes an asynchronous connection Y - cancel – abandon processing of current SQL command Y - close – close the database connection Y - transaction – get the current transaction state Y - parameter – get a current server parameter setting Y - date_format – get the currently used date format Y - fileno – get the socket used to connect to the database Y - set_non_blocking - set the non-blocking status of the connection Y - is_non_blocking - report the blocking status of the connection Y - getnotify – get the last notify from the server N 数据库不支持listen/notify inserttable – insert a list into a table Y copy命令中如果有\n,请使用双引号引用此字段 get/set_notice_receiver – custom notice receiver Y - putline – write a line to the server socket [DA] Y - getline – get a line from server socket [DA] Y - endcopy – synchronize client and server [DA] Y - locreate – create a large object in the database [LO] N 大对象相关操作 getlo – build a large object from given oid [LO] N 大对象相关操作 loimport – import a file to a large object [LO] N 大对象相关操作 Object attributes Y - The DB wrapper class Initialization Y - pkey – return the primary key of a table Y - get_databases – get list of databases in the system Y - get_relations – get list of relations in connected database Y - get_tables – get list of tables in connected database Y - get_attnames – get the attribute names of a table Y - has_table_privilege – check table privilege Y - get/set_parameter – get or set run-time parameters Y - begin/commit/rollback/savepoint/release – transaction handling Y - get – get a row from a database table or view Y - insert – insert a row into a database table Y - update – update a row in a database table Y - upsert – insert a row with conflict resolution Y - query – execute a SQL command string Y - query_formatted – execute a formatted SQL command string Y - query_prepared – execute a prepared statement Y - prepare – create a prepared statement Y - describe_prepared – describe a prepared statement Y - delete_prepared – delete a prepared statement Y - clear – clear row values in memory Y - delete – delete a row from a database table Y 元组必须有唯一键或者主键 truncate – quickly empty database tables Y - get_as_list/dict – read a table as a list or dictionary Y - escape_literal/identifier/string/bytea – escape for SQL Y - unescape_bytea – unescape data retrieved from the database Y - encode/decode_json – encode and decode JSON data Y - use_regtypes – determine use of regular type names Y - notification_handler – create a notification handler N 数据库不支持listen/notify Attributes of the DB wrapper class Y - Query methods getresult – get query values as list of tuples Y - dictresult/dictiter – get query values as dictionaries Y - namedresult/namediter – get query values as named tuples Y - scalarresult/scalariter – get query values as scalars Y - one/onedict/onenamed/onescalar – get one result of a query Y - single/singledict/singlenamed/singlescalar – get single result of a query Y - listfields – list fields names of previous query result Y - fieldname, fieldnum – field name/number conversion Y - fieldinfo – detailed info about query result fields Y - ntuples – return number of tuples in query object Y - memsize – return number of bytes allocated by query result Y - LargeObject – Large Objects open – open a large object N 大对象相关操作 close – close a large object N 大对象相关操作 read, write, tell, seek, unlink – file-like large object handling N 大对象相关操作 size – get the large object size N 大对象相关操作 export – save a large object to a file N 大对象相关操作 Object attributes N 大对象相关操作 The Notification Handler Instantiating the notification handler N 数据库不支持listen/notify Invoking the notification handler N 数据库不支持listen/notify Sending notifications N 数据库不支持listen/notify Auxiliary methods N 数据库不支持listen/notify pgdb Module functions and constants connect – Open a PostgreSQL connection Y - get/set/reset_typecast – Control the global typecast functions Y - Module constants Y - Errors raised by this module Y - Connection – The connection object close – close the connection Y - commit – commit the connection Y - rollback – roll back the connection Y - cursor – return a new cursor object Y - Attributes that are not part of the standard Y - Cursor – The cursor object description – details regarding the result columns Y - rowcount – number of rows of the result Y - close – close the cursor Y - execute – execute a database operation Y - executemany – execute many similar database operations Y - callproc – Call a stored procedure Y - fetchone – fetch next row of the query result Y - fetchmany – fetch next set of rows of the query result Y - fetchall – fetch all rows of the query result Y - arraysize - the number of rows to fetch at a time Y - Methods and attributes that are not part of the standard Y - Type – Type objects and constructors Type constructors Y - Type objects Y -
  • 连接集群前的准备 GaussDB(DWS)集群已绑定弹性IP。 已获取GaussDB(DWS)集群的数据库管理员用户名和密码。 请注意,由于MD5算法已经被证实存在碰撞可能,已严禁将之用于密码校验算法。当前GaussDB(DWS)采用默认安全设计,默认禁止MD5算法的密码校验,可能导致开源客户端无法正常连接的问题。建议先检查数据库参数password_encryption_type参数是否为1,如果取值不为1,需要修改,修改方法参见修改数据库参数;然后修改一次准备使用的数据库用户的密码。 当前GaussDB(DWS)出于安全考虑,已经默认不再使用MD5存储密码摘要了,这将导致使用开源驱动或者客户端无法正常连接数据库。需要您调整密码策略后再创建一个新用户或者对老用户做一次密码修改,方可使用开源协议中使用的MD5认证算法。 数据库中是不会存储您的密码原文的,而是存储的密码的HASH摘要,在密码校验时与客户端发来的密码摘要进行比对(中间会有加盐操作)。故当您改变了密码算法策略时,数据库也是无法还原您的密码,再生成新的HASH算法的摘要值的。必须您手动修改一次密码或者创建一个新用户,这时新的密码将会采用您设置的HASH算法进行摘要存储,用于下次连接认证。 已获取GaussDB(DWS)集群的公网访问地址,含IP地址和端口。具体请参见获取集群连接地址。 已安装PyGreSQL第三方库。 下载地址:http://www.pygresql.org/download/index.html。 安装部署操作请参见:http://www.pygresql.org/contents/install.html。 CentOS、Redhat等操作系统中使用yum命令安装,命令为: 1 yum install PyGreSQL PyGreSQL的使用依赖于PostgreSQL的libpq动态库(32位的PyGreSQL对应32位的libpq,64位的PyGreSQL对应64位的libpq),Linux中可以依赖yum命令解决。在Windows系统使用PyGreSQL需要先安装libpq,主要方式有两种: 安装PostgreSQL,并配置libpq、ssl、crypto动态库位置到环境变量PATH中。 安装psqlodbc,使用PostgreSQL ODBC驱动携带的libpq、ssl、crypto动态库。
  • 告警解释 GaussDB(DWS)每30秒采集集群各节点所有磁盘的使用情况。 如果存在磁盘最近10分钟(可配置)内的最大使用率超过80%(可配置),则上报节点数据盘使用率超阈值的重要告警;如果平均使用率低于75%(即上报阈值减去5%),则消除该重要告警。 如果存在磁盘最近10分钟(可配置)内的最大使用率超过85%(可配置),则上报节点数据盘使用率超阈值的紧急告警;如果平均使用率低于80%(即上报阈值减去5%),则消除该紧急告警。 如果存在磁盘的最大使用率一直大于上报阈值,那么在24小时(可配置)后将再次发起告警。
  • 告警参数 参数名称 参数含义 告警源 产生告警的系统名称。例如:DWS。 集群名称 产生告警的集群名称。 定位信息 产生告警的集群ID、集群名称、实例ID、实例名称。例如,cluster_id: xxxx-xxxx-xxxx-xxxx,cluster_name: test_dws,instance_id: xxxx-xxxx-xxxx-xxxx,instance_name: test_dws-dws-cn-cn-1-1。 详细信息 产生告警的详细信息,包括集群、实例、磁盘、阈值信息。例如:CloudService=DWS, resourceId: xxxx-xxxx-xxxx-xxxx, resourceIdName: test_dws, instance_id: xxxx-xxxx-xxxx-xxxx,instance_name: test_dws-dws-cn-cn-2-1,host_name: host-192-168-1-122,disk_name: /dev/vdb,first_alarm_time: 2022-11-26 11:14:58; 节点10分钟内的平均数据磁盘使用率为84%,超过阈值80%。 产生日期 产生告警的时间。 状态 当前告警的处理状态。
  • 查看已使用的连接数 使用SQL客户端工具连接集群中的数据库。 支持查看如表2所示的连接数场景。 除了创建的时候用双引号引起的数据库和用户名称外,以下命令中用到的数据库名称和用户名称,其中包含的英文字母必须使用小写。 表2 查看连接数介绍 描述 命令 查看指定用户的会话连接数上限。 执行如下命令查看连接到指定用户dbadmin的会话连接数上限。 1 SELECT ROLNAME,ROLCONNLIMIT FROM PG_ROLES WHERE ROLNAME='dbadmin'; 查询结果类似如下信息,其中“-1”表示没有对用户dbadmin设置连接数的限制。 rolname | rolconnlimit ----------+-------------- dwsadmin | -1 (1 row) 查看指定用户已使用的会话连接数。 执行如下命令查看指定用户dbadmin已使用的会话连接数。 1 SELECT COUNT(*) FROM V$SESSION WHERE USERNAME='dbadmin'; 查询结果类似如下信息,其中,“1”表示dbadmin已使用的会话连接数。 count ------- 1 (1 row) 查看指定数据库的会话连接数上限。 执行如下命令查看连接到指定数据库gaussdb的会话连接数上限。 1 SELECT DATNAME,DATCONNLIMIT FROM PG_DATABASE WHERE DATNAME='gaussdb'; 查询结果类似如下信息,其中“-1”表示没有对数据库gaussdb设置连接数的限制。 datname | datconnlimit ----------+-------------- gaussdb | -1 (1 row) 查看指定数据库已使用的会话连接数。 执行如下命令查看指定数据库gaussdb上已使用的会话连接数。 1 SELECT COUNT(*) FROM PG_STAT_ACTIVITY WHERE DATNAME='gaussdb'; 查询结果类似如下信息,其中,“1”表示数据库gaussdb上已使用的会话连接数。 count ------- 1 (1 row) 查看所有用户已使用会话连接数。 执行如下命令查看所有用户已使用的会话连接数。 1 2 3 4 5 SELECT COUNT(*) FROM PG_STAT_ACTIVITY; count ------- 10 (1 row)
  • 查看最大连接数 方式一:集群创建成功后,用户可在GaussDB(DWS)管理控制台上单击指定集群名称,切换至“参数修改”模块查看数据库参数max_connections的取值。 方式二:使用SQL客户端工具连接集群中的数据库后,通过SQL命令的方式查看数据库参数max_connections的取值。 1 SHOW max_connections; 界面显示的结果与以下信息类似,表示数据库默认支持的最大连接数为200。 max_connections ----------------- 200 (1 row)
  • 支持的连接数规格 集群支持的连接数与集群节点规格有关: 表1 支持连接数规格 参数 参数描述 CN连接数 DN连接数 max_connections 允许和数据库连接的最大并发连接数。 800 max(VCPU核数/单节点DN数量*120+24, 5000) max_pool_size CN的连接池与其它某个CN/DN的最大连接数。 max_prepared_transactions 设置可以同时处于预备状态的事务的最大数。 CN及DN概述详情请参见集群逻辑架构。
  • 创建OBS委托 操作场景 创建OBS数据源前需要用户提前创建好授权给GaussDB(DWS)具有OBS OperateAccess或OBS Administrator权限的委托。 操作步骤 鼠标移动至页面右上角账号,单击“统一身份认证”,进入统一身份认证服务页面。 在左侧导航栏单击“委托”,在委托页面右上角单击“创建委托”。 创建委托时委托类型选择“云服务”,云服务选择“DWS”。 单击“下一步”,对委托授予OBS服务的“OBS OperateAccess”或“OBS Administrator”权限。 单击“下一步”,选择授权资源范围为“所有资源”或需要访问的资源,然后确认无误后提交。
  • 使用OBS数据源 GaussDB(DWS)使用外表方式访问OBS上的数据。委托方式与非委托方式,在外表上体现出来的差异仅在于指定了不同的SERVER。 对于非委托方式,控制台提供的SERVER包含access_key和secret_access_key参数,分别对应OBS访问协议的AK和SK值。 对于委托方式,控制台提供的SERVER包含access_key、secret_access_key和security_token参数,分别对应OBS访问协议的临时AK、临时SK和统一身份认证服务IAM中临时安全凭证的SecurityToken值。 在创建好OBS委托和OBS数据源之后,用户从控制台获得相应的包含委托信息的SERVER,假设为obs_server。用户创建和使用外表与非委托方式无差异。关于如何使用OBS数据源,具体请参见从OBS导入数据。 如下示例为通过外表读取OBS上的数据。 建立OBS外表customer_address,不包含分区列。obs_server上的文件,其格式为‘orc’,对应的存储目录为'/user/obs/region_orc11_64stripe1/'。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 CREATE FOREIGN TABLE customer_address ( ca_address_sk integer not null, ca_address_id char(16) not null, ca_street_number char(10) , ca_street_name varchar(60) , ca_street_type char(15) , ca_suite_number char(10) , ca_city varchar(60) , ca_county varchar(30) , ca_state char(2) , ca_zip char(10) , ca_country varchar(20) , ca_gmt_offset decimal(36,33) , ca_location_type char(20) ) SERVER obs_server OPTIONS ( FOLDERNAME '/user/obs/region_orc11_64stripe1/', FORMAT 'ORC', ENCODING 'utf8', TOTALROWS '20' ) DISTRIBUTE BY roundrobin; 通过外表查询OBS上的数据。 1 2 3 4 5 SELECT COUNT(*) FROM customer_address; count ------- 20 (1row)
  • 前提条件 已下载Linux版本的ODBC驱动包“dws_x.x.x_odbc_driver_for_xxx.zip”和Windows版本的ODBC驱动包“dws_odbc_driver_for_windows.zip”,请参见下载JDBC或ODBC驱动。 GaussDB(DWS)也支持开源的ODBC驱动程序:PostgreSQL ODBC 09.01.0200或更高版本。 已下载开源unixODBC代码文件,支持版本为2.3.0,下载地址:https://sourceforge.net/projects/unixodbc/files/unixODBC/2.3.0/unixODBC-2.3.0.tar.gz/download 已下载SSL证书文件,请参见下载SSL证书。
  • 概述 GaussDB(DWS)提供了使用IAM认证方式访问数据库的功能。当使用JDBC应用程序连接集群时,您可以在JDBC连接中配置IAM用户名及其用户凭证等信息,在连接数据库时系统就会自动生成临时数据库凭证,从而成功连接到数据库。 当前仅支持1.3.1及以上版本的集群及其配套的JDBC驱动程序使用IAM认证方式访问数据库。请先参考下载JDBC或ODBC驱动下载JDBC驱动程序。 IoT数仓暂不支持IAM认证方式连接集群。 IAM用户凭证有密码和访问密钥(Access Key ID和Secret Access Key,简称AK和SK)两种类型,您要为JDBC连接提供 IAM 访问密钥。 如需使用IAM用户凭证访问数据库,必须先给您的IAM用户授予DWS Database Access权限,同时拥有DWS Administrator和DWS Database Access权限的用户,才能基于IAM用户生成临时数据库用户凭证以连接GaussDB(DWS)数据库。 需要注意的是,DWS Database Access是用户组级别的权限,您可以通过为用户组授权并将用户加入到用户组的方式,使用户具有用户组中的权限。 在IAM中,只有admin用户组的用户可以管理用户。如需给IAM用户授权,您的IAM账号必须属于IAM的admin用户组,否则,请联系IAM账号管理员帮您授权。 使用IAM用户凭证访问数据库的流程如下: 授予IAM用户DWS Database Access权限 创建IAM用户凭证 配置JDBC连接使用IAM认证方式连接集群
  • 创建IAM用户凭证 用户可以登录管理控制台创建访问密钥,如果您已经创建过了,也可以使用已有的访问密钥。 登录管理控制台。 将鼠标移到右上角的用户名,单击“我的凭证”。 再单击“管理访问密钥”页签,可以查看已有的访问密钥,也可以单击“新增访问密钥”进行创建。 访问密钥是IAM身份认证的重要凭证,只有在新增访问密钥时,用户才可以下载到含有Access Key ID(AK)和Secret Access Key(SK)的密钥文件,在管理控制台只能查看到Access Key ID,如果您未曾下载过该密钥文件,请联系您的管理员进行获取,或者重新创建。 每个用户最多可创建2个访问密钥,有效期为永久。为了账号安全性,建议您定期更换并妥善保存访问密钥。