Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ Multiple aliases may be supported on a single host.
action [:setup, :start]
end

# setup and start a connection pool with database fallback (all databases)
pgbouncer_connection "database_example_com_fallback" do
db_host "database.example.com"
db_port "6432"
use_db_fallback true
userlist "readwrite_user" => "md500000000000000000000000000000000", "readonly_user" => "md500000000000000000000000000000000"
max_client_conn 100
default_pool_size 20
action [:setup, :start]
end

# stop a connection pool
pgbouncer_connection "database_example_com_ro" do
action :stop
Expand Down
4 changes: 3 additions & 1 deletion resources/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
attribute :db_alias, :kind_of => String, :name_attribute => true
attribute :db_host, :kind_of => String, :required => true
attribute :db_port, :kind_of => String, :required => true
attribute :db_name, :kind_of => String, :required => true
attribute :db_name, :kind_of => String

attribute :use_db_fallback, :kind_of => [TrueClass, FalseClass], :default => false

attribute :userlist, :kind_of => Hash, :required => true

Expand Down
4 changes: 4 additions & 0 deletions templates/default/etc/pgbouncer/pgbouncer.ini.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
;; client_encoding= datestyle= timezone=
;; pool_size= connect_query=
[databases]
<% if @use_db_fallback %>
* = host=<%= @db_host %> port=<%= @db_port %>
<% else %>
<%= @db_alias %> = host=<%= @db_host %> port=<%= @db_port %> dbname=<%= @db_name %> <%= "connect_query='#{@connect_query}'" unless @connect_query.nil? || @connect_query.empty? %>
<% end %>

;; Configuration section
[pgbouncer]
Expand Down