示例表 table t_ex; c1 | c2 ----+---- 2 | B 4 | C 6 | A 2 | C 4 | B 6 | B 2 | A 4 | B 6 | C 2 | C 以下SQL语句有序地返回"c1"列中唯一值: select distinct on(c1) * from abce; 对于c2列,会根据c1的唯一性,从表中找到的第一个值. postgres=# select distinct on(c1) * from abce; c1 | c2 ----+----…
Get the current free disk space in PostgreSQL PostgreSQL获取磁盘空间 from eshizhan Here has a simple way to get free disk space without any extended language, just define a function using pgsql. CREATE OR REPLACE FUNCTION sys_df() RETURNS SETOF text[] LANG…
基于PostgreSQL,总结几条常用的查询操作的优化建议,部分也适用于Oracle等数据库. 1.选择合适的分布键 分布键选择不当会导致重分布.数据分布不均等,而数据分布不均会使SQL集中在一个segment节点的执行,限制了gp整体的速度.查看某表是否分布不均: select gp_segment_id,count(*) from table_name group by gp_segment_id ; 例子如图: 2.使用分区表 按照某字段进行分区,不影响数据在数据节点上的分布,但是,仅在单…