hologres 常用命令
- 设置binlog:
- 查看表结构
- 查日志
- 查binlog
- 筛选已过期的binlog
- 日期函数
- 查询慢sql 查cpu耗时
- 切换表结构
- 日期转换
- yyyymmdd 转 yyyy-mm-dd
- 查cpu占用
- 2. 表属性查询(DK / SK / CK / TG)
- 3. WHERE 字段分布采集(判断 DK 是否命中查询模式)
- 4. 视图链路追踪(确认查询实际落到的物理底表)
- 5. 表门店字段确认
- 6. 单表查询性能明细(avg / max / rows)
设置binlog:
– 设置表属性开启Binlog功能
call set_table_property(‘t.t’, ‘binlog.level’, ‘replica’);
– 设置表属性,配置Binlog TTL时间,单位秒
call set_table_property(‘t.t’, ‘binlog.ttl’, ‘259200’);
查看表结构
select hg_dump_script(‘t’)
查日志
select digest, count(1), avg(cpu_time_ms), sum(cpu_time_ms)
from hologres.hg_query_log where 1 = 1
and query_start > ‘2024-10-26 08:00:00+08’
and query_start < ‘2024-10-26 10:00:00+08’
and cpu_time_ms > 0
group by digest
order by sum(cpu_time_ms) desc limit 100;
select
query,
count(*) as total_cnt
from hologres.hg_query_log
where
query_start BETWEEN ‘2024-12-13 17:30:00+08’ and ‘2024-12-13 18:00:00+08’
group by 1
order by 2 desc
limit 100
查binlog
SELECT hg_binlog_lsn,hg_binlog_event_type,hg_binlog_timestamp_us,* FROM test_message_src;
查看开启binlog的表的list
SELECT
*
FROM
hologres.hg_table_properties
WHERE
property_key = ‘binlog.level’
AND property_value = ‘replica’;
SELECT *
FROM
warehouse_bi_car.dws_sale_clue_final_rt WHERE clue_id = 12746690;
SELECT
hg_binlog_lsn,
case when hg_binlog_event_type= 2 then ‘-D’
when hg_binlog_event_type= 3 then ‘-U’
when hg_binlog_event_type= 5 then ‘+I’
when hg_binlog_event_type= 7 then ‘+U’
else ‘null’ end log_type,
hg_binlog_timestamp_us,
to_timestamp(hg_binlog_timestamp_us/1000000) as hg_binlog_time,
*
FROM
table WHERE
ORDER BY
hg_binlog_timestamp_us desc, hg_binlog_lsn desc
筛选已过期的binlog
WITH log AS (
SELECT
MAX( hg_binlog_lsn ) hg_binlog_lsn,
$update_keys
FROM $table_name
$filter_sql
GROUP BY $update_keys
),
res AS (
SELECT
$update_keys
FROM $table_name
$filter_sql
GROUP BYu p d a t e k e y s ) , l m t a s ( S E L E C T r . update_keys ), lmt as( SELECT r.updatekeys),lmtas(SELECTr.relation_key::text as uk,
hg_binlog_lsn
FROM res r
LEFT JOIN log l ON r.r e l a t i o n k e y = l . relation_key = l.re