Debian Codegraph @

pg_checksystem

raw
1 #!/usr/bin/perl -wT
2
3 # Check various system parameters for PostgreSQL. This needs to be run as root.
4 #
5 # (C) 2005-2009 Martin Pitt <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16
17 use strict;
18
19 use PgCommon;
20
21 # Check write cache setting for given drive.
22 # Arguments: <device>
23 # Returns: 0 = disabled, 1 = enabled, -1: could not determine
24 sub get_device_write_cache {
25 open DRV, $_[0] or return -1;
26 sub HDIO_GET_WCACHE () {0x30e;}
27 my $pval = pack 'l', 0;
28 ioctl DRV, &HDIO_GET_WCACHE, $pval or return -1;
29 my ($val) = unpack 'l', $pval;
30 close DRV;
31 return $val;
32 }
33
34
35 error 'This command needs to be executed as root' if $> != 0;
36
37 # collect write cache-enabled drives with databases
38 my %drive_wcache;
39 my %seen;
40 for my $v (get_versions) {
41 for my $c (get_version_clusters $v) {
42 my $datadir = PgCommon::cluster_data_directory $v, $c;
43 my $drv = PgCommon::get_file_device $datadir;
44 $drv =~ s/[0-9]+$//;
45 unless (exists $seen{$drv}) {
46 $drive_wcache{$drv} = 1 if (get_device_write_cache $drv) > 0;
47 $seen{$drv} = 1;
48 }
49 }
50 }
51 my @unsave_drives = keys %drive_wcache;
52
53 if (@unsave_drives) {
54 print 'Warning: The following devices contain databases and have write
55 caching enabled: ', (join ' ', @unsave_drives), '
56 This could destroy the integrity of your databases in the event of power
57 failure. Consider disabling the write cache with "hdparm -W 0 <device>".
58 ';
59 }