postgresql常用SQL
- --查看数据库
- select * from pg_database;
- --查看表空间
- select * from pg_tablespace;
- --查看语言
- select * from pg_language;
- --查看角色用户
- select * from pg_user;
- select * from pg_shadow;
- select * from pg_roles;
- --查看会话进程
- select * from pg_stat_activity;
- --查看表
- SELECT * FROM pg_tables where schemaname = 'public';
- --查看表字段
- select * from information_schema.columns where table_schema = 'public' and table_name = 'pf_vip_org';
- --查看视图
- select * from pg_views where schemaname = 'public';
- select * from information_schema.views where table_schema = 'public';
- --查看触发器
- select * from information_schema.triggers;
- --查看序列
- select * from information_schema.sequences where sequence_schema = 'public';
- --查看约束
- select * from pg_constraint where contype = 'p'
- --u unique,p primary,f foreign,c check,t trigger,x exclusion
- 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';
- --查看索引
- select * from pg_index ;
- --查看表上存在哪些索引以及大小
- select relname,n.amname as index_type from pg_class m,pg_am n where m.relam = n.oid and m.oid in (
- select b.indexrelid from pg_class a,pg_index b where a.oid = b.indrelid and a.relname = 'cc');
- SELECT c.relname,c2.relname, c2.relpages*8 as size_kb
- FROM pg_class c, pg_class c2, pg_index i
- WHERE c.relname = 'cc' AND
- c.oid = i.indrelid AND
- c2.oid = i.indexrelid
- ORDER BY c2.relname;
- --查看索引定义
- select b.indexrelid from pg_class a,pg_index b where a.oid = b.indrelid and a.relname = 'cc';
- select pg_get_indexdef(b.indexrelid);
- --查看过程函数定义
- select oid,* from pg_proc where proname = 'insert_platform_action_exist'; --oid = 24610
- select * from pg_get_functiondef(24610);
- --查看表大小(不含索引等信息)
- select pg_relation_size('cc'); --368640 byte
- select pg_size_pretty(pg_relation_size('cc')) --360 kB
- --查看DB大小
- select pg_size_pretty(pg_database_size('smiletao')); --12M
- --查看服务器DB运行状态
- [postgres@eyar ~]$ pg_ctl status -D $PGDATA
- pg_ctl: server is running (PID: 2373)
- /home/postgres/bin/postgres "-D" "/database/pgdata"
- --查看每个DB的使用情况(读,写,缓存,更新,事务等)
- select * from pg_stat_database
- --查看索引的使用情况
- select * from pg_stat_user_indexes;
- --查看表所对应的数据文件路径与大小
- SELECT pg_relation_filepath(oid), relpages FROM pg_class WHERE relname = 'empsalary';
- --查看索引与相关字段及大小
- SELECT n.nspname AS schema_name,
- r.rolname as table_owner,
- bc.relname AS table_name,
- ic.relname AS index_name,
- a.attname AS column_name,
- bc.relpages*8 as index_size_kb
- FROM pg_namespace n,
- pg_class bc, -- base class
- pg_class ic, -- index class
- pg_index i,
- pg_attribute a, -- att in base
- pg_roles r
- WHERE bc.relnamespace = n.oid
- and i.indrelid = bc.oid
- and i.indexrelid = ic.oid
- and bc.relowner = r.oid
- and i.indkey[0] = a.attnum
- and i.indnatts = 1
- and a.attrelid = bc.oid
- and n.nspname = 'public'
- and bc.relname = 'cc'
- ORDER BY schema_name, table_name, index_name, attname;
- --查看PG锁
- select * from pg_locks;
- 备注:relpages*8 是实际所占磁盘大小
- --查看表空间大小
- select pg_tablespace_size('pg_default');
- --查看序列与表的对应关系
- WITH fq_objects AS (SELECT c.oid,c.relname AS fqname ,
- c.relkind, c.relname AS relation
- FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace ),
- sequences AS (SELECT oid,fqname FROM fq_objects WHERE relkind = 'S'),
- tables AS (SELECT oid, fqname FROM fq_objects WHERE relkind = 'r' )
- SELECT
- s.fqname AS sequence,
- '->' as depends,
- t.fqname AS table
- FROM
- pg_depend d JOIN sequences s ON s.oid = d.objid
- JOIN tables t ON t.oid = d.refobjid
- WHERE
- d.deptype = 'a' and t.fqname = 'cc';
postgresql常用SQL的更多相关文章
- 常用SQL操作(MySQL或PostgreSQL)与相关数据库概念
本文对常用数据库操作及相关基本概念进行总结:MySQL和PostgreSQL对SQL的支持有所不同,大部分SQL操作还是一样的. 选择要用的数据库(MySQL):use database_name; ...
- Mysql 常用 SQL 语句集锦
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数
花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...
- 常用SQL[ORACLE]
1.常用系统函数 2.常用sql语句 3.一些定义和关键字 4.需要注意点 1.常用系统函数 ↑ --decode decode(column,if_value,value,elseif_ ...
- Oracle常用SQL查询(2)
三.查看数据库的SQL 1 .查看表空间的名称及大小 select t.tablespace_name, round ( sum (bytes / ( 1024 * 1024 )), 0 ) ts ...
- Oracle常用SQL查询
一.ORACLE的启动和关闭 1.在单机环境下要想启动或关闭oracle系统必须首先切换到oracle用户,如下: su - oracle a.启动Oracle系统 oracle>svrmgrl ...
- Mysql 常用 SQL 语句集锦 转载(https://gold.xitu.io/post/584e7b298d6d81005456eb53)
Mysql 常用 SQL 语句集锦 基础篇 //查询时间,友好提示 $sql = "select date_format(create_time, '%Y-%m-%d') as day fr ...
- 50个常用SQL语句
50个常用SQL语句 Student(S#,Sname,Sage,Ssex) 学生表 S#学号,主键 Course(C#,Cname,T#) 课程表 C#课程号,主键 SC(S#, ...
- 测试常用SQL注入语句大全
转载自Cracer,标题:<渗透常用SQL注入语句大全>,链接http://www.xxxx.com/?p=2226 1.判断有无注入点 整形参数判断 1.直接加' 2.and 1=1 3 ...
随机推荐
- wine的中文字体显示
从1.1.4开始wine的界面就已经支持中文了,但是对于软件中的中文支持并不太好,主要原因.还是字体...Let's go 首先,copy一下字体:把simsun.ttc (即宋体)复制到 ~/.wi ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- POJ1062昂贵的聘礼(dijkstra)
昂贵的聘礼 题目大意是说有N个物品,每个物品都有自己的价格,但同时某些物品也可以由其他的(可能不止一个)替代品,这些替代品的价格比较“优惠”,问怎么样选取可以让你的花费最少来购买到物品1 由于有N个物 ...
- HDU 4463 Outlets (最小生成树)
题意:给定n个点坐标,并且两个点已经连接,但是其他的都没有连接,但是要找出一条最短的路走过所有的点,并且路线最短. 析:这个想仔细想想,就是应该是最小生成树,把所有两点都可以连接的当作边,然后按最小生 ...
- CSS构造超链接
超链接边框 派生超链接 属性选择器超链接 动态超链接 图像翻转超链接 CSS工具提示 1.给链接加上边框 A:link { Color: #f00; Text- ...
- 关于.net中线程原子性的自我总结
首先来张图,一张 cpu的简图,仅从个人理解角度理解画的 大体 解释下这张图 这是 一张 i5的简图i5 大家都知道 是双核四线程,(超线程技术)l1,l2,l3是 1,2,3级缓存. Cpu工作:每 ...
- SAP BW标准模型简介(BW星形模型 BW Star Schema )
标准星型模型是 数据仓库中一种常用的组织信息和数据的多维数据模型.它由中心的一个事实表(Fact Table)和一些围绕它的维度表(Dimensional Table)组成. 事实(Fact)着眼于 ...
- Java模拟登陆新浪微博抓取数据【转载】
package com.shiyimm.crawler.weibo; import java.io.FileNotFoundException; import java.io.FileReader; ...
- Codeforces Round #331 (Div. 2)C. Wilbur and Points 贪心
C. Wilbur and Points Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/ ...
- Spark Core源代码分析: Spark任务运行模型
DAGScheduler 面向stage的调度层,为job生成以stage组成的DAG,提交TaskSet给TaskScheduler运行. 每个Stage内,都是独立的tasks,他们共同运行同一个 ...