千家信息网

Postgresql有哪些常用命令

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,本篇内容介绍了"Postgresql有哪些常用命令"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!--
千家信息网最后更新 2025年01月21日Postgresql有哪些常用命令

本篇内容介绍了"Postgresql有哪些常用命令"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

--设置模式set search_path to firsoul;--默认只列出当前模式下的表\d--列出常用模式\dn--列出所有模式\dnS--查看表的大小select pg_size_pretty(pg_relation_size('test'));--or\dt+ test--infoSELECT n.nspname as "Schema",  c.relname as "Name",  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'materialized view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' WHEN 'f' THEN 'foreign table' WHEN 'p' THEN 'table' END as "Type",  pg_catalog.pg_get_userbyid(c.relowner) as "Owner",  pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as "Size",  pg_catalog.obj_description(c.oid, 'pg_class') as "Description"FROM pg_catalog.pg_class c     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespaceWHERE c.relkind IN ('r','p','s','')      AND n.nspname !~ '^pg_toast'  AND c.relname OPERATOR(pg_catalog.~) '^(test)$'  AND pg_catalog.pg_table_is_visible(c.oid)ORDER BY 1,2;--查看模式大小,表,索引select schemaname ,round(sum(pg_total_relation_size(schemaname||'.'||tablename))/1024/1024) "Size_MB" from pg_tables where schemaname='public' group by 1;select schemaname ,round(sum(pg_total_relation_size(schemaname||'.'||tablename))/1024/1024) "Size_MB" from pg_tables where schemaname='public' group by 1;select schemaname ,round(sum(pg_total_relation_size(schemaname||'.'||indexname))/1024/1024) "Size_MB" from pg_indexes where schemaname='public' group by 1;--查询数据库大小select datname,pg_size_pretty(pg_database_size(datname)) from pg_database;

"Postgresql有哪些常用命令"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0