Server IP : 127.0.0.2 / Your IP : 3.145.171.144 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/bin/ |
Upload File : |
#!/usr/bin/perl -wT # Show all PostgreSQL clusters in a list # # (C) 2005-2009 Martin Pitt <mpitt@debian.org> # (C) 2013-2015 Christoph Berg <myon@debian.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. use strict; use PgCommon; use Getopt::Long; my $no_header; exit 1 unless GetOptions ('h|no-header' => \$no_header); my @lines; push @lines, ['Ver', 'Cluster', 'Port', 'Status', 'Owner', 'Data directory', 'Log file'] unless ($no_header); foreach my $v (sort (get_versions())) { my @clusters = get_version_clusters $v; foreach my $c (sort @clusters) { my %info = cluster_info $v, $c; my $logfile = $info{logfile}; # default logfile in /var/log/postgresql if (config_bool ($info{logging_collector})) { my $path = $info{log_directory} || 'pg_log'; my $file = $info{log_filename} || 'postgresql-%Y-%m-%d_%H%M%S.log'; $logfile = "$path/$file"; } my $destination = $info{log_destination} || 'stderr'; $destination =~ s/stderr/$logfile/; my $csvlog = $logfile; $csvlog =~ s/(?:\.log)?$/.csv/; $destination =~ s/csvlog/$csvlog/; push @lines, [$v, $c, $info{'port'}, ($info{'running'} ? "online" : "down") . ($info{'recovery'} ? ",recovery" : ""), defined $info{'owneruid'} ? (getpwuid $info{'owneruid'})[0] : '<unknown>', $info{'pgdata'} || '<not set>', $destination]; } } my @colwidth = qw(1 1 1 1 1 1 1); foreach my $line (@lines) { for (my $i = 0; $i < @$line - 1; $i++) { # skip adjustment for last column my $len = length @$line[$i]; $colwidth[$i] = $len if ($len > $colwidth[$i]); } } my $color = -t 1; # color output if stdout is a terminal my $fmtstring = join ' ', map { "%-${_}s" } @colwidth; foreach my $line (@lines) { if ($color and $line->[3] =~ /online/) { print "\033[32m"; # green } elsif ($color and $line->[3] =~ /down/) { print "\033[31m"; # red } printf "$fmtstring\n", @$line; } if ($color) { print "\033[0m"; # reset terminal } __END__ =head1 NAME pg_lsclusters - show information about all PostgreSQL clusters =head1 SYNOPSIS B<pg_lsclusters> [I<options>] =head1 DESCRIPTION This command shows a list about the configuration and status of all clusters. =head1 OPTIONS =over 4 =item B<-h>, B<--no-header> Do not print the column header line. =back =head1 NOTES The cluster status is shown as B<online> or B<down>. If a F<recovery.conf> file is found in the data directory, B<,recovery> is appended. The latter needs read access to the data directory, which only root and the cluster owner have. The output lines are colored green and red to indicate the cluster status visually. =head1 AUTHOR Martin Pitt L<E<lt>mpitt@debian.orgE<gt>>