Merge branch 'postgresql-replication' into 'master'

Added postgresql replication settings

This will add settings for enabling streaming replication in postgresql, default master.

WAL will be enabled by default so it's easier to add a slave to your current postgresql instance.

See merge request !532
This commit is contained in:
Marin Jankovski 2015-11-05 18:37:40 +00:00
commit f1949604de
3 changed files with 24 additions and 6 deletions

View File

@ -313,7 +313,12 @@ default['gitlab']['postgresql']['checkpoint_segments'] = 10
default['gitlab']['postgresql']['checkpoint_timeout'] = "5min"
default['gitlab']['postgresql']['checkpoint_completion_target'] = 0.9
default['gitlab']['postgresql']['checkpoint_warning'] = "30s"
# Replication settings
default['gitlab']['postgresql']['sql_replication_user'] = "gitlab_replicator"
default['gitlab']['postgresql']['wal_level'] = "minimal"
default['gitlab']['postgresql']['max_wal_senders'] = 0
default['gitlab']['postgresql']['wal_keep_segments'] = 10
default['gitlab']['postgresql']['hot_standby'] = "off"
####
# Redis

View File

@ -166,3 +166,16 @@ databases.each do |rails_app, db_name, sql_user|
notifies :run, "execute[initialize #{rails_app} database]", :immediately
end
end
###
# Create replication user
###
sql_replication_user = node['gitlab']['postgresql']['sql_replication_user']
execute "create #{sql_replication_user} replication user" do
command "#{bin_dir}/psql --port #{pg_port} -h #{postgresql_socket_dir} -d template1 -c \"CREATE USER #{sql_replication_user} REPLICATION\""
user postgresql_user
# Added retries to give the service time to start on slower systems
retries 20
not_if { !pg_helper.is_running? || pg_helper.user_exists?(sql_replication_user) }
end

View File

@ -154,7 +154,7 @@ work_mem = <%= node['gitlab']['postgresql']['work_mem'] %> # min 64kB
# - Settings -
#wal_level = minimal # minimal, archive, or hot_standby
wal_level = <%= node['gitlab']['postgresql']['wal_level'] %>
# (change requires restart)
#fsync = on # turns forced synchronization on or off
#synchronous_commit = on # synchronization level; on, off, or local
@ -175,7 +175,7 @@ work_mem = <%= node['gitlab']['postgresql']['work_mem'] %> # min 64kB
# - Checkpoints -
checkpoint_segments = <%= node['gitlab']['postgresql']['checkpoint_segments'] %> # in logfile segments, min 1, 16MB each, default 3
checkpoint_segments = <%= node['gitlab']['postgresql']['checkpoint_segments'] %> # in logfile segments, min 1, 16MB each, default 3
checkpoint_timeout = <%= node['gitlab']['postgresql']['checkpoint_timeout'] %> # range 30s-1h, default 5min
checkpoint_completion_target = <%= node['gitlab']['postgresql']['checkpoint_completion_target'] %> # checkpoint target duration, 0.0 - 1.0, default 0.5
checkpoint_warning = <%= node['gitlab']['postgresql']['checkpoint_warning'] %> # 0 disables, default 30s
@ -197,10 +197,10 @@ checkpoint_warning = <%= node['gitlab']['postgresql']['checkpoint_warning'] %>
# These settings are ignored on a standby server
#max_wal_senders = 0 # max number of walsender processes
max_wal_senders = <%= node['gitlab']['postgresql']['max_wal_senders'] %>
# (change requires restart)
#wal_sender_delay = 1s # walsender cycle time, 1-10000 milliseconds
#wal_keep_segments = 0 # in logfile segments, 16MB each; 0 disables
wal_keep_segments = <%= node['gitlab']['postgresql']['wal_keep_segments'] %>
#vacuum_defer_cleanup_age = 0 # number of xacts by which cleanup is delayed
#replication_timeout = 60s # in milliseconds; 0 disables
#synchronous_standby_names = '' # standby servers that provide sync rep
@ -211,7 +211,7 @@ checkpoint_warning = <%= node['gitlab']['postgresql']['checkpoint_warning'] %>
# These settings are ignored on a master server
#hot_standby = off # "on" allows queries during recovery
hot_standby = <%= node['gitlab']['postgresql']['hot_standby'] %>
# (change requires restart)
#max_standby_archive_delay = 30s # max delay before canceling queries
# when reading WAL from archive;