首页 数据库 mysql教程 GreenPlum DBA常用SQL

GreenPlum DBA常用SQL

Jun 07, 2016 pm 02:53 PM
dba greenplum sql 常用

GreenPlum DBA常用SQL 查看对象大小(表、索引、数据库等) select pg_size_pretty(pg_relation_size($schema.$table)); 查看用户(非系统)表和索引 select * from pg_stat_user_tables; seect * from pg_stat_user_indexes; www.2cto.com 查看表分区 select b.

GreenPlum DBA常用SQL

 

查看对象大小(表、索引、数据库等)

select pg_size_pretty(pg_relation_size(’$schema.$table’));

 

查看用户(非系统)表和索引

select * from pg_stat_user_tables;

 

seect * from pg_stat_user_indexes;

  www.2cto.com  

查看表分区

select b.nspname||’.'||a.relname as tablename, d.parname as partname

from pg_class a, pg_namespace b, pg_partition c, pg_partition_rule d

where a.relnamespace = b.oid

and b.nspname = ‘$schema’

and a.relname = ‘$table’

and a.oid = c.parrelid

and c.oid = d.paroid

order by parname;

 

查看Distributed key

select  b.attname

from pg_class a, pg_attribute b, pg_type c, gp_distribution_policy  d, pg_namespace e

where d.localoid = a.oid

and a.relnamespace = e.oid

and e.nspname = ‘$schema’

and a.relname=’$table’

and a.oid = b.attrelid

and b.atttypid = c.oid

and b.attnum > 0

and b.attnum = any(d.attrnums)

order by attnum;

  www.2cto.com  

查看当前存活的查询

select procpid as pid, sess_id as session, usename as user, current_query as query, waiting,

date_trunc(’second’, query_start) as start_time, client_addr as useraddr

from pg_stat_activity

where datname =’$PGDATABASE’

and current_query not like ‘%from pg_stat_activity%where datname =%’

order by start_time;

 

表上被用作外键的字段名

select f.conname, pg_get_constraintdef(f.oid), t2.relname

from pg_class t, pg_class t2, pg_constraint f

where f.confrelid = t.oid

and f.conrelid = t2.oid

and f.contype = ‘f’

and t.relname = ‘$table’;

  www.2cto.com  

1. 查看表使用空间

 SELECT      *  

FROM         PUBLIC.dba_segments  

WHERE         owner   LIKE   'owber_name'

 AND            table_name   LIKE   '%table_name%'

 ORDER   BY   table_name;

 

2. GP中查看分区:

 select   partitionname,partitionboundary   from   pg_partitions   where   tablename='table_name';  

select   partitionname,partitionboundary   from   pg_catalog.pg_partitions   where   tablename='table_name';

 

3.  查看正在运行的sql

   select   *   from   pg_stat_activity;

 

4. 修改表的owner语句

 Alter table table_name owner to owner_name;

   www.2cto.com  

5. 增加表分区

 ALTER TABLE table_name   ADD PARTITION P20091001  START (DATE '2009-10-01') INCLUSIVE END (DATE '2009-10-02')  EXCLUSIVE WITH(appendonly=true,compresslevel=5);

 

6. 修改列类型

 ALTER TABLE table_name  ALTER COLUMN a TYPE varchar(2048);

 

7. 修改distributed 列

 alter table table_name  set distributed by(column_1);

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

Hibernate 框架中 HQL 和 SQL 的区别是什么? Hibernate 框架中 HQL 和 SQL 的区别是什么? Apr 17, 2024 pm 02:57 PM

Hibernate 框架中 HQL 和 SQL 的区别是什么?

Oracle SQL中除法运算的用法 Oracle SQL中除法运算的用法 Mar 10, 2024 pm 03:06 PM

Oracle SQL中除法运算的用法

SQL中的identity属性是什么意思? SQL中的identity属性是什么意思? Feb 19, 2024 am 11:24 AM

SQL中的identity属性是什么意思?

Oracle和DB2的SQL语法比较与区别 Oracle和DB2的SQL语法比较与区别 Mar 11, 2024 pm 12:09 PM

Oracle和DB2的SQL语法比较与区别

详解MyBatis动态SQL标签中的Set标签功能 详解MyBatis动态SQL标签中的Set标签功能 Feb 26, 2024 pm 07:48 PM

详解MyBatis动态SQL标签中的Set标签功能

SQL出现5120错误怎么解决 SQL出现5120错误怎么解决 Mar 06, 2024 pm 04:33 PM

SQL出现5120错误怎么解决

如何使用SQL语句在MySQL中进行数据聚合和统计? 如何使用SQL语句在MySQL中进行数据聚合和统计? Dec 17, 2023 am 08:41 AM

如何使用SQL语句在MySQL中进行数据聚合和统计?

MySQL中SQL优化、索引优化、锁机制、主从复制的方法 MySQL中SQL优化、索引优化、锁机制、主从复制的方法 Jun 05, 2023 pm 03:09 PM

MySQL中SQL优化、索引优化、锁机制、主从复制的方法

See all articles