PostgreSQL 查看数据库,索引,表,表空间大小_pg_column_size
idx_test 和idx_join_date_test 两个索引大小加起来差不多等于上面pg_indexes_size() 查询出来的索引大小。增加foo用户对该数据库某个模式的权限,权限有all,create,usage。增加foo用户对该数据库public模式下所有表的select权限。增加foo用户对该数据库某个表的权限,权限可以一个或多个。删除foo用户对该数据库test表的select
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
david=# select pg\_size\_pretty(pg\_database\_size('david'));
pg_size_pretty
----------------
MB
(1 row)
索引
创建索引
CREATE INDEX idx_key_eng_search_status
ON base.keyword_engine
USING btree
(search_status);
3.4 查看单索引大小
david=# select pg\_relation\_size('idx\_test');
pg_relation_size
------------------
(1 row)
david=# select pg\_size\_pretty(pg\_relation\_size('idx\_test'));
pg_size_pretty
----------------
MB
(1 row)
david=# select pg\_size\_pretty(pg\_relation\_size('idx\_join\_date\_test'));
pg_size_pretty
----------------
MB
(1 row)
3.5 查看指定表中所有索引大小
david=# select pg\_indexes\_size('test');
pg_indexes_size
-----------------
(1 row)
david=# select pg\_size\_pretty(pg\_indexes\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
idx_test 和idx_join_date_test 两个索引大小加起来差不多等于上面pg_indexes_size() 查询出来的索引大小。
3.6 查看指定schema 里所有的索引大小,按从大到小的顺序排列。
david=# select \* from pg_namespace;
nspname | nspowner | nspacl
--------------------+----------+-------------------------------------
pg_toast | 10 |
pg_temp_1 | 10 |
pg_toast_temp_1 | 10 |
pg_catalog | 10 | {postgres=UC/postgres,=U/postgres}
information_schema | 10 | {postgres=UC/postgres,=U/postgres}
public | 10 | {postgres=UC/postgres,=UC/postgres}
(6 rows)
david=# select indexrelname, pg\_size\_pretty(pg\_relation\_size(relid)) from pg_stat_user_indexes where schemaname='public' order by pg\_relation\_size(relid) desc;
indexrelname | pg_size_pretty
-------------------------------+----------------
idx_join_date_test | 91 MB
idx_test | 91 MB
testtable_idx | 1424 kB
city_pkey | 256 kB
city11 | 256 kB
countrylanguage_pkey | 56 kB
sale_pkey | 8192 bytes
track_pkey | 8192 bytes
tbl_partition_201211_joindate | 8192 bytes
tbl_partition_201212_joindate | 8192 bytes
tbl_partition_201301_joindate | 8192 bytes
tbl_partition_201302_joindate | 8192 bytes
tbl_partition_201303_joindate | 8192 bytes
customer_pkey | 8192 bytes
album_pkey | 8192 bytes
item_pkey | 8192 bytes
tbl_partition_201304_joindate | 8192 bytes
tbl_partition_201307_joindate | 8192 bytes
tbl_partition_201305_joindate | 0 bytes
tbl_partition_201306_joindate | 0 bytes
(20 rows)
查看索引大小
select indexrelname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_indexes where schemaname='public' order by pg_relation_size(relid) desc;
3.7 查看指定表大小
david=# select pg\_relation\_size('test');
pg_relation_size
------------------
(1 row)
david=# select pg\_size\_pretty(pg\_relation\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
使用pg_table_size() 函数查看
david=# select pg\_table\_size('test');
pg_table_size
---------------
(1 row)
david=# select pg\_size\_pretty(pg\_table\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
3.8 查看指定表的总大小
david=# select pg\_total\_relation\_size('test');
pg_total_relation_size
------------------------
(1 row)
david=# select pg\_size\_pretty(pg\_total\_relation\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
3.9 查看指定schema 里所有的表大小,按从大到小的顺序排列。
david=# select \* from pg_namespace;
nspname | nspowner | nspacl
--------------------+----------+-------------------------------------
pg_toast | 10 |
pg_temp_1 | 10 |
pg_toast_temp_1 | 10 |
pg_catalog | 10 | {postgres=UC/postgres,=U/postgres}
information_schema | 10 | {postgres=UC/postgres,=U/postgres}
public | 10 | {postgres=UC/postgres,=UC/postgres}
(6 rows)
david=# select indexrelname, pg\_size\_pretty(pg\_relation\_size(relid)) from pg_stat_user_indexes where schemaname='public' order by pg\_relation\_size(relid) desc;
indexrelname | pg_size_pretty
-------------------------------+----------------
idx_join_date_test | 91 MB
idx_test | 91 MB
testtable_idx | 1424 kB
city_pkey | 256 kB
city11 | 256 kB
countrylanguage_pkey | 56 kB
sale_pkey | 8192 bytes
track_pkey | 8192 bytes
tbl_partition_201211_joindate | 8192 bytes
tbl_partition_201212_joindate | 8192 bytes
tbl_partition_201301_joindate | 8192 bytes
tbl_partition_201302_joindate | 8192 bytes
tbl_partition_201303_joindate | 8192 bytes
customer_pkey | 8192 bytes
album_pkey | 8192 bytes
item_pkey | 8192 bytes
tbl_partition_201304_joindate | 8192 bytes
tbl_partition_201307_joindate | 8192 bytes
tbl_partition_201305_joindate | 0 bytes
tbl_partition_201306_joindate | 0 bytes
(20 rows)
3.7 查看指定表大小
david=# select pg\_relation\_size('test');
pg_relation_size
------------------
(1 row)
david=# select pg\_size\_pretty(pg\_relation\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
使用pg_table_size() 函数查看
david=# select pg\_table\_size('test');
pg_table_size
---------------
(1 row)
david=# select pg\_size\_pretty(pg\_table\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
3.8 查看指定表的总大小
david=# select pg\_total\_relation\_size('test');
pg_total_relation_size
------------------------
(1 row)
david=# select pg\_size\_pretty(pg\_total\_relation\_size('test'));
pg_size_pretty
----------------
MB
(1 row)
3.9 查看指定schema 里所有的表大小,按从大到小的顺序排列。
david=# select relname, pg\_size\_pretty(pg\_relation\_size(relid)) from pg_stat_user_tables where schemaname='public' order by pg\_relation\_size(relid) desc;
relname | pg_size_pretty
-------------------------------+----------------
test | 91 MB
testtable | 1424 kB
city | 256 kB
countrylanguage | 56 kB
country | 40 kB
testcount | 8192 bytes
tbl_partition_201302 | 8192 bytes
tbl_partition_201303 | 8192 bytes
person | 8192 bytes
customer | 8192 bytes
american_state | 8192 bytes
tbl_david | 8192 bytes
emp | 8192 bytes
tbl_partition_201212 | 8192 bytes
tbl_partition_201304 | 8192 bytes
tbl_partition_error_join_date | 8192 bytes
tbl_partition_201211 | 8192 bytes
album | 8192 bytes
tbl_partition_201307 | 8192 bytes
tbl_xulie | 8192 bytes
tbl_partition_201301 | 8192 bytes
sale | 8192 bytes
item | 8192 bytes
track | 8192 bytes
tbl_partition_201306 | 0 bytes
tbl_partition | 0 bytes
tbl_partition_201305 | 0 bytes
person2 | 0 bytes
(28 rows)
3.10 查看表空间大小
david=# select spcname from pg_tablespace;
spcname
------------
pg_default
pg_global
(2 rows)
david=# select pg\_tablespace\_size('pg\_default');
pg_tablespace_size
--------------------
(1 row)
david=# select pg\_size\_pretty(pg\_tablespace\_size('pg\_default'));
pg_size_pretty
----------------
GB
(1 row)
另一种查看方法:
david=# select pg\_tablespace\_size('pg\_default')/1024/1024 as "SIZE M";
SIZE M
--------
(1 row)
david=# select pg\_tablespace\_size('pg\_default')/1024/1024/1024 as "SIZE G";
SIZE G
--------
(1 row)
四、模式授权
增加
增加foo用户对该数据库public模式下所有表的select权限
test=# grant select on all tables in schema public to foo ;
增加foo用户对该数据库public模式下所有函数的执行权限
test=# grant execute on all functions in schema public to foo ;
增加foo用户对该数据库某个表的权限,权限可以一个或多个
test=# grant select,insert,update,delete on public.test to foo ;
增加foo用户对该数据库某个模式的权限,权限有all,create,usage 。
test=# grant all on schema public to foo ;
删除
删除foo用户对该数据库test表的select权限
![img](https://img-blog.csdnimg.cn/img_convert/04fbe955d620762be44f489609f45228.png)
![img](https://img-blog.csdnimg.cn/img_convert/a688d911b5945dc2aac4c53b15e8f26d.png)
![img](https://img-blog.csdnimg.cn/img_convert/cc7106a5893dee8c8dfc30bdeaead5c4.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)**
schema public to foo ;
删除
删除foo用户对该数据库test表的select权限
[外链图片转存中...(img-4X11fEDM-1715815065547)]
[外链图片转存中...(img-OjOedOgo-1715815065548)]
[外链图片转存中...(img-6BwULDvN-1715815065548)]
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[需要这份系统化的资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618631832)**
更多推荐
所有评论(0)