pgsql查看每张表数据量
时间: 2023-10-01 19:05:52 浏览: 90
可以使用以下 SQL 查询语句来查看每张表的数据量:
```
SELECT
relname AS table_name,
pg_size_pretty(pg_total_relation_size(relid)) AS total_size
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
```
该查询语句会返回每张表的名称和数据占用的空间大小,按照数据占用大小降序排序。其中,`pg_catalog.pg_statio_user_tables` 是 PostgreSQL 中的一个系统表,用于存储用户表的统计信息。`pg_size_pretty` 函数用于将字节大小转换为易读的格式。
相关问题
pgsql清空一个表数据
以下是两种清空pgSql表数据的方法:
1. 使用truncate table语句清空表数据:
```sql
truncate table 表名;
```
例如,清空表t_table_a和t_table_b的数据:
```sql
truncate table t_table_a;
truncate table t_table_b;
```
2. 使用DELETE语句清空表数据:
```sql
DELETE FROM 表名;
```
例如,清空表t_table_a和t_table_b的数据:
```sql
DELETE FROM t_table_a;
DELETE FROM t_table_b;
```
pgsql 统计每分钟的数据
你可以使用以下 SQL 查询来统计每分钟的数据:
```sql
SELECT date_trunc('minute', timestamp_column) AS minute, COUNT(*) AS count
FROM your_table
GROUP BY minute
ORDER BY minute;
```
请将 `timestamp_column` 替换为你数据表中的时间戳列名,将 `your_table` 替换为你的数据表名。
这个查询使用了 `date_trunc` 函数来将时间戳精确到分钟级别,并使用 `GROUP BY` 语句按分钟进行分组。然后,使用 `COUNT(*)` 函数统计每分钟的数据量,并按时间顺序进行排序。
这样,你就能获得每分钟的数据量统计结果。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)