I'm receiving connect ENOENT /cloudsql/<proj>:us-west1:<instance>/.s.PGSQL.5432
When connecting to a Cloud SQL instance of PostgreSQL 15 from a Firebase V2 Callable function. I've looked everywhere and even reluctantly used ChatGPT but I cannot seem to fix the issue.
export const createUnixSocketPool = (config: DatabaseConfig) => {
return knex({
client: "pg",
connection: {
user: config.user,
password: config.password,
database: "default",
host: "/cloudsql/<proj-id>:us-west1:<instance-name>",
},
pool: { min: 0, max: 1 },
});
};
Your code configuration looks good, but the service configuration is not. You must tell to the service to open a connection with your Cloud SQL database, and then to open a unix socket for your code
I didn't find anywhere how to set up a Cloud SQL connection for Firebase Functions V2. The most appropriate documentation page is on Cloud Functions.