暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

PostgreSQL 学习笔记014 —— PostgreSQL 常用命令(4)

心有阳光 2023-01-09
618

查看表空间

postgres=# \db List of tablespaces Name | Owner | Location ------------+----------+---------- pg_default | postgres | pg_global | postgres | (2 rows) postgres=# select * from pg_tablespace; oid | spcname | spcowner | spcacl | spcoptions ------+------------+----------+--------+------------ 1663 | pg_default | 10 | | 1664 | pg_global | 10 | | (2 rows)

查看数据库中所有表

postgres=# \dt List of relations Schema | Name | Type | Owner --------+-------+-------+---------- public | test1 | table | postgres public | test2 | table | postgres (2 rows)

查询表大小

postgres=# select pg_size_pretty(pg_relation_size('test1')) as size; size --------- 0 bytes (1 row) -- 查询单个表的总大小,包括该表的索引大小 postgres=# select pg_size_pretty(pg_total_relation_size('test1')) as size; size --------- 0 bytes (1 row)

查询所有表大小

postgres=# select relname, pg_size_pretty(pg_relation_size(relid)) as size from pg_stat_user_tables; relname | size ---------+--------- test1 | 0 bytes test2 | 0 bytes (2 rows) -- 查询所有表的总大小,包括其索引大小 postgres=# select relname, pg_size_pretty(pg_total_relation_size(relid)) as size from pg_stat_user_tables; relname | size ---------+--------- test1 | 0 bytes test2 | 0 bytes (2 rows)

切换用户

-- 使用\c - username表示数据库不变,只切换用户 postgres=# \c - user1; You are now connected to database "postgres" as user "user1". -- 以用户username切换到databasename的数据库 postgres=# \c testdb user1; You are now connected to database "testdb" as user "user1".

查看当前数据库名称

postgres=# select current_database(); current_database ------------------ postgres (1 row)
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论