@@ -920,7 +920,8 @@ package check_postgres;
920
920
921
921
# # These options are multiples ('@s')
922
922
for my $arr (qw/ include exclude includeuser excludeuser host port
923
- dbuser dbname dbpass dbservice schema/ ) {
923
+ dbuser dbname dbpass dbservice schema excludeapp
924
+ includeapp/ ) {
924
925
next if $name ne $arr and $name ne " ${arr} 2" ;
925
926
push @{$tempopt {$name }} => $value ;
926
927
# # Don't set below as a normal value
@@ -961,6 +962,8 @@ package check_postgres;
961
962
' exclude=s@' ,
962
963
' includeuser=s@' ,
963
964
' excludeuser=s@' ,
965
+ ' excludeapp=s@' ,
966
+ ' includeapp=s@' ,
964
967
965
968
' host|dbhost|H|dbhost1|H1=s@' ,
966
969
' port|dbport|p|port1|dbport1|p1=s@' ,
@@ -1224,6 +1227,8 @@ package check_postgres;
1224
1227
--exclude=name(s) items to specifically exclude (e.g. tables), depends on the action
1225
1228
--includeuser=include objects owned by certain users
1226
1229
--excludeuser=exclude objects owned by certain users
1230
+ --excludeapp=exclude objects by application_name
1231
+ --includeapp=include objects by application_name
1227
1232
1228
1233
Other options:
1229
1234
--assume-standby-mode assume that server in continious WAL recovery mode
@@ -1871,6 +1876,52 @@ sub finishup {
1871
1876
}
1872
1877
}
1873
1878
1879
+ our $APPWHERECLAUSE = ' ' ;
1880
+ if ($opt {includeapp }) {
1881
+ my %applist ;
1882
+ for my $app (@{$opt {includeapp }}) {
1883
+ for my $a2 (split /,/ => $app ) {
1884
+ $applist {$a2 }++;
1885
+ }
1886
+ }
1887
+ my $safeapp ;
1888
+ if (1 == keys %applist ) {
1889
+ ($safeapp = each %applist ) =~ s / '/ ''/ g ;
1890
+ $APPWHERECLAUSE = " AND application_name = '$safeapp '" ;
1891
+ }
1892
+ else {
1893
+ $APPWHERECLAUSE = ' AND application_name IN (' ;
1894
+ for my $app (sort keys %applist ) {
1895
+ ($safeapp = $app ) =~ s / '/ ''/ g ;
1896
+ $APPWHERECLAUSE .= " '$safeapp '," ;
1897
+ }
1898
+ chop $APPWHERECLAUSE ;
1899
+ $APPWHERECLAUSE .= ' )' ;
1900
+ }
1901
+ }
1902
+ elsif ($opt {excludeapp }) {
1903
+ my %applist ;
1904
+ for my $app (@{$opt {excludeapp }}) {
1905
+ for my $a2 (split /,/ => $app ) {
1906
+ $applist {$a2 }++;
1907
+ }
1908
+ }
1909
+ my $safeapp ;
1910
+ if (1 == keys %applist ) {
1911
+ ($safeapp = each %applist ) =~ s / '/ ''/ g ;
1912
+ $APPWHERECLAUSE = " AND application_name <> '$safeapp '" ;
1913
+ }
1914
+ else {
1915
+ $APPWHERECLAUSE = ' AND application_name NOT IN (' ;
1916
+ for my $app (sort keys %applist ) {
1917
+ ($safeapp = $app ) =~ s / '/ ''/ g ;
1918
+ $APPWHERECLAUSE .= " '$safeapp '," ;
1919
+ }
1920
+ chop $APPWHERECLAUSE ;
1921
+ $APPWHERECLAUSE .= ' )' ;
1922
+ }
1923
+ }
1924
+
1874
1925
# # Check number of connections, compare to max_connections
1875
1926
check_backends() if $action eq ' backends' ;
1876
1927
@@ -7599,7 +7650,7 @@ sub check_txn_idle {
7599
7650
$SQL = q{ SELECT datname, datid, procpid AS pid, usename, client_addr, xact_start, current_query AS current_query, '' AS state, } .
7600
7651
q{ CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, } .
7601
7652
qq{ COALESCE(ROUND(EXTRACT(epoch FROM now()-$start )),0) AS seconds } .
7602
- qq{ FROM pg_stat_activity WHERE ($clause )$USERWHERECLAUSE } .
7653
+ qq{ FROM pg_stat_activity WHERE ($clause )$USERWHERECLAUSE $APPWHERECLAUSE } .
7603
7654
q{ ORDER BY xact_start, query_start, procpid DESC} ;
7604
7655
# # Craft an alternate version for old servers that do not have the xact_start column:
7605
7656
($SQL2 = $SQL ) =~ s / xact_start/ query_start AS xact_start/ ;
@@ -7609,7 +7660,7 @@ sub check_txn_idle {
7609
7660
$SQL2 = $SQL = q{ SELECT datname, datid, procpid AS pid, usename, client_addr, current_query AS current_query, '' AS state, } .
7610
7661
q{ CASE WHEN client_port < 0 THEN 0 ELSE client_port END AS client_port, } .
7611
7662
qq{ COALESCE(ROUND(EXTRACT(epoch FROM now()-$start )),0) AS seconds } .
7612
- qq{ FROM pg_stat_activity WHERE ($clause )$USERWHERECLAUSE } .
7663
+ qq{ FROM pg_stat_activity WHERE ($clause )$USERWHERECLAUSE $APPWHERECLAUSE } .
7613
7664
q{ ORDER BY query_start, procpid DESC} ;
7614
7665
}
7615
7666
0 commit comments