应用引擎的Spring Boot实例不断重新连接到Postgres Google sql

时间:2019-04-11 15:17:14

标签: postgresql spring-boot google-app-engine google-cloud-sql

我正在Google App Engine上运行Spring Boot应用程序,而前一天该应用程序崩溃导致该应用程序重新启动。在查看日志时,我注意到应用程序不断重复连接到我的Google sql postgres数据库。

从数据库中查看日志,我可以看到我在数据库上有60个连接。我使用JDBC URL通过cloud-sql-jdbc-socket-factory简单地连接到数据库: dbc:postgresql://google/{databaseName}?useSSL=false&cloudSqlInstance={instanceUrl}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user={user}&password={password}

显示的日志为:

A  2019-04-11 14:57:01.674  INFO 1 --- [onnection adder] c.g.cloud.sql.core.SslSocketFactory      : Connecting to Cloud SQL instance [{instance url}] on IP [{ip adress}].

A  2019-04-11 14:58:11.458  INFO 1 --- [onnection adder] c.g.cloud.sql.postgres.SocketFactory     : Connecting to Cloud SQL instance [{instance url}] via ssl socket.

A  2019-04-11 14:58:11.460  INFO 1 --- [onnection adder] c.g.cloud.sql.core.SslSocketFactory      : Connecting to Cloud SQL instance [{instance url}] on IP [{ip adress}].

A  2019-04-11 14:58:22.878  INFO 1 --- [onnection adder] c.g.cloud.sql.postgres.SocketFactory     : Connecting to Cloud SQL instance [{instance url}] via ssl socket.

A  2019-04-11 14:58:22.880  INFO 1 --- [onnection adder] c.g.cloud.sql.core.SslSocketFactory      : Connecting to Cloud SQL instance [{instance url}] on IP [{ip adress}].

A  2019-04-11 15:01:56.477  INFO 1 --- [onnection adder] c.g.cloud.sql.postgres.SocketFactory     : Connecting to Cloud SQL instance  [{instance url}] via ssl socket.

A  2019-04-11 15:01:56.479  INFO 1 --- [onnection adder] c.g.cloud.sql.core.SslSocketFactory      : Connecting to Cloud SQL instance  [{instance url}] on IP [{ip adress}].

A  2019-04-11 15:02:08.108  INFO 1 --- [onnection adder] c.g.cloud.sql.postgres.SocketFactory     : Connecting to Cloud SQL instance [{instance url}] via ssl socket.

1 个答案:

答案 0 :(得分:0)

建议应用引擎中的Project至少具有Ram 2 gb,以避免Connection Error,您可以查看此url中的所有代码问题: https://cloud.google.com/sql/docs/postgres/connect-external-app