When connecting directly to a PostgreSQL Cloud SQL instance the password is required:
> psql --host=12.34.56.78 --dbname=mydb --username=postgres
Password for user postgres:
psql (17.2)
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off, ALPN: PostgreSQL)
Type "help" for help.
mydb=>
When connecting with Cloud SQL Studio from the Console it is also required.
But when connecting through the Cloud SQL Auth Proxy it is not asked:
> psql --dbname=mydb --username=postgres
psql (17.2)
WARNING: Console code page (850) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
mydb=>
Why is that so?
EDIT: as requested, here are the commands:
> gcloud sql instances create --database-version POSTGRES_17 --tier db-perf-optimized-N-2 test-sql
WARNING: Starting with release 233.0.0, you will need to specify either a region or a zone to create an instance.
Creating Cloud SQL instance for POSTGRES_17...done.
Created [https://sqladmin.googleapis.com/sql/v1beta4/projects/test-gcp-123456/instances/test-sql].
NAME DATABASE_VERSION LOCATION TIER PRIMARY_ADDRESS PRIVATE_ADDRESS STATUS
test-sql POSTGRES_17 us-central1-c db-perf-optimized-N-2 12.345.678.910 - RUNNABLE
> gcloud sql databases create test-db --instance test-sql
Creating Cloud SQL database...done.
Created database [test-db].
instance: test-sql
name: test-db
project: test-gcp-123456
> gcloud sql users set-password postgres --instance test-sql --password postgres
Updating Cloud SQL user...done.
> gcloud sql instances describe test-sql --format='get(connectionName)'
test-gcp-123456:us-central1:test-sql
> C:\Users\orbsv\Downloads\cloud-sql-proxy.x64.exe test-gcp-123456:us-central1:test-sql
2025/01/22 20:37:59 Authorizing with Application Default Credentials
2025/01/22 20:38:01 [test-gcp-123456:us-central1:test-sql] Listening on 127.0.0.1:5432
2025/01/22 20:38:01 The proxy has started successfully and is ready for new connections!
But I was not able to reproduce from another machine, I thought some environment variable like PGPASSWORD might provide the password implicitly but I don't see it defined.
So I wonder where it could be "cached".
Note:Cloud SQL Auth proxy is used as a Cloud SQL connector that provides secure access to your instances without a need for Authorized networks or for configuring SSL. You can refer to Documentation to know how Cloud SQL Auth Proxy works.