Vadym Urupa
Vadym Urupa

Reputation: 41

Google Cloud SQL cannot connect to Apache Superset

While trying to connect Apache Superset to Google Cloud SQL (PostgreSQL) I get this error:

5432 The port is closed.

I also unsuccessfully tried to connect by SQLAlchemy URI string
postgresql://username:password@host:port/database as well as
PostgreSQL+psycopg2://username:password@host:port/database?sslmode=require;
yielding
Error: Please check your connection details and database settings, and ensure that your database is accepting connections, then try connecting again.

What I used:

Can somebody help to understand and solve?

Upvotes: 1

Views: 532

Answers (3)

Puranjay Kwatra
Puranjay Kwatra

Reputation: 316

Instead of External IP enter the Internal Ip address when it is asking for IP address and in port provide 3306 port it is the default port address

Upvotes: 0

Jonathan Hess
Jonathan Hess

Reputation: 356

I recommend configuring Superset to connect to the private IP address of your Google Cloud SQL Postgres instance. This has a few main benefits:

  • Your postgres database is not reachable from the public internet.
  • The database connection will behave like any other posgres database.

First, get the name of the VPC connected to the VMs running your Superset application.

Then, you have two options to configure access to Cloud SQL from your private network:

Option 1: Use the instance's Private IP Address

If your Cloud SQL Instance will only be accessed from one VPC, then configure it to

Configure your Cloud SQL instance to attach a private IP address to that VPC following the instructions here Cloud SQL Configure Private IP

To enable the private IP on an existing instance using the gcloud cli:

gcloud beta sql instances patch INSTANCE_ID \
--project=PROJECT_ID \
--network=projects/NETWORK_PROJECT_ID/global/networks/VPC_NETWORK_NAME \
--no-assign-ip \
--enable-google-private-path

Then, get the private IP address for your instance from the cloud console, or by running this command:

gcloud beta sql instances describe <INSTANCENAME>

Which will produce output that looks like this, including the private ip address for the instance.

connectionName: <CONNECTION NAME>
# ...
instanceType: CLOUD_SQL_INSTANCE
ipAddresses:
- ipAddress: 10.2.2.2 ### Note: your instance address will be different
  type: PRIVATE
# ...

Finally, connect your database using the private IP Address with a connection string like this:

postgresql://username:[email protected]:5432/database

Option 2: Use Private Service Connect

If your Cloud SQL Instance needs to be reached from multiple applications running on different VPCs, need to configure Private Service Access

This is considerably more complex to set up, but has the advantage of being a more flexible way to connect a Cloud SQL instance to multiple VPC networks.

Upvotes: 2

Vadym Urupa
Vadym Urupa

Reputation: 41

Private IP has to be created in cloud SQL to connect to Superset. Link to the docs

Upvotes: 2

Related Questions