1. --查看数据库
  2. select * from pg_database;
  3. --查看表空间
  4. select * from pg_tablespace;
  5. --查看语言
  6. select * from pg_language;
  7. --查看角色用户
  8. select * from pg_user;
  9. select * from pg_shadow;
  10. select * from pg_roles;
  11. --查看会话进程
  12. select * from pg_stat_activity;
  13. --查看表
  14. SELECT * FROM pg_tables where schemaname = 'public';
  15. --查看表字段
  16. select * from information_schema.columns where table_schema = 'public' and table_name = 'pf_vip_org';
  17. --查看视图
  18. select * from pg_views where schemaname = 'public';
  19. select * from information_schema.views where table_schema = 'public';
  20. --查看触发器
  21. select * from information_schema.triggers;
  22. --查看序列
  23. select * from information_schema.sequences where sequence_schema = 'public';
  24. --查看约束
  25. select * from pg_constraint where contype = 'p'
  26. --u unique,p primary,f foreign,c check,t trigger,x exclusion
  27. select a.relname as table_name,b.conname as constraint_name,b.contype as constraint_type from pg_class a,pg_constraint b where a.oid = b.conrelid and a.relname = 'cc';
  28. --查看索引
  29. select * from pg_index ;
  30. --查看表上存在哪些索引以及大小
  31. select relname,n.amname as index_type from pg_class m,pg_am n where m.relam = n.oid and m.oid in (
  32. select b.indexrelid from pg_class a,pg_index b where a.oid = b.indrelid and a.relname = 'cc');
  33. SELECT c.relname,c2.relname, c2.relpages*8 as size_kb
  34. FROM pg_class c, pg_class c2, pg_index i
  35. WHERE c.relname = 'cc' AND
  36. c.oid = i.indrelid AND
  37. c2.oid = i.indexrelid
  38. ORDER BY c2.relname;
  39. --查看索引定义
  40. select b.indexrelid from pg_class a,pg_index b where a.oid = b.indrelid and a.relname = 'cc';
  41. select pg_get_indexdef(b.indexrelid);
  42. --查看过程函数定义
  43. select oid,* from pg_proc where proname = 'insert_platform_action_exist'; --oid = 24610
  44. select * from pg_get_functiondef(24610);
  45. --查看表大小(不含索引等信息)
  46. select pg_relation_size('cc');                         --368640 byte
  47. select pg_size_pretty(pg_relation_size('cc'))   --360 kB
  48. --查看DB大小
  49. select pg_size_pretty(pg_database_size('smiletao'));   --12M
  50. --查看服务器DB运行状态
  51. [postgres@eyar ~]$ pg_ctl status -D $PGDATA
  52. pg_ctl: server is running (PID: 2373)
  53. /home/postgres/bin/postgres "-D" "/database/pgdata"
  54. --查看每个DB的使用情况(读,写,缓存,更新,事务等)
  55. select * from pg_stat_database
  56. --查看索引的使用情况
  57. select * from pg_stat_user_indexes;
  58. --查看表所对应的数据文件路径与大小
  59. SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'empsalary';
  60. --查看索引与相关字段及大小
  61. SELECT n.nspname AS schema_name,
  62. r.rolname as table_owner,
  63. bc.relname AS table_name,
  64. ic.relname AS index_name,
  65. a.attname  AS column_name,
  66. bc.relpages*8 as index_size_kb
  67. FROM pg_namespace n,
  68. pg_class bc,             -- base class
  69. pg_class ic,             -- index class
  70. pg_index i,
  71. pg_attribute a,           -- att in base
  72. pg_roles r
  73. WHERE bc.relnamespace = n.oid
  74. and i.indrelid = bc.oid
  75. and i.indexrelid = ic.oid
  76. and bc.relowner = r.oid
  77. and i.indkey[0] = a.attnum
  78. and i.indnatts = 1
  79. and a.attrelid = bc.oid
  80. and n.nspname = 'public'
  81. and bc.relname = 'cc'
  82. ORDER BY schema_name, table_name, index_name, attname;
  83. --查看PG锁
  84. select * from pg_locks;
  85. 备注:relpages*8 是实际所占磁盘大小
  86. --查看表空间大小
  87. select pg_tablespace_size('pg_default');
  88. --查看序列与表的对应关系
  89. WITH fq_objects AS (SELECT c.oid,c.relname AS fqname ,
  90. c.relkind, c.relname AS relation
  91. FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace ),
  92. sequences AS (SELECT oid,fqname FROM fq_objects WHERE relkind = 'S'),
  93. tables    AS (SELECT oid, fqname FROM fq_objects WHERE relkind = 'r' )
  94. SELECT
  95. s.fqname AS sequence,
  96. '->' as depends,
  97. t.fqname AS table
  98. FROM
  99. pg_depend d JOIN sequences s ON s.oid = d.objid
  100. JOIN tables t ON t.oid = d.refobjid
  101. WHERE
  102. d.deptype = 'a' and t.fqname = 'cc';

postgresql常用SQL的更多相关文章

  1. 常用SQL操作(MySQL或PostgreSQL)与相关数据库概念

    本文对常用数据库操作及相关基本概念进行总结:MySQL和PostgreSQL对SQL的支持有所不同,大部分SQL操作还是一样的. 选择要用的数据库(MySQL):use database_name; ...

  2. Mysql 常用 SQL 语句集锦

    Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...

  3. oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数

        花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...

  4. 常用SQL[ORACLE]

        1.常用系统函数 2.常用sql语句 3.一些定义和关键字 4.需要注意点   1.常用系统函数 ↑ --decode decode(column,if_value,value,elseif_ ...

  5. Oracle常用SQL查询(2)

    三.查看数据库的SQL 1 .查看表空间的名称及大小 select  t.tablespace_name,  round ( sum (bytes / ( 1024 * 1024 )), 0 ) ts ...

  6. Oracle常用SQL查询

    一.ORACLE的启动和关闭 1.在单机环境下要想启动或关闭oracle系统必须首先切换到oracle用户,如下: su - oracle a.启动Oracle系统 oracle>svrmgrl ...

  7. Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)

    Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...

  8. 50个常用SQL语句

    50个常用SQL语句 Student(S#,Sname,Sage,Ssex) 学生表  S#学号,主键 Course(C#,Cname,T#) 课程表          C#课程号,主键 SC(S#, ...

  9. 测试常用SQL注入语句大全

    转载自Cracer,标题:<渗透常用SQL注入语句大全>,链接http://www.xxxx.com/?p=2226 1.判断有无注入点 整形参数判断 1.直接加' 2.and 1=1 3 ...

随机推荐

  1. Row Border in DataGrid 表格边框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. homework-03

    1.分工准备 这次的工作是结对编程,在第二次作业中我是使用python完成的作业,而小明是使用C完成的作业.因为打算使用动态链接库的方式将第二次的代码嵌入到本次的作业中,而python生成动态链接库不 ...

  3. thymeleaf中的th:each用法

    一.th:eath迭代集合用法: <table> <thead> <tr> <th>序号</th> <th>用户名</th ...

  4. BestCoder Round #70 Jam's math problem(hdu 5615)

    Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...

  5. [C语言 - 6] static & extern

    A. extern函数 一个c文件生成一个obj文件   外部函数:允许其他文件访问.调用的函数(默认函数为外部函数),不允许存在同名的外部函数   my.c //define a extern fu ...

  6. ADUM1201在隔离RS232中的应用 【瓦特芯收藏】

    ADUM1201在隔离RS232中的应用 引言: RS-232是PC机与工业通信中应用最广泛的一种串行接口.RS-232接口最初是由美国EIA(电子工业联合会)规定的用于计算机与终端设备之间通讯的一种 ...

  7. uLua学习笔记(三):Unity3D和Lua之间的相互调用

    这篇笔记主要集中学习一下uLua和Unity3D之间相互调用的方法,我们导入了uLua之后,现在会弹出一个类似学习屏幕的东西,如下: 先赞一个! Unity3D调用Lua Unity3D调用Lua的方 ...

  8. 初学Android 二 创建项目以及目录结构

    命令行创建 android create project Usage: android [global options] create project [action options] Global ...

  9. 剑指OFFER之二进制中1的个数(九度OJ1513)

    题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样例.对于每个输入文件,第一行输入一个整数T,代表测试样例的数量.对于每个测试样例输入为一个整 ...

  10. PC/UVa 题号: 110101/100 The 3n+1 problem (3n+1 问题)

     The 3n + 1 problem  Background Problems in Computer Science are often classified as belonging to a ...