1

I have a Django app that I built, I am trying to upload the app into the app engine, but for some reason, I am getting the error could not connect to server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket I already upload another Django app to GCP using the app engine, but this time is different; my guess is something about PostgreSQL.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'main',
        'USER': os.getenv('USERNAME'),
        'PASSWORD': os.getenv('PASSWORD'),
        'HOST': os.getenv("HOST"),
        'PORT': '5432'
    }
}

I tried removing the port, change it, etc.. locally. The app is running and can connect to the proxy; when I deploy the app, it can not connect. And I made sure I close the local connection before I deploy the app just in case. My old app is running with the same configuration except for engine 'django.db.backends.postgresql_psycopg2' The reason I change the engine here was that django postgresql

shaked
  • 561
  • 7
  • 19

2 Answers2

1

So I solved this, and this is a connection detail. The issue was that HOST was "/cloudsql/host/dbname," and on my local machine, that works fine with the cloud SQL proxy but on app engine production, that causes the error. Anyway, thank you for the answers.

shaked
  • 561
  • 7
  • 19
0

I think it depends on where Postgress is running comnpared to the app. For example, I have a postgres server running on windows. I can connect with the normal password, host, and port number. But I also develop in WSL (Sub system for Linux) as which point I still wanted to use postgres on my windows environment so i need to allow that port to recieve incoming requests.
https://serverfault.com/questions/1041981/how-can-i-connect-to-postgres-running-on-the-windows-host-from-inside-wsl2

After opening the port, I needed to specify the ipadress of my windows environment. In linux, windows is not localhost, so its like user:password@172.*.*:5432/<db_name> from the cli

This is another way to open ports to allow incoming requests. How to Allow Remote Access to PostgreSQL database

Hopefully this helps

enjoi4life411
  • 568
  • 5
  • 11
  • I agree, but my situation is slightly different cause I am using GCP SQL, and the default port is open and allows the incoming request. I am using the cloud SQL proxy, which opens a port to the cloud from the local port and is working fine. Only when I upload the server. If you know what to do in GCP to solve this, I will be happy to hear. – shaked Jun 21 '21 at 17:06