Google Cloud Run: Cant connect to Postgress SQL - django

I am following this tutorial to upload my existing Django project running locally on sqlite to Google Cloud Run / Postgres.
I have the cloud_sql_proxy service running and can sign into Postgres from the command line.
I am at the point of running the command
python manage.py migrate
And I get the error:
django.db.utils.OperationalError: connection to server on socket "/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
The answer to that questions is Yes, the server is running locally and accepting connections because I can log in with the Postgres client:
agerson#agersons-iMac ~ % psql "sslmode=disable dbname=postgres user=postgres hostaddr=127.0.0.1"
Password for user postgres:
psql (14.1, server 13.4)
Type "help" for help.
postgres=>
I double checked the connection string in my .env file and it has the correct UN / P
Is this scoket not getting created somehow in a previous step?
/cloudsql/cgps-registration-2:us-central-1:cgps-reg-2-postgre-sql/.s.PGSQL.5432

It looks like there's a mismatch between what the app is looking for and how you're launching the proxy. The error explains the problem.
You're launching the proxy like this with an incorrect region name (us-central):
cloud_sql_proxy -instances="cgps-registration-2:us-central:cgps-reg-2-postgre-sql=tcp:5432
But the app is looking for us-central1. Try this (omitting the =tcp:5432 to create a Unix socket):
cloud_sql_proxy -instances="cgps-registration-2:us-central1:cgps-reg-2-postgre-sql

Related

migration problem while hosting a django project on PythonAnywhere

I recently finished my django project and i switched my database from the local SQLite database, provided by django, to an online postgreSQL database provided by elephantSQL. Clearly, by entering my database credential in the setings.py file of my django project i am able to migrate to my new database locally while not on my host's bash console. Meaning that, when i run my server on port 8000 it loads my data from the postgreSQL, but when i push my website to PythonAnywhere and try to run my migrations from the bash console of PythonAnywhere it throws out the following error:`
django.db.utils.OperationalError: connection to server at "'USER'.db.elephantsql.com" ("DATABASE_IP"), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
`
I even changed my database Host from elephanSQL to nhost, but still it promps the same result.

Database connection Error while hosting site on heroku

So I was trying to host my first Django app on heroku.
Took help form some Youtube channels. I used postgresql as my database. Now when I tried hosting my app on heroku the following error is showing up:
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?```
**This is the error showing**
run postgres -D /usr/local/var/postgres The result of this should be:
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 379) running in data directory
"/usr/local/var/postgres"?
Then type kill -9 PID in HINT
Let me know if this works for you?

Won't create a PostgreSQL database on Unix server

I am trying to deploy my django project to a unix server. When I run the command to create the PostgreSQL database using SSH, I encounter the following error:
$ createdb elections
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Does the error mean running 'locally' as in the server or my machine?
What is stopping it from connecting to the server?
How do I fix the error?

django website working, but django manage.py cannot connect to db

I'm trying to run a django migration to update my database, but "manage.py migrate" can't connect to my postgresql db. The odd thing is: my django website (which is exactly the same code) is working including connecting to the db.
Error messages:
psycopg2.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.xxxxxx"?
and
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL
Workaround: Change HOST variable to either localhost or 127.0.0.1 .
see: https://community.webfaction.com/questions/21072/django-website-working-but-django-managepy-cannot-connect-to-db

how to start postgresql server on Ubuntu 12.04

I had just installed a PostgreSQL 9.1 on the Ubuntu 12.04 server (hosted by Amazon EWS).When I tried to launch the psql command, the following error message shows up.
psql: could not connect to server: No such file or directory Is the
server running locally and accepting connections on Unix domain
socket "/var/run/postgresql/.s.PGSQL.5432"?
After searching on the web, I found I have to start the Server before using it. By following this initdb link, I still cannot use the postgresql database. Are there any further work (like configuration) should I do to start the server ?
I tried to start the service : service postgresql start
Another error message shows :
No PostgreSQL clusters exist; see "man pg_createcluster"
I received this message running a new installation of Postgres 9.3 on Ubuntu 11.04. The full message was:
$ sudo /etc/init.d/postgresql start
Error: Cannot stat /var/run/postgresql
* No PostgreSQL clusters exist; see "man pg_createcluster"
Turned out that the /var/run/postgresql directory did not exist, and it is in that directory where it was attempting to create a file with the process ID. I created the directory as root and made the "postgres" user the owner, and I was able to start the server.
Further explanation found here:
http://www.postgresql.org/message-id/21044.1326496507#sss.pgh.pa.us