Greenplum 调优--查看子节点SQL运行状态

摘自《Greenplum企业应用实战》

重点:

使用gp_dist_random函数,将查询下发到每个Segement

创建查看子节点SQL运行状态视图

1)创建v_active_sql视图方便查看SQL

create view v_active_sql as 

select pg_stat_activity.procpid,pg_stat_activity.sess_id,

pg_stat_activity.usename,pg_stat_activity.waiting as w ,

to_char(pg_stat_activity.query_start,'yyyymmdd hh24:mi:ss'::text) as query_start,

to_char(now()-pg_stat_activity.query_start,'hh24:mi'::text) as exec,

pg_stat_activity.current_query

from pg_stat_activity

where pg_stat_activity.current_query <> '<IDLE>'::text

order by pg_stat_activity.datname,

to_char(pg_stat_activity.query_start,'yyyymmdd hh24:mi:ss'::text);

2)创建获取IP的函数

create or replace function public.hostip()

return text

as $$

import socket

return socket.gethostbyname(socket.gethostname())

$$ language plpythonu;

3)创建all_seg_sql函数

create view public.all_seg_sql

as 

select hostip(),

current_setting(replace('port'||current_query,current_query,'')) as port,

current_setting(replace('gp_contentid'||current_query,current_query,'')) as content,*

from gp_dist_random('v_active_sql')

where current_query <> '<IDLE>';

 

转载于:https://www.cnblogs.com/xibuhaohao/p/11133467.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值