So i have NodeJS application with PostgreSQL which i wanted to host on GCP. Ive created instance of GCP SQL and i can sucessfully connect to it via PGadmin but i cannot connect via my code used on GCP App Engine.
Here is my data about GCP SQL instance
<code>Connection to instance
Connection name
xyz-xyz-444412:europe-central2:gcp-sql-database-name
Private IP Connections
Disabled
Connections using a public IP address
Enabled
Public IP address
12.123.123.23
Outgoing IP Address
33.333.27.157
Default TCP Database Port Number
5432
</code>
<code>Connection to instance
Connection name
xyz-xyz-444412:europe-central2:gcp-sql-database-name
Private IP Connections
Disabled
Connections using a public IP address
Enabled
Public IP address
12.123.123.23
Outgoing IP Address
33.333.27.157
Default TCP Database Port Number
5432
</code>
Connection to instance
Connection name
xyz-xyz-444412:europe-central2:gcp-sql-database-name
Private IP Connections
Disabled
Connections using a public IP address
Enabled
Public IP address
12.123.123.23
Outgoing IP Address
33.333.27.157
Default TCP Database Port Number
5432
And below is my code trying to connect to this database
<code>const { Pool, types } = require('pg');
types.setTypeParser(1114, str => str);
types.setTypeParser(1184, str => str);
const pool = new Pool({
user: 'postgres',
host: `/cloudsql/xyz-xyz-444412:europe-central2:gcp-sql-database-name`,
database: 'database-name-created-in-pgadmin',
password: 'password',
port: 5432,
});
module.exports = pool;
</code>
<code>const { Pool, types } = require('pg');
types.setTypeParser(1114, str => str);
types.setTypeParser(1184, str => str);
const pool = new Pool({
user: 'postgres',
host: `/cloudsql/xyz-xyz-444412:europe-central2:gcp-sql-database-name`,
database: 'database-name-created-in-pgadmin',
password: 'password',
port: 5432,
});
module.exports = pool;
</code>
const { Pool, types } = require('pg');
types.setTypeParser(1114, str => str);
types.setTypeParser(1184, str => str);
const pool = new Pool({
user: 'postgres',
host: `/cloudsql/xyz-xyz-444412:europe-central2:gcp-sql-database-name`,
database: 'database-name-created-in-pgadmin',
password: 'password',
port: 5432,
});
module.exports = pool;
and in app.yaml i have
<code>runtime: nodejs20
env: standard
instance_class: F1
beta_settings:
cloud_sql_instances: "xyz-xyz-444412:europe-central2:gcp-sql-database-name"
</code>
<code>runtime: nodejs20
env: standard
instance_class: F1
beta_settings:
cloud_sql_instances: "xyz-xyz-444412:europe-central2:gcp-sql-database-name"
</code>
runtime: nodejs20
env: standard
instance_class: F1
beta_settings:
cloud_sql_instances: "xyz-xyz-444412:europe-central2:gcp-sql-database-name"
I dont believe this a problem with configuration as i added to service account multiple roles. Here are my logs i get from application
<code>"POST /login HTTP/1.1" 302
2024-12-14 15:44:23 default[20241214t154235] Couldn't find such user Error: getaddrinfo ENOTFOUND xyz-xyz-444412:europe-central2:gcp-sql-database-name
2024-12-14 15:44:23 default[20241214t154235] at /workspace/node_modules/pg-pool/index.js:45:11
2024-12-14 15:44:23 default[20241214t154235] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-12-14 15:44:23 default[20241214t154235] at async findByUsername (/workspace/models/user.js:17:24)
2024-12-14 15:44:23 default[20241214t154235] at async login (/workspace/controllers/authController.js:7:22) {
2024-12-14 15:44:23 default[20241214t154235] errno: -3008,
2024-12-14 15:44:23 default[20241214t154235] code: 'ENOTFOUND',
2024-12-14 15:44:23 default[20241214t154235] syscall: 'getaddrinfo',
2024-12-14 15:44:23 default[20241214t154235] hostname: 'xyz-xyz-444412:europe-central2:gcp-sql-database-name'
2024-12-14 15:44:23 default[20241214t154235] }
</code>
<code>"POST /login HTTP/1.1" 302
2024-12-14 15:44:23 default[20241214t154235] Couldn't find such user Error: getaddrinfo ENOTFOUND xyz-xyz-444412:europe-central2:gcp-sql-database-name
2024-12-14 15:44:23 default[20241214t154235] at /workspace/node_modules/pg-pool/index.js:45:11
2024-12-14 15:44:23 default[20241214t154235] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-12-14 15:44:23 default[20241214t154235] at async findByUsername (/workspace/models/user.js:17:24)
2024-12-14 15:44:23 default[20241214t154235] at async login (/workspace/controllers/authController.js:7:22) {
2024-12-14 15:44:23 default[20241214t154235] errno: -3008,
2024-12-14 15:44:23 default[20241214t154235] code: 'ENOTFOUND',
2024-12-14 15:44:23 default[20241214t154235] syscall: 'getaddrinfo',
2024-12-14 15:44:23 default[20241214t154235] hostname: 'xyz-xyz-444412:europe-central2:gcp-sql-database-name'
2024-12-14 15:44:23 default[20241214t154235] }
</code>
"POST /login HTTP/1.1" 302
2024-12-14 15:44:23 default[20241214t154235] Couldn't find such user Error: getaddrinfo ENOTFOUND xyz-xyz-444412:europe-central2:gcp-sql-database-name
2024-12-14 15:44:23 default[20241214t154235] at /workspace/node_modules/pg-pool/index.js:45:11
2024-12-14 15:44:23 default[20241214t154235] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2024-12-14 15:44:23 default[20241214t154235] at async findByUsername (/workspace/models/user.js:17:24)
2024-12-14 15:44:23 default[20241214t154235] at async login (/workspace/controllers/authController.js:7:22) {
2024-12-14 15:44:23 default[20241214t154235] errno: -3008,
2024-12-14 15:44:23 default[20241214t154235] code: 'ENOTFOUND',
2024-12-14 15:44:23 default[20241214t154235] syscall: 'getaddrinfo',
2024-12-14 15:44:23 default[20241214t154235] hostname: 'xyz-xyz-444412:europe-central2:gcp-sql-database-name'
2024-12-14 15:44:23 default[20241214t154235] }