Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Getting Error: The connection was forcibly closed

Hello Team,

I've been working on establishing a connection with Cloud SQL - Postgres. I've ensured that I have all the required permissions both for myself and the service account. Additionally, I've successfully created the instance in Cloud SQL - Postgres, along with the necessary user and database configurations. However, during the connector setup process in Application Integration, after providing all the requisite details, I encounter an issue where the connection attempt loads for a few minutes before ultimately failing with one of the following error messages: "The Connection has been closed", "The connection was forcibly closed", or "Connection deployment timeout". Interestingly, I'm encountering a similar issue with the Cloud SQL - MySQL connector as well. I'm seeking assistance in resolving this issue and understanding the underlying cause. Any insights or guidance you can provide would be greatly appreciated. I've attached a screenshot of the error for reference.

ahitankar_1-1715781131161.png

Thanks

 

Solved Solved
1 14 1,307
1 ACCEPTED SOLUTION

Hi Ahitankar, 

Probably worth checking what permissions you have given the service account, we gave ours:

GrahamVosper_0-1715845018970.png

Otherwise not sure what else to suggest, probably needs a case raised with Google.

View solution in original post

14 REPLIES 14

Hi Ahitankar, 

in my team we have been using this postgres connector successfully for the last year. It sounds more like a networking issue preventing connection to your database.  Have you allowed "Private IP connectivity" to your database (edit database, scroll down to connections, enable 'private ip')

Hi Graham-Vosper,

Even after enabling "Private IP connectivity" in my database settings with default network configurations, the error persists. I've included a screenshot of the connections tab for reference. Can you speculate on other potential causes for this issue?

Hi Ahitankar, 

Probably worth checking what permissions you have given the service account, we gave ours:

GrahamVosper_0-1715845018970.png

Otherwise not sure what else to suggest, probably needs a case raised with Google.

Hi Graham - Vosper,

We have all the above three mentioned permissions to the service account. 

ahitankar_0-1715847034975.png

 

Hi Ahitankar,

I'm facing the same issue, did you figure out how to solve?

Thanks,

Mattia

@ahitankar @Graham-Vosper 

Dears did you solve this problem ?

check firewall and vpc.

what should i check ?

the port is opened in firewall

 

thanks @SinghPavan 
Is there a guide for this troubleshooting ?

can you check the logs for error or cause

here
Screenshot 2024-12-26 133714.png

 

This log entry indicates a problem with a connection to a PostgreSQL database. The error message "Connection was forcibly closed" suggests that the connection was terminated unexpectedly. This could be due to several factors:

Possible Causes:

  • Network Issues: A temporary network interruption or instability could have caused the connection to be dropped.
  • Database Server Issues: The PostgreSQL server itself might be experiencing problems, such as resource exhaustion or a temporary outage.
  • Connection Timeout: The connection might have timed out due to inactivity or a configured timeout setting.
  • Database Access Restrictions: The user account or the application might have insufficient permissions to access the database.
  • Firewall Rules: Firewall rules on the database server or the client machine might be blocking the connection.
  • Database Load: The PostgreSQL server might be under heavy load, causing it to close connections to manage resources.
  • Client-Side Issues: The application or the client library might be experiencing issues that are causing the connection to be closed.

Troubleshooting Steps:

  1. Check Network Connectivity: Verify that there is a stable network connection between the client and the PostgreSQL server.
  2. Review Database Server Logs: Examine the PostgreSQL server logs for any errors or warnings related to the connection.
  3. Check Connection Settings: Ensure that the connection parameters (host, port, username, password) are correct and that the connection timeout is set appropriately.
  4. Verify Database Access Permissions: Confirm that the user account has the necessary permissions to access the database.
  5. Review Firewall Rules: Check firewall rules on both the client and server machines to ensure that the connection is allowed.
  6. Monitor Database Load: Observe the PostgreSQL server's load and resource usage to see if it is experiencing any performance issues.
  7. Debug Client-Side Code: Inspect the application code or client library for any potential issues that might be causing the connection to be closed.

Additional Tips:

  • Retry the Connection: Try re-establishing the connection to see if the issue is temporary.

Thank you @SinghPavan 

Top Solution Authors