skip to Main Content

I’m getting this error when I try and connect caught error @ main Error: connect ENOENT /cloudsql/<PROJECT ID>:us-central1:<DB NAME>/.s.PGSQL.5432
This is what my typeorm config file looks like

  const config2 = {
    database: <DB NAME>,
    entities: Object.values(entities),
    host: '/cloudsql/<project id>:us-central1:<db name>',
    extra: {
      socketPath: '/cloudsql/<project id>:us-central1:<db name>',
    },
    password: ...,
    port: 5432,
    type: process.env.POSTGRES_CONNECTION as DatabaseType,
    username: ...,
    synchronize: false,
    dropSchema:
      process.env.NODE_ENV !== 'production' &&
      process.env.POSTGRES_DROP_SCHEMA === 'true',
    migrations: ['dist/migrations/*.js'],
    migrationsRun: true,
    cache: shouldCache(),
  } as PostgresConnectionOptions;

I also tried to connect via a connection URL in Postico 2 and I’m getting the error Hostname not found.

I have cloud SQL API enabled in my google project

2

Answers


  1. Did you add your network? If not, postgres will not allow to connect.

    enter image description here

    enter image description here

    Try to use ‘Connections’.

    Login or Signup to reply.
  2. To connect via Postico to your Google Cloud SQL instance, you’ll need to tunnel over SSH on port 15432 using the downloadable cloud_sql_proxy executable.

    The user you’re signed-in as in your terminal needs IAM permissions of:

    Service Account Admin (or Service Account User may suffice)

    If you aren’t sure which user to give this IAM permissions to, run:

    gcloud config get account

    Once those permissions are confined, a command similar to this would establish the tunnel (note the & at the end, which is purposeful!)

    ./cloud_sql_proxy -instances=<CONNECTION_NAME>:<DB_NAME>=tcp:15432 &

    The CONNECTION_NAME can be found inside your cloud console under SQL > ‘Connect to this instance’ section.

    Now with the tunnel open, you should be able to connect inside of Postico.

    To ensure your app can connect, you may just need to assign Cloud SQL Client IAM permission to your app in the same way you assigned service account permissions to your local user.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search