From 30850b5496922652247c3d447e8698d920a7c5d1 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 5 Apr 2018 10:17:03 +0900 Subject: [PATCH] check_disk_space: handle relative symlinks for the WAL directory If the WAL directory (pg_xlog or pg_wal) resolves to a symbolic link, e.g. "../some-wal-dir", the check fails with an error like: ERROR: Invalid result from command "/bin/df -kP "../some-wal-dir" 2>&1": /bin/df: "../some-wal-dir": No such file or directory This patch checks for a relative symlink and extracts the actual WAL directory using abs_path(). --- check_postgres.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/check_postgres.pl b/check_postgres.pl index 3851d8f2..0e4863ee 100755 --- a/check_postgres.pl +++ b/check_postgres.pl @@ -26,6 +26,7 @@ package check_postgres; use File::Temp qw/tempfile tempdir/; File::Temp->safe_level( File::Temp::MEDIUM ); use Cwd; +use Cwd 'abs_path'; use Data::Dumper qw/Dumper/; $Data::Dumper::Varname = 'POSTGRES'; $Data::Dumper::Indent = 2; @@ -4995,6 +4996,12 @@ sub check_disk_space { my $xlog = "$datadir/pg_xlog"; if (-l $xlog) { my $linkdir = readlink($xlog); + + ## Handle relative symbolic links + if ($linkdir =~ m|^\.|) { + $linkdir = abs_path("$datadir/$linkdir"); + } + $dir{$linkdir} = 1 if ! exists $dir{$linkdir}; } }