From 52977a7794fdf0d0569cbcb0eb9e771fd8a16805 Mon Sep 17 00:00:00 2001 From: glyn Date: Tue, 13 Oct 2015 10:56:57 +0100 Subject: [PATCH] Add support for auth_user and ensure nodes currently being cloned are never used. --- README.md | 1 + pgbouncer_follower.pl | 14 ++++++++++++-- pgbouncer_follower_ro.conf | 3 +++ pgbouncer_follower_rw.conf | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8357780..142e864 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ $ sudo invoke-rc.d pgbouncer_follower_rw start | pgBouncer | sets_to_follow | text | *1* | Comma separated list of sets to follow or 'all' to follow all sets | pgBouncer | pool_mode | 'ro/rw' | *'rw'* | Select a read-only subscriber or the origin for read-write | pgBouncer | pool_all_databases | boolean | *'false'* | If true uses wildcard for database name in pgbouncer.ini, false uses slony database +| pgBouncer | auth_user | text | *''* | If set auth_user will be appended to conninfo written in [databases] section | pgBouncer | only_follow_origins | boolean | *'false'* | If true pgbouncer will only be reconfigured and reloaded when sets move origin | pgBouncer | status_file | text | *'/tmp/pgbouncer_follower_%mode.status'* | File used to store a hash depicting the state of the cluster | pgBouncer | log_file | text | *'/tmp/pgbouncer_follower_%mode.log'* | Log file for the script diff --git a/pgbouncer_follower.pl b/pgbouncer_follower.pl index aa55bcb..e2c2561 100755 --- a/pgbouncer_follower.pl +++ b/pgbouncer_follower.pl @@ -55,6 +55,7 @@ my $g_conf_target = "/etc/pgbouncer/pgbouncer_%mode.ini"; my $g_reload_command = "/etc/init.d/pgbouncer_%mode reload"; my $g_mode = 'rw'; my $g_all_databases=false; +my $g_auth_user=''; my ($year, $month, $day, $hour, $min, $sec); my $change_time; my $g_host = hostname; @@ -186,11 +187,16 @@ sub generateConfig { my $target_sets; my $target_port = 5432; my $target_is_origin; + my $target_auth = ""; if ($g_debug) { printLogLn($g_logfile, "DEBUG: All databases = " . ($g_all_databases ? 'true' : 'false')); } + if ($g_auth_user ne "") { + $target_auth = " auth_user=" . $g_auth_user; + } + if (open(INFILE, "<", $template)) { if (open(OUTFILE, ">", $target)) { print OUTFILE "# Configuration file autogenerated at " . getRuntime() . " from $template\n"; @@ -259,10 +265,10 @@ sub generateConfig { printLogLn ($g_logfile, "DEBUG: Configuration for " . ($target_is_origin ? "origin" : "subscriber") . " of sets $target_sets node #$target_node_id $target_host:$target_port"); } if ($all_databases) { - $_ =~ s/(\[databases\])/$1\n\* = host=$target_host port=$target_port/; + $_ =~ s/(\[databases\])/$1\n\* = host=$target_host port=$target_port$target_auth/; } else { - $_ =~ s/(\[databases\])/$1\n$target_db = host=$target_host port=$target_port dbname=$target_db/; + $_ =~ s/(\[databases\])/$1\n$target_db = host=$target_host port=$target_port dbname=$target_db$target_auth/; } } else { @@ -387,6 +393,7 @@ sub loadCluster { COALESCE((? BETWEEN 1 AND extract(epoch from s.st_lag_time)),false) AS lag_exceeded FROM x LEFT JOIN $qw_clname.sl_status s ON s.st_received = x.no_id + WHERE x.no_conninfo != '' ) SELECT * FROM z ORDER BY origin_sets, @(CASE WHEN (host ~ '^[0-9]{1,3}(.[0-9]{1,3}){3}\$') THEN host::inet ELSE '255.255.255.255'::inet END - ?::inet) ASC"; @@ -497,6 +504,9 @@ sub getConfig { when(/\bpool_all_databases\b/i) { $g_all_databases = checkBoolean($value); } + when(/\bauth_user\b/i) { + $g_auth_user = $value; + } when(/\bonly_follow_origins\b/i) { $g_origins_only = checkBoolean($value); } diff --git a/pgbouncer_follower_ro.conf b/pgbouncer_follower_ro.conf index 209c8bc..7c07e7f 100755 --- a/pgbouncer_follower_ro.conf +++ b/pgbouncer_follower_ro.conf @@ -33,6 +33,9 @@ pool_all_databases=false # thus hosting all databases on the node. If false # only the replicated database is hosted. +auth_user= # If set auth_user will be appended to conninfo written + # in [databases] section. + status_file=/var/slony/pgbouncer_follower/pgbouncer_follower_%mode.status # File used to store tate of the cluster log_file=/var/slony/pgbouncer_follower/pgbouncer_follower_%mode.log # Log for pool_follower script pid_file=/var/run/pgbouncer_follower_%mode.pid # Pidfile for poll mode diff --git a/pgbouncer_follower_rw.conf b/pgbouncer_follower_rw.conf index f06fa44..8f58c75 100755 --- a/pgbouncer_follower_rw.conf +++ b/pgbouncer_follower_rw.conf @@ -33,6 +33,9 @@ pool_all_databases=false # thus hosting all databases on the node. If false # only the replicated database is hosted. +auth_user= # If set auth_user will be appended to conninfo written + # in [databases] section. + status_file=/var/slony/pgbouncer_follower/pgbouncer_follower_%mode.status # File used to store tate of the cluster log_file=/var/slony/pgbouncer_follower/pgbouncer_follower_%mode.log # Log for pool_follower script pid_file=/var/run/pgbouncer_follower_%mode.pid # Pidfile for poll mode -- 2.39.5