李士朝
发布于

如何查看分布键,并将数据导入到临时表

查看分布键

select 
t4.nspname,
t1.relname,
t3.attname,
t2.bucketnum
from pg_class t1
inner join pg_catalog.pg_namespace t4
on t4.oid=t1.relnamespace
left join gp_distribution_policy t2
   on t2.localoid = t1.oid
left join pg_attribute t3
   on t1.oid = t3.attrelid
  and t2.localoid = t3.attrelid
  and t3.attnum = t2.attrnums[1]
where t3.attname is not null
  and t4.nspname not in ('hawq_toolkit','information_schema','pg_aoseg','pg_bitmapindex','pg_catalog','pg_toast')
;

将查询出来的信息加载到表中,由于 5.0 版本不支持系统表和普通表做关联和插入操作,采用以下命令实现

psql -d postgres -A -t -c "sql" | psql -d postgres -c "copy xxx from STDIN delimiter '|';"
评论
    test