Search code examples
djangopostgresqlgoogle-cloud-sql

"Error: unknown shorthand flag: 'n' in -nstances" when trying to connect Google Cloud Proxy to Postgresql (Django)


I'm following a google tutorial to set up Django on Cloud Run with Postgresql connected via Google Cloud Proxy. However I keep hitting an error on this command in the Google Cloud Shell.

cloud shell input: xyz@cloudshell:~ (project-xyz)$ ./cloud-sql-proxy -instances="amz-reporting-files-21:us-west1-c:api-20230212"=tcp:5432

returns: Error: unknown shorthand flag: 'n' in -nstances=amz-reporting-files-21:us-west1-c:Iamz-ads-api-20230212=tcp:5432 Usage: cloud-sql-proxy INSTANCE_CONNECTION_NAME... [flags]

Flags: -a, --address string () Address to bind Cloud SQL instance listeners. (default "127.0.0.1") --admin-port string Port for localhost-only admin server (default "9091") -i, --auto-iam-authn () Enables Automatic IAM Authentication for all instances -c, --credentials-file string Use service account key file as a source of IAM credentials. --debug Enable the admin server on localhost --disable-metrics Disable Cloud Monitoring integration (used with --telemetry-project) --disable-traces Disable Cloud Trace integration (used with --telemetry-project) --fuse string Mount a directory at the path using FUSE to access Cloud SQL instances. --fuse-tmp-dir string Temp dir for Unix sockets created with FUSE (default "/tmp/csql-tmp") -g, --gcloud-auth Use gcloud's user credentials as a source of IAM credentials. --health-check Enables health check endpoints /startup, /liveness, and /readiness on localhost. -h, --help Display help information for cloud-sql-proxy --http-address string Address for Prometheus and health check server (default "localhost") --http-port string Port for Prometheus and health check server (default "9090") --impersonate-service-account string Comma separated list of service accounts to impersonate. Last value is the target account. -j, --json-credentials string Use service account key JSON as a source of IAM credentials. --max-connections uint Limit the number of connections. Default is no limit. --max-sigterm-delay duration Maximum number of seconds to wait for connections to close after receiving a TERM signal. -p, --port int () Initial port for listeners. Subsequent listeners increment from this value. --private-ip () Connect to the private ip address for all instances --prometheus Enable Prometheus HTTP endpoint /metrics on localhost --prometheus-namespace string Use the provided Prometheus namespace for metrics --quiet Log error messages only --quota-project string Specifies the project to use for Cloud SQL Admin API quota tracking. The IAM principal must have the "serviceusage.services.use" permission for the given project. See https://cloud.google.com/service-usage/docs/overview and https://cloud.google.com/storage/docs/requester-pays --sqladmin-api-endpoint string API endpoint for all Cloud SQL Admin API requests. (default: https://sqladmin.googleapis.com) -l, --structured-logs Enable structured logging with LogEntry format --telemetry-prefix string Prefix for Cloud Monitoring metrics. --telemetry-project string Enable Cloud Monitoring and Cloud Trace with the provided project ID. --telemetry-sample-rate int Set the Cloud Trace sample rate. A smaller number means more traces. (default 10000) -t, --token string Use bearer token as a source of IAM credentials. -u, --unix-socket string (*) Enables Unix sockets for all listeners with the provided directory. --user-agent string Space separated list of additional user agents, e.g. cloud-sql-proxy-operator/0.0.1 -v, --version Print the cloud-sql-proxy version

While my input is "-instances" the error message returns "-nstances" as if it's either truncating somehow, or as if it's matching my input to the "-i" flag inadvertently.

I've tried shortening my project name to avoid truncating, and tried inputting the command inside a yaml file instead of running it in google cloud shell.


Solution

  • Looks like -instances is not a valid flag for Cloud SQL Proxy tool and hence the error.

    Remove that flag, something like below should work.

    ./cloud-sql-proxy amz-reporting-files-21:us-west1-c:api-20230212 -p 5432

    Please refer to the supported flags here.

    This is using the latest cloud-sql-proxy version 2.0.0.