How to allow postgres to connect to Django using torify - django

I'm trying to run a Django server using torify, but when I run torify python3 manage.py runserver I get below error:
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I've already added this code to the torrc:
HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 5432 127.0.0.1:5432
HiddenServicePort 5432 localhost:5432
or even just this:
HiddenServiceDir /var/lib/tor/hidden_service/
HiddenServicePort 5432 127.0.0.1:5432
But both of them didn't work.

Related

connection to server at "localhost" (127.0.0.1), port 5432 failed

I am facing this error "OperationalError at /results/
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
Is the server running on that host and accepting TCP/IP connections?" when I try to run a django application that I just deployed in railway.app.
What is the problem and how can I fix?
When I run the application locally it works well, it is my first time deploying a django application to production and I have no idea how to solve that issue, your help is greatly appreciated.
I just realized that the error is due to not using railway's database. Apparently it was running localhost and my postgres' port, created a postgres database in railway and connected to the deployed django app and it is now working well. Thank you #Laurenz Albe for reminding me that.

How do I connect my Django App to Postgres Databse?

How do I connect my Django App to Postgres Databse?
Whenever I run python manage.py makemigrations after the changes, then I get this kind of error. How can I fix it?
Got an error checking a consistent migration history performed for database connection 'default': connection to server
at "localhost" (::1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
warnings.warn(
No changes detected
Seems like your postgres server is not running. I would suggest you to ensure that postgres server is running and you are able to connect to it.
You can use your terminal or any DB tool like PgAdmin, DBeaver, Tableplus etc.
After you are able to connect to your database through any of the above mentioned ways. Django db connection should not be a problem.
You can take help from
https://tableplus.com/blog/2018/10/how-to-start-stop-restart-postgresql-server.html
https://www.enterprisedb.com/postgres-tutorials/connecting-postgresql-using-psql-and-pgadmin

PostgreSQL: could not connect to server: Connection refused

I have a Django project, I want to switch from SQLite to PostgreSQL.
After installation, I can't run the command psql
Here is the traceback:
psql: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
OS: Windows
TCP/IP connections are not enabled by default, so you probably have to edit a file called postgres.conf:
vi /etc/postgresql/9.4/main/postgresql.conf
For you it may reside in a different location. Look for a line saying:
#listen_addresses = '' # what IP address(es) to listen on;
Change it to this:
listen_addresses = '*' # what IP address(es) to listen on;
Right under this there's the port setting. For me it reads:
port = 5432 # (change requires restart)
Higher up in the same file there is a reference to another config file:
hba_file = '/etc/postgresql/9.4/main/pg_hba.conf' # host-based authentication file
Go ahead and edit that file. You should insert a line like this:
host all all 192.168.1.0 255.255.255.0 trust
Your IP may be different. (Once you ensure this is working, you can change "trust" to "md5" for better security.) After doing this, you need to restart the postgres server.
/usr/lib/postgresql/9.4/bin/pg_ctl restart

Django retry if the database service is down

I use postgres database, and deploy my django with uwsgi and nginx
if the postgres service is not running before uwsgi and nginx , It will cause error
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: Host is down
Is the server running on host "192.168.1.21" and accepting
TCP/IP connections on port 5432?
I want to know can I retry to start the nginx and uwsgi until the postgres service is running ?

Postgresql localhost connection - Connection refused

i just installed pgadmin iii and try to connect server.
I configured my setting
name:localhost
host: 127.0.0.1
port:5432
username:postgres
but i always get this error
The server doesn't accept connection: the connection library reports
**could not connect to server : Connection refused Is server runing on host "127.0.0.1" and accepting TCP/IP connections on port 5432?
However, i'm runing django and python on 127.0.0.1 What's missing?
There's also a problem with mysql. I could not connect with them
If you change the pg_hba.conf file to accept connections (for example: "host all all 127.0.0.1 255.255.255.0 trust") it should work
Installing postgre v12 before uninstalling v11 I found the config file (postgresql.conf) had a line "port = 5433". Changing this to "port = 5432" fixed the issue for me.