Greenplum 調優--查看子節點SQL運行狀態

摘自《Greenplum企業應用實戰》python

重點:sql

使用gp_dist_random函數,將查詢下發到每一個Segementdom

建立查看子節點SQL運行狀態視圖socket

1)建立v_active_sql視圖方便查看SQL函數

create view v_active_sql as blog

select pg_stat_activity.procpid,pg_stat_activity.sess_id,ip

pg_stat_activity.usename,pg_stat_activity.waiting as w ,get

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

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

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

相關文章
相關標籤/搜索