diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-03 09:31:37 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-03 17:00:31 +0300 |
commit | fd7f95ee7421f297e71f8fe81159b6d9df381e4c (patch) | |
tree | 6a6c8aca35fba80ca915318265950204cfe4fe4b /app/models/postgresql | |
parent | 3cdf7c7ec137d7753bab7687b24c7c1cd880357b (diff) |
Disable replication lag check for Aurora PostgreSQL databases
Replication slots are not supported in Aurora. Attempting to check
the lag results in the message:
```
ActiveRecord::StatementInvalid: PG::FeatureNotSupported: ERROR:
Replication slots are currently not supported in Aurora : SELECT
pg_xlog_location_diff(pg_current_xlog_insert_location(),
restart_lsn)::...
```
To avoid breaking support for background migrations in Aurora, we just
disable the check if we encounter this error.
This change also now checks whether there are any replication slots
present in the primary before checking the replication lag.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/52176
Diffstat (limited to 'app/models/postgresql')
-rw-r--r-- | app/models/postgresql/replication_slot.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/postgresql/replication_slot.rb b/app/models/postgresql/replication_slot.rb index 70c7432e6b5..e264fe88e47 100644 --- a/app/models/postgresql/replication_slot.rb +++ b/app/models/postgresql/replication_slot.rb @@ -4,6 +4,15 @@ module Postgresql class ReplicationSlot < ActiveRecord::Base self.table_name = 'pg_replication_slots' + # Returns true if there are any replication slots in use. + # PostgreSQL-compatible databases such as Aurora don't support + # replication slots, so this will return false as well. + def self.in_use? + transaction { exists? } + rescue ActiveRecord::StatementInvalid + false + end + # Returns true if the lag observed across all replication slots exceeds a # given threshold. # @@ -11,6 +20,8 @@ module Postgresql # statistics it takes between 1 and 5 seconds to replicate around # 100 MB of data. def self.lag_too_great?(max = 100.megabytes) + return false unless in_use? + lag_function = "#{Gitlab::Database.pg_wal_lsn_diff}" \ "(#{Gitlab::Database.pg_current_wal_insert_lsn}(), restart_lsn)::bigint" |