TeleDB-X是天翼云基于PostgreSQL研发的企业级分布式数据库管理系统。支持完整事务能力的同时兼具写扩展性,完整兼容 PostgreSQL语法和常用Oracle语法。
TeleDB-X数据库支持shard分片表和复制表(全局表),可以通过TeleDB-X自带的psql客户端执行 \d+ 表名,查看表的类型和分布键字段,但有一批表都需要查询时,这个方法效率太低。
系统表pg_catalog.pgxc_class的字段pclocatortype记录了表的类型,其中 R表示是复制表,S表示分片表,可以用以下SQL批量查询。
SELECT n.nspname as schema_name,
c1.relname as table_name,
CASE pclocatortype WHEN 'R' THEN 'REPLICATION' WHEN 'S' THEN 'SHARD' else pclocatortype END as shard_type,
attname as shardkey,
pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c1.oid)) as size,
string_agg(pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)||';','
') as primary_or_uniqe
FROM pg_catalog.pgxc_class c
join pg_catalog.pg_class c1 on c.pcrelid=c1.oid
left join pg_catalog.pg_namespace n on n.oid=c1.relnamespace
left join pg_catalog.pg_attribute a on a.attrelid = c.pcrelid and a.attnum = c.pcattnum
left join pg_catalog.pg_index i on c1.oid=i.indrelid
left join pg_catalog.pg_constraint con ON (con.conrelid = i.indrelid AND con.conindid = i.indexrelid AND con.contype IN ('p','u'))
WHERE n.nspname in ('public')
group by 1,2,3,4,c1.oid
order by pg_catalog.pg_table_size(c1.oid) desc;
分布键/复制表、主键/唯一约束、表大小,根据需要,更改where条件。