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 <> ''::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 <> '';

 

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

你可能感兴趣的:(Greenplum 调优--查看子节点SQL运行状态)