How to get the free disk space in PostgreSQL (PostgreSQL获取磁盘空间)

Get the current free disk space in PostgreSQL

PostgreSQL获取磁盘空间

Here has a simple way to get free disk space without any extended language, just define a function using pgsql.

CREATE OR REPLACE FUNCTION sys_df() RETURNS SETOF text[]
LANGUAGE plpgsql $$
BEGIN
    CREATE TEMP TABLE IF NOT EXISTS tmp_sys_df (content text) ON COMMIT DROP;
    COPY tmp_sys_df FROM PROGRAM 'df | tail -n +2';
    RETURN QUERY SELECT regexp_split_to_array(content, '\s+') FROM tmp_sys_df;
END;
$$;

Usage:

select * from sys_df();
                      sys_df
-------------------------------------------------------------------
 {overlay,15148428,6660248,7695656,46%,/}
 {overlay,15148428,6660248,7695656,46%,/}
 {tmpfs,65536,0,65536,0%,/dev}
 {tmpfs,768284,0,768284,0%,/sys/fs/cgroup}
 {/dev/sda2,15148428,6660248,7695656,46%,/etc/resolv.conf}
 {/dev/sda2,15148428,6660248,7695656,46%,/etc/hostname}
 {/dev/sda2,15148428,6660248,7695656,46%,/etc/hosts}
 {shm,65536,8,65528,0%,/dev/shm}
 {/dev/sda2,15148428,6660248,7695656,46%,/var/lib/postgresql/data}
 {tmpfs,65536,0,65536,0%,/proc/kcore}
 {tmpfs,65536,0,65536,0%,/proc/timer_list}
 {tmpfs,65536,0,65536,0%,/proc/sched_debug}
 {tmpfs,768284,0,768284,0%,/sys/firmware}
(13 rows)

Using df $PGDATA | tail -n +2 instead of df | tail -n +2 while you saving all data in same path on disk. In this case, the function only return one row disk usage for $PGDATA path.

NOTE FOR SECURITY

PROGRAM can run any command by shell, it like two-edged sword. it is best to use a fixed command string, or at least avoid passing any user input in it. See detail on document.

PROGRAM可以运行任意的命令,所以最好是用固定字符串命令,尽量避免通过参数传入。

原文地址:https://www.cnblogs.com/eshizhan/p/11444001.html

时间: 2024-08-30 04:26:49

How to get the free disk space in PostgreSQL (PostgreSQL获取磁盘空间)的相关文章

“no space left on device”(磁盘空间不足)问题(续)

1.问题描述 no space left on device(磁盘空间不足) 2.文件删除原理 (1)硬链接数为0(所有硬链接均被删除) (2)进程调用数为0(没有进程在调度文件) 3.原因分析 硬链接数为0,进程调度数不为0 4.过程演示 (1)创建大文件 [[email protected] ~]# seq 500000000 > /var/log/messages (2)查看磁盘使用情况 [[email protected] ~]# df -h Filesystem     Size  U

关于“no space left on device”(磁盘空间不足)问题

1.首先介绍两个命令 df -h查看磁盘使用情况 df -i 查看inode使用情况 2.block满了 通常解决方法是删除大文件,不要直接删除,先确认数据是否重要,否则就掉坑里了. [[email protected] ~]# cd /app/logs/ [[email protected] logs]# ls -lh /bin/ls -rwxr-xr-x. 1 root root 107K Mar 23 02:52 /bin/ls [[email protected] logs]# df -

[转]Disk Space Usage and SQL Server Performance

Disk Space Usage and SQL Server Performance By Gregory A. Larsen When you think of SQL Server performance components, you think of the usage of CPU, memory, and the I/O it takes to process a query. However, there is another component you should consi

linux下如何查看disk space硬盘应用情况

主要是运用 df 指令,df是disk filesystem的缩写 其后面还可以加很多有用的tag df -h 以适合人类阅读的格式显示,也就是把容量以多少G(giga bytes),多少M为单位来显示 df -a 则是打印出最全的信息 以上两种便是最常用的了,若欲了解其他用法,可以查看 http://www.tecmint.com/how-to-check-disk-space-in-linux/ 或者直接 df --help得到帮助信息 linux下如何查看disk space硬盘应用情况

Disk Space Checking

On Error Resume Next Dim fso, DiskDriver,DD,Showfreespace,Totalsizespace,SizePercent Dim SendmailPermission SendmailPermission = 0 Set fso = wscript.createobject("scripting.filesystemobject") If (fso.folderexists("C:\Disk2")) = False t

Not enough free disk space on disk '/boot'(转载)

转自:http://m.oschina.net/blog/277224 # 解决 出现此情况是因为你的boot分区是单独分区的,像我只给了100M,以前装ubuntu时没有出现,所以当出现这个提示时,很纳闷,发现了答案. 为什么boot分区会满? 主要是存放了一些老的linux image镜像文件. SO, 我们想查看我们boot分区有那些linux image,使用命令: dpkg -l | grep linux-image 我们发现有 linux-image-3.13.0-24-generi

提示如下错误:No space left ondevice,通过 df -h 查看磁盘空间,发现没满,请问可能原因是什么?

如果向磁盘写入数据提示如下错误:No space left ondevice,通过 df -h 查看磁盘空间,发现没 满,请问可能原因是什么? 1.1首先查看我们的磁盘剩余情况 [[email protected] /]# df -h                 #发现磁盘没有满  还有%47 Filesystem      Size  Used Avail Use% Mounted on /dev/sda3       6.9G  3.1G 3.5G  47% / tmpfs       

Ora-19804: Cannot reclaim 45561856 bytes disk space from 8589934592 limit

启动数据库到Nomount: startup nomount 扩大闪回恢复区的大小:show parameter db_recovery 执行SQL语句:alter system set db_recovery_file_dest_size=5g scope=both; 打开数据库:alter database mount; 打开数据库:alter database open; 进入RMAN模式:rman target sys/admin nocatalog RMAN删除过期的备份文件与归档文件

jenkins出现Disk space is too low /tmp left

今天刚刚配置完毕jenkins突然出现构建项目的时候一直卡在 pending上面于是查看了一下 提示说是 tmp目录太小,不足1GB,需要添加但是磁盘已经分完了,于是修改一下jenkins的free的需求保存,解决 原文地址:http://blog.51cto.com/9025736/2061679