diff --git a/lib/gitlab/database/load_balancing/load_balancer.rb b/lib/gitlab/database/load_balancing/load_balancer.rb
index dc6678dc93ba4ac1ae02de30f43df71f179a69cf..c9ae7d222ed18a02989460e7c680ebaa7105d4da 100644
--- a/lib/gitlab/database/load_balancing/load_balancer.rb
+++ b/lib/gitlab/database/load_balancing/load_balancer.rb
@@ -54,7 +54,10 @@ def read(&block)
               connection = host.connection
               return yield connection
             rescue StandardError => error
-              if serialization_failure?(error)
+              if primary_only?
+                # If we only have primary configured, retrying is pointless
+                raise error
+              elsif serialization_failure?(error)
                 # This error can occur when a query conflicts. See
                 # https://www.postgresql.org/docs/current/static/hot-standby.html#HOT-STANDBY-CONFLICT
                 # for more information.
diff --git a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
index 883c847370415f422210361f3111371cf61e1147..117fa6be20941d854b083de15277a5914f7b1917 100644
--- a/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
+++ b/spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb
@@ -141,6 +141,24 @@ def twice_wrapped_exception(top, middle, original)
       lb.read { raise conflict_error }
     end
 
+    context 'only primary is configured' do
+      let(:lb) do
+        config = Gitlab::Database::LoadBalancing::Configuration.new(ActiveRecord::Base)
+        allow(config).to receive(:load_balancing_enabled?).and_return(false)
+
+        described_class.new(config)
+      end
+
+      it 'does not retry a query on connection error if only the primary is configured' do
+        host = double(:host, query_cache_enabled: true)
+
+        allow(lb).to receive(:host).and_return(host)
+        allow(host).to receive(:connection).and_raise(PG::UnableToSend)
+
+        expect { lb.read }.to raise_error(PG::UnableToSend)
+      end
+    end
+
     it 'uses the primary if no secondaries are available' do
       allow(lb).to receive(:connection_error?).and_return(true)