1. 下午查看一下greenplum的对应关系, oid与文件属性
1. oid是一种特殊的数据类型, 在PG/GP中,oid都是自增的。
2. 每一个表空间,表,索引, 数据文件,函数,约束都对应一个唯一标识的oid, oid是全局递增的。
3. 1259是pg_class对应的oid,每一个postgresql都是如此。
select oid, relname from pg_class where oid = 'pg_class'::regclass;
select attrelid::regclass, attname, b.relname
from pg_attribute a, pg_class b
where a.attrelid = b.oid
and b.relnamespace = 11
and atttypid = 26
and b.relstorage='h'
and attname = 'oid'
and b.relname not like '%index';
4. 查询schema信息。
select * from pg_namespace where nspowner > 10
5. 节点的配置信息和文件空间信息, 如下2个表在pg_global表空间下,全局共用。
gp_segment_configuration;
pg_filespace_entry
select * from gp_segment_configuration;
select * from pg_filespace_entry order by fsedbid
6. 创建视图:
create view public.v_gp_id
as
select 'Greenplum'::name as gpname
, current_setting('gp_num_contents_in_cluster') as numsegments
, current_setting('gp_dbid')
, current_setting('gp_contentid') as content;
create or replace function public.hostname()
return text
as $$
import socket
return socket.gethostname()
$$ language plpythonu;
7. 在主节点上,想获取子节点的信息, 需要使用gp_dist_random.
select gp_segment_id, count(1) from gp_dist_random('pg_class') group by 1 order by 1;
select hostname() from gp_dist_random('gp_id');
8. 查看fi_user是否有对order_share的select权限
select has_table_privilege('fi_user','dw_stage.order_share','select');
9. 同一个表在pg_attribute表的字段数会比使用\d dw_stage.order_send时得到的要多,因为有一些隐藏字段在使用\d命令时,是不显示的。
--查询表的oid
select oid, relacl, *
from pg_class
where relname = 'orders_send';
--查询表的字段信息数
select *
from pg_attribute
where attrelid in (1246871, 1257272)
order by attrelid
10. 表的分布键策略
select * from gp_distribution_policy;
--下表localoid中的oid从pg_class表中得到
select * from gp_distribution_policy
where localoid = 1246871
或者使用如下方法:
select * from gp_distribution_policy where localoid = 'orders_send'::regclass;
11.分区表的约束,不要主表上创建策略,除非这个策略适用于所有子表。
12.查询分区表的分区信息:
--从pg_class中查询到oid信息
select oid, relacl, *
from pg_class
where relname = 'fi_gp_sale_rtn_prod_basic';
--查询出pg_partition表中的oid信息;
select oid, * from pg_partition
where parrelid = 3069750
--根据pg_partition表中的oid,到pg_partition_rule表中查询对应的分区信息。
select *
from pg_partition_rule
where paroid = 3073374