1.查看数据库
#psql -U postgres
//\加上字母l,相当于MysqL的,MysqL> show databases;
postgres-# \l
//查看testuser数据库的大小
postgres-# select pg_database_size('postgres');
//查看所有数据库的大小
select pg_database.datname,pg_database_size(pg_database.datname) AS size from pg_database;
//以KB,MB,GB的方式来查看数据库大小
select pg_size_pretty(pg_database_size('postgres'));
2.查看多表
psql -U testuser -d testdb
//相当于MysqL的,MysqL> show tables;
testuser=> \dt
List of relations
Schema | name | Type | Owner
--------+------+-------+---------
public | test | table | testuser
3.查看单表
//相当于MysqL的,MysqL> desc test;
testuser=> \d test;
table "public.test"
Column | Type | ModifIErs
--------+-----------------------+-----------
ID | integer | not null
name | character varying(32) |
Indexes: "testuser_ID_pk" PRIMARY KEY,btree (ID)
//查看表大小
testuser=> select pg_relation_size('test');
pg_relation_size
------------------
0
(1 row)
//以KB,MB,GB的方式来查看表大小
testuser=> select pg_size_pretty(pg_relation_size('test'));
pg_size_pretty
----------------
0 bytes
(1 row)
//查看表的总大小,包括索引大小
testuser=> select pg_size_pretty(pg_total_relation_size('test'));
pg_size_pretty
----------------
8192 bytes
(1 row)
4.查看索引
//相当于MysqL的,MysqL> show index from test;
testuser=> \di
List of relations
Schema | name | Type | Owner | table
--------+---------------+-------+---------+-------
public | testuser_ID_pk | index | playboy | test
(1 row)
//查看索大小
testuser=> select pg_size_pretty(pg_relation_size('playboy_ID_pk'));
pg_size_pretty
----------------
8192 bytes
(1 row)
5.查看表空间,以及大小
//查看所有表空间
testuser=> select spcname from pg_tablespace;
spcname
------------
pg_default
pg_global
(2 rows)
//查看表空间大小 testuser=> select pg_size_pretty(pg_tablespace_size('pg_default')); pg_size_pretty ---------------- 14 MB (1 row) 总结
以上是内存溢出为你收集整理的postgresql 查看数据库,表,索引,表空间以及大小全部内容,希望文章能够帮你解决postgresql 查看数据库,表,索引,表空间以及大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)