diff --git a/changelogs/unreleased/zj-pg-connection-ff-gitaly.yml b/changelogs/unreleased/zj-pg-connection-ff-gitaly.yml
new file mode 100644
index 0000000000000000000000000000000000000000..39b335b76b99228747f0e9b16c1ad14d840a6741
--- /dev/null
+++ b/changelogs/unreleased/zj-pg-connection-ff-gitaly.yml
@@ -0,0 +1,5 @@
+---
+title: Remove required dependecy of Postgresql for Gitaly
+merge_request: 18659
+author:
+type: other
diff --git a/lib/feature/gitaly.rb b/lib/feature/gitaly.rb
index c23d7025d0f0eb2df84f71b4ee0e19b21eb2d2bc..0ac2d017e1afca4f6f95ab2370cbc49770ebd715 100644
--- a/lib/feature/gitaly.rb
+++ b/lib/feature/gitaly.rb
@@ -19,7 +19,7 @@ class Feature
 
         default_on = DEFAULT_ON_FLAGS.include?(feature_flag)
         Feature.enabled?("gitaly_#{feature_flag}", default_enabled: default_on)
-      rescue ActiveRecord::NoDatabaseError
+      rescue ActiveRecord::NoDatabaseError, PG::ConnectionBad
         false
       end
 
diff --git a/qa/qa/specs/features/browser_ui/3_create/repository/user_views_commit_diff_patch_spec.rb b/qa/qa/specs/features/browser_ui/3_create/repository/user_views_commit_diff_patch_spec.rb
index b2eef38f8960c41db4377ee3fb8a17111c3ee1a1..5459104ec847073f39c51556bf21d450e008e5ca 100644
--- a/qa/qa/specs/features/browser_ui/3_create/repository/user_views_commit_diff_patch_spec.rb
+++ b/qa/qa/specs/features/browser_ui/3_create/repository/user_views_commit_diff_patch_spec.rb
@@ -4,9 +4,6 @@ module QA
   context 'Create' do
     describe 'Commit data' do
       before(:context) do
-        Runtime::Browser.visit(:gitlab, Page::Main::Login)
-        Page::Main::Login.perform(&:sign_in_using_credentials)
-
         # Get the user's details to confirm they're included in the email patch
         @user = Resource::User.fabricate_via_api! do |user|
           user.username = Runtime::User.username
@@ -34,9 +31,12 @@ module QA
       end
 
       def view_commit
+        Runtime::Browser.visit(:gitlab, Page::Main::Login)
+        Page::Main::Login.perform(&:sign_in_using_credentials)
+
         @project.visit!
-        Page::Project::Show.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
-          page.click_commit(@commit_message)
+        Page::Project::Show.perform do |show|
+          show.click_commit(@commit_message)
         end
       end
 
diff --git a/qa/qa/support/api.rb b/qa/qa/support/api.rb
index d0ff1f8bc2c065e1b82fc5448951f5fc1f5a9f68..cd496efb4db7f7568c8aad55cd6f813928fa391c 100644
--- a/qa/qa/support/api.rb
+++ b/qa/qa/support/api.rb
@@ -14,7 +14,7 @@ module QA
           payload: payload,
           verify_ssl: false)
       rescue RestClient::ExceptionWithResponse => e
-        e.response
+        return_response_or_raise(e)
       end
 
       def get(url, raw_response: false)
@@ -24,7 +24,7 @@ module QA
           verify_ssl: false,
           raw_response: raw_response)
       rescue RestClient::ExceptionWithResponse => e
-        e.response
+        return_response_or_raise(e)
       end
 
       def put(url, payload)
@@ -34,7 +34,7 @@ module QA
           payload: payload,
           verify_ssl: false)
       rescue RestClient::ExceptionWithResponse => e
-        e.response
+        return_response_or_raise(e)
       end
 
       def delete(url)
@@ -43,7 +43,7 @@ module QA
           url: url,
           verify_ssl: false)
       rescue RestClient::ExceptionWithResponse => e
-        e.response
+        return_response_or_raise(e)
       end
 
       def head(url)
@@ -52,12 +52,18 @@ module QA
           url: url,
           verify_ssl: false)
       rescue RestClient::ExceptionWithResponse => e
-        e.response
+        return_response_or_raise(e)
       end
 
       def parse_body(response)
         JSON.parse(response.body, symbolize_names: true)
       end
+
+      def return_response_or_raise(error)
+        raise error unless error.respond_to?(:response) && error.response
+
+        error.response
+      end
     end
   end
 end