I host Database and Django Application separately Server.
I have a Google Cloud SQL (PostgreSQL) but I tried many ways to configure Database as Django document
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'HOST': '[Your-Cloud-SQL-Public-IP]',
'USER': '[YOUR-USERNAME]',
'PASSWORD': '[YOUR-PASSWORD]',
'NAME': '[YOUR-DATABASE]',
}
}
by filling it with my credential but cannot connect got error like this:
line 729, in connect
raise ex.with_traceback(None)
django.db.utils.OperationalError: connection failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
Expert please help me to make it works.
I am looking the guideline to configure Django project with Google Cloud SQL.
For Public IP, you will need to add your Django application's IP address as an authorized network of your Cloud SQL instance.
For Private IP if you deploy your Django application within your VPC network the above sample should work as is in your settings.py
file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': '[Your-Cloud-SQL-Private-IP]',
'USER': '[YOUR-USERNAME]',
'PASSWORD': '[YOUR-PASSWORD]',
'NAME': '[YOUR-DATABASE]',
'SSLMODE': 'require'
}
}