华为云用户手册

  • array_to_string(anyarray, text [, text]) 描述:使用第一个text作为数组的新分隔符,使用第二个text替换数组值为null的值。 返回类型:text 示例: 12345 SELECT array_to_string(ARRAY[1, 2, 3, NULL, 5], ',', '*') AS RESULT; result ----------- 1,2,3,*,5(1 row) 在array_to_string中,如果省略null字符串参数或为NULL,运算中将跳过在数组中的任何null元素,并且不会在输出字符串中出现。
  • hll_add_agg(hll_hashval, int32 log2m, int32 regwidth, int64 expthresh) 描述:把哈希后的数据按照分组放到hll中,依次指定参数log2m、regwidth、expthresh。expthresh的取值范围是-1~7之间的整数,该参数可以用来设置从Explicit模式到Sparse模式的阈值大小。-1表示自动模式,0表示跳过Explicit模式,取1~7表示在基数到达 2expthresh时切换模式。 返回值类型:hll 示例: 12345 SELECT hll_cardinality(hll_add_agg(hll_hash_text(c), NULL, 1, 4)) FROM t_data; hll_cardinality ------------------ 496.628982624022(1 row)
  • hll_add_agg(hll_hashval, int32 log2m, int32 regwidth, int64 expthresh, int32 sparseon) 描述:把哈希后的数据按照分组放到hll中,依次指定参数log2m、regwidth、expthresh、sparseon。sparseon取值范围为0或者1。 返回值类型:hll 示例: 12345 SELECT hll_cardinality(hll_add_agg(hll_hash_text(c), NULL, 1, 4, 0)) FROM t_data; hll_cardinality ------------------ 496.628982624022(1 row)
  • hll_add_agg(hll_hashval) 描述:把哈希后的数据按照分组放到hll中。 返回值类型:hll 示例: 准备数据。 1234 CREATE TABLE t_id(id int);INSERT INTO t_id VALUES(generate_series(1,500));CREATE TABLE t_data(a int, c text);INSERT INTO t_data SELECT mod(id,2), id FROM t_id; 创建表并指定列为hll。 1 CREATE TABLE t_a_c_hll(a int, c hll); 根据a列group by对数据分组,把各组数据加到hll中。 1 INSERT INTO t_a_c_hll SELECT a, hll_add_agg(hll_hash_text(c)) FROM t_data GROUP BY a; 得到每组数据中hll的Distinct值。 123456 SELECT a, #c as cardinality FROM t_a_c_hll order by a; a | cardinality ---+------------------ 0 | 250.741759091658 1 | 250.741759091658(2 rows)
  • hll_add_agg(hll_hashval, int32 log2m) 描述:把哈希后的数据按照分组放到hll中。并指定参数log2m,取值范围为10~16。 返回值类型:hll 示例: 12345 SELECT hll_cardinality(hll_add_agg(hll_hash_text(c), 10)) FROM t_data; hll_cardinality ------------------ 503.932348927339(1 row)
  • hll_add_agg(hll_hashval, int32 log2m, int32 regwidth) 描述:把哈希后的数据按照分组放到hll中。依次指定参数log2m,regwidth。 regwidth取值范围为1~5。 返回值类型:hll 示例: 12345 SELECT hll_cardinality(hll_add_agg(hll_hash_text(c), NULL, 1)) FROM t_data; hll_cardinality ------------------ 496.628982624022(1 row)
  • hll_union_agg(hll) 描述:将多个hll类型数据union成一个hll。 返回值类型:hll 示例: 将各组中的hll数据union成一个hll,并计算distinct值。 12345 SELECT #hll_union_agg(c) as cardinality FROM t_a_c_hll; cardinality ------------------ 496.628982624022(1 row)
  • 使用示例 以当前两个用户自建的数据库db1、db2为例: 在CN上获取集群的所有残留文件记录: 1 db1=# SELECT * FROM pgxc_get_residualfiles() order by 4, 6; -- order by不是必须的 当前集群中: dn_6001_6002 节点(当前的主节点实例)的db1和db2数据库中都存在残留文件记录。 残留文件在residualfile列展示。 filepath列为记录残留文件的记录文件,保存在实例数据目录下pg_residualfiles目录中。 调用pgxc_verify_residualfiles()函数对db1库进行验证: 1 db1=# SELECT * FROM pgxc_verify_residualfiles(); 因为verify类函数都是database级别,所以当前在db1库中调用verify函数时,只对属于db1的残留文件进行验证。 可以再次调用get函数查看是否验证完成: 1 db1=# SELECT * FROM pgxc_get_residualfiles() order by 4, 6; 如上图所示,已确认db1数据库中的残留文件都已经验证,db2数据库中的残留文件都未进行验证。 调用pgxc_rm_residualfiles()函数删除残留文件。 1 db1=# SELECT * FROM pgxc_rm_residualfiles(); 再次调用pgxc_get_residualfiles()函数检查删除后的结果。 结果显示db1数据库中的残留文件已经被删除(isdeleted标记为t),db2中的残留文件都未被删除。 同时可以看到查询出9条结果,与之前查询出的结果相比,缺少一条以9438结尾的残留文件记录文件。这是因为以9438结尾的残留文件记录文件中只有一条残留文件记录,这条记录在步骤3中被删除,当记录文件中的所有残留文件都被删除后,记录文件本身也会被删除,并备份到pg_residualfiles/backup目录中: 如果需要删除db2数据库中的文件,需要在db2中调用verify函数后再调用rm函数。 进入db2数据库,并调用验证函数: 此时可以查询验证的结果: 调用删除函数: 再查询删除的结果: 此时因为8342结尾的记录文件中残留文件已经全部删除,所以整个记录文件也被删除并备份到backup目录下,所以查询到0条记录。
  • 使用步骤 调用pgxc_get_residualfiles()函数,获取存在残留文件的数据库名称。 分别进入确认有残留文件的数据库,调用pgxc_verify_residualfiles()函数,对当前数据库中记录的残留文件进行验证。 调用pgxc_rm_residualfiles()函数,删除所有已经验证过的残留文件。 pgxc类残留文件管理函数只对CN和当前主DN进行操作,不会验证和清理备DN上的残留文件。所以主DN完成清理后,应在备DN上及时执行残留文件清理操作或对备机进行build,防止主备切换后由于增量build导致备机残留文件被重新复制回主DN,导致未成功清理的假象。
  • pg_rm_residualfiles() 描述:用于删除当前实例中所有的残留文件列表中的文件。该函数为实例级函数,与当前所在的数据库无关,可以在任意实例上运行。 参数类型:无 返回值类型:record 函数返回字段如下: 表2 pg_rm_residualfiles()返回字段 名称 类型 描述 result bool 是否已经完成删除。 filepath text 残留文件记录路径。 notes text 注释。 示例: 12345 SELECT * FROM pg_rm_residualfiles(); result | filepath | notes --------+---------------------------+------- t | pgrf_20200908160211441546 | (1 row) 残留文件只有在调用pg_verify_residualfiles()进行验证后才能被真正删除。 删除动作不区分数据库,指定文件中所有已经验证的文件都会被删除。 如果指定文件中记录的所有文件都已经被删除,指定文件会被移除并备份到$PGDATA/pg_residualfile/backup目录下。
  • pgxc_rm_residualfiles() 描述:pgxc_rm_residualfiles的CN统一查询函数。该函数为集群级函数,与当前所在的数据库无关,在CN实例上运行。 参数类型:无 返回值类型:record 函数返回字段如下: 表3 pgxc_rm_residualfiles()返回字段 名称 类型 描述 nodename text 节点名。 result bool 是否已经完成删除。 filepath text 残留文件记录路径。 notes text 注释。 示例: 123456 SELECT * FROM pgxc_rm_residualfiles(); nodename | result | filepath | notes --------------+--------+---------------------------+------- cn_5001 | t | pgrf_20200910170129360401 | dn_6001_6002 | t | pgrf_20200908160211441546 | (2 rows)
  • pg_rm_residualfiles(filepath) 描述:用于删除当前实例中指定残留文件列表中的文件。该函数为实例级函数,与当前所在的数据库无关,可以在任意实例上运行。 参数类型:text 返回值类型:record 函数返回字段如下: 表1 pg_rm_residualfiles(filepath)返回字段 名称 类型 描述 result bool 是否已经完成删除。 示例: 12345 SELECT * FROM pg_rm_residualfiles('pgrf_20200908160211441599'); result -------- t(1 row) 残留文件只有在调用pg_verify_residualfiles()进行verify后才能被真正删除。 删除动作不区分数据库,指定文件中所有已经verify的文件都会被删除。 如果指定文件中记录的所有文件都已经被删除,指定文件会被移除并备份到$PGDATA/pg_residualfile/backup目录下。
  • current_user 描述:当前执行环境下的用户名。current_user是用于表示权限检查的用户标识。通常用来表示会话用户,但是可以通过SET ROLE改变。在函数执行的过程中随着属性SECURITY DEFINER的改变,其值也会改变。 返回值类型:name 示例: 12345 SELECT current_user; current_user-------------- dbadmin(1 row)
  • pgxc_version() 描述:Postgres-XC版本信息。 返回值类型:text 示例: 12345 SELECT pgxc_version(); pgxc_version ------------------------------------------------------------------------------------------------------------- Postgres-XC 1.1 on x86_64-unknown-linux-gnu, based on PostgreSQL 9.2.4, compiled by g++ (GCC) 5.4.0, 64-bit(1 row)
  • pg_my_temp_schema() 描述:pg_my_temp_schema返回当前会话中临时模式的OID,如果不存在(没有创建临时表)的话则返回0。如果给定的OID是其它会话中临时模式的OID,pg_is_other_temp_schema则返回true。 返回值类型:oid 示例: 12345 SELECT pg_my_temp_schema(); pg_my_temp_schema ------------------- 0(1 row)
  • version() 描述:版本信息。version返回一个描述服务器版本信息的字符串。 返回值类型:text 示例: 12345 SELECT version(); version --------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.2.4 gsql (( GaussDB 8.1.3 build 39137c2d) compiled at 2022-04-01 15:43:11 commit 3629 last mr 5138 release) on x86_64-unknown-linux-gnu, compiled by g++ (GCC) 5.4.0, 64-bit(1 row)
  • current_schema[()] 描述:当前模式的名字。current_schema返回在搜索路径中第一个顺位有效的模式名。(如果搜索路径为空则返回NULL,没有有效的模式名也返回NULL)。如果创建表或者其他命名对象时没有声明目标模式,则将使用这些对象的模式。 返回值类型:name 示例: 12345 SELECT current_schema(); current_schema---------------- public(1 row)
  • current_schemas(boolean) 描述:current_schemas(boolean)返回搜索路径中所有模式名字的数组。布尔选项决定像pg_catalog这样隐含包含的系统模式是否包含在返回的搜索路径中。 返回值类型:name[] 示例: 12345 SELECT current_schemas(true); current_schemas--------------------- {pg_catalog,public}(1 row) 搜索路径可以通过运行时设置更改。命令是: 1 SET search_path TO schema [, schema, ...]
  • pg_conf_load_time() 描述:配置加载时间。pg_conf_load_time返回最后加载服务器配置文件的时间戳。 返回值类型:timestamp with time zone 示例: 12345 SELECT pg_conf_load_time(); pg_conf_load_time ------------------------------ 2017-09-01 16:05:23.89868+08(1 row)
  • pg_postmaster_start_time() 描述:数据库实例启动时间。pg_postmaster_start_time返回数据库实例启动时的timestamp with time zone。 返回值类型:timestamp with time zone 示例: 12345 SELECT pg_postmaster_start_time(); pg_postmaster_start_time ------------------------------ 2017-08-30 16:02:54.99854+08(1 row)
  • = 描述:比较两个roaringbitmap是否相等。 返回值类型:bool 示例: 1 2 3 4 5 6 7 8 910 SELECT rb_build('{1,2,3}') = rb_build('{1,2,3}');?column?----------t(1 row)SELECT rb_build('{2,3}') = rb_build('{1,2,3}');?column?----------f(1 row)
  • && 描述:两个roaringbitmap如果有交集返回true,否则返回false。 返回值类型:bool 示例: 1 2 3 4 5 6 7 8 910 SELECT rb_build('{2,3,4}') && rb_build('{2,3}');?column?----------t(1 row)SELECT rb_build('{2,3,4}') && rb_build('{7,8,9}');?column?----------f(1 row)
  • ts_token_type(parser_oid oid, OUT tokid integer, OUT alias text, OUT description text) 描述:获取分析器定义的记号类型。 返回类型:setof record 示例: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627 SELECT ts_token_type(3722); ts_token_type -------------------------------------------------------------- (1,asciiword,"Word, all ASCII") (2,word,"Word, all letters") (3,numword,"Word, letters and digits") (4,email,"Email address") (5,url,URL) (6,host,Host) (7,sfloat,"Scientific notation") (8,version,"Version number") (9,hword_numpart,"Hyphenated word part, letters and digits") (10,hword_part,"Hyphenated word part, all letters") (11,hword_asciipart,"Hyphenated word part, all ASCII") (12,blank,"Space symbols") (13,tag,"XML tag") (14,protocol,"Protocol head") (15,numhword,"Hyphenated word, letters and digits") (16,asciihword,"Hyphenated word, all ASCII") (17,hword,"Hyphenated word, all letters") (18,url_path,"URL path") (19,file,"File or path name") (20,float,"Decimal notation") (21,int,"Signed integer") (22,uint,"Unsigned integer") (23,entity,"XML entity")(23 rows)
  • ts_token_type(parser_name text, OUT tokid integer, OUT alias text, OUT description text) 描述:获取分析器定义的记号类型。 返回类型:setof record 示例: 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627 SELECT ts_token_type('default'); ts_token_type -------------------------------------------------------------- (1,asciiword,"Word, all ASCII") (2,word,"Word, all letters") (3,numword,"Word, letters and digits") (4,email,"Email address") (5,url,URL) (6,host,Host) (7,sfloat,"Scientific notation") (8,version,"Version number") (9,hword_numpart,"Hyphenated word part, letters and digits") (10,hword_part,"Hyphenated word part, all letters") (11,hword_asciipart,"Hyphenated word part, all ASCII") (12,blank,"Space symbols") (13,tag,"XML tag") (14,protocol,"Protocol head") (15,numhword,"Hyphenated word, letters and digits") (16,asciihword,"Hyphenated word, all ASCII") (17,hword,"Hyphenated word, all letters") (18,url_path,"URL path") (19,file,"File or path name") (20,float,"Decimal notation") (21,int,"Signed integer") (22,uint,"Unsigned integer") (23,entity,"XML entity")(23 rows)
  • ts_stat(sqlquery text, [ weights text, ] OUT word text, OUT ndoc integer, OUT nentry integer) 描述:获取tsvector列的统计数据。 返回类型:setof record 示例: 123456 SELECT ts_stat('select ''hello world''::tsvector'); ts_stat ------------- (world,1,1) (hello,1,1)(2 rows)
  • ts_debug([ config regconfig, ] document text, OUT alias text, OUT description text, OUT token text, OUT dictionaries regdictionary[], OUT dictionary regdictionary, OUT lexemes text[]) 描述:测试一个配置。 返回类型:setof record 示例: 123456789 SELECT ts_debug('english', 'The Brightest supernovaes'); ts_debug ----------------------------------------------------------------------------------- (asciiword,"Word, all ASCII",The,{english_stem},english_stem,{}) (blank,"Space symbols"," ",{},,) (asciiword,"Word, all ASCII",Brightest,{english_stem},english_stem,{brightest}) (blank,"Space symbols"," ",{},,) (asciiword,"Word, all ASCII",supernovaes,{english_stem},english_stem,{supernova})(5 rows)
  • ts_parse(parser_oid oid, document text, OUT tokid integer, OUT token text) 描述:测试一个解析。 返回类型:setof record 示例: 12345678 SELECT ts_parse(3722, 'foo - bar'); ts_parse ----------- (1,foo) (12," ") (12,"- ") (1,bar)(4 rows)
  • ts_parse(parser_name text, document text, OUT tokid integer, OUT token text) 描述:测试一个解析。 返回类型:setof record 示例: 12345678 SELECT ts_parse('default', 'foo - bar'); ts_parse ----------- (1,foo) (12," ") (12,"- ") (1,bar)(4 rows)
  • hll_hash_bytea(bytea, int32) 描述:对bytea类型数据计算哈希值,并设置hashseed(即改变哈希策略)。 返回值类型:hll_hashval 示例: 12345 SELECT hll_hash_bytea(E'\\x', 10); hll_hash_bytea --------------------- 6574525721897061910(1 row)
  • hll_hash_bigint(bigint, int32) 描述:对bigint类型数据计算哈希值,并设置hashseed(即改变哈希策略)。 返回值类型:hll_hashval 示例: 12345 SELECT hll_hash_bigint(100::bigint, 10); hll_hash_bigint --------------------- 4631120266694327276(1 row)
共99354条