postgresql查看数据库、表、表空间
PostgreSQL 是一个免费的对象-关系数据库服务器(ORDBMS),在灵活的BSD许可证下发行。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| postgresql查看数据库、表、表空间(位置大小)、索引的方法 1.数据库 postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=CTc/postgres+ | | | | | =c/postgres test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows) postgres=# select pg_database_size('test'); pg_database_size
43819524 (1 row) postgres=# select pg_database.datname, pg_database_size(pg_database.datname) AS size from pg_database; datname | size
template0 | 7430660 postgres | 224188952 template1 | 7537156 test | 43819524 (4 rows) postgres=# select pg_size_pretty(pg_database_size('test')); pg_size_pretty
42 MB (1 row) 2、表 postgres=# \d List of relations Schema | Name | Type | Owner
osdba | tb11 | table | postgres public | a | table | user1 public | b | table | postgres public | emp | table | postgres public | events | table | postgres public | events_id_seq | sequence | postgres public | mv_events | materialized view | postgres (7 rows) postgres=# \d a Table "public.a" Column | Type | Modifiers
a | integer | Indexes: "a_index" btree (a) postgres=# select pg_relation_size('a'); pg_relation_size
8192 (1 row) postgres=# select pg_size_pretty(pg_relation_size('a')); pg_size_pretty
8192 bytes (1 row) postgres=# select pg_size_pretty(pg_total_relation_size('a')); pg_size_pretty
24 kB (1 row) 3、索引 postgres=# \di List of relations Schema | Name | Type | Owner | Table
public | a_index | index | user1 | a public | events_id | index | postgres | events public | pk_user_info | index | postgres | user_info public | pk_user_session | index | postgres | user_session public | t11_pkey | index | postgres | t11 public | tran_pkey | index | postgres | tran public | zz_pkey | index | postgres | zz (7 rows) postgres=# select pg_size_pretty(pg_relation_size('a_index')); pg_size_pretty
16 kB (1 row) 4、表空间 postgres=# \db List of tablespaces Name | Owner | Location
pg_default | postgres | pg_global | postgres | txt | postgres | /home/postgres/pgsql96/tablespace1 (3 rows) postgres=# select pg_size_pretty(pg_tablespace_size('pg_default')); pg_size_pretty
270 MB (1 row)
|