摘自《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>';