I have an os x server running django 1.6 and postgresql 9.
I have just noticed that if I logout of the machine I can no longer connect to my app from another machine.
The error is:
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
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?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
I have had a look around for a solution but I can't seem to get it to work.
My django settings are:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'myuser',
'PASSWORD': 'mypw',
'HOST': 'localhost',
'PORT': '5432',
}
}
And as I say if I log in to the server with my server user i can then immediately access my web app from another machine. I hope that makes sense. It's as if postgresql runs when my user logs in.
I am assuming that postgresql runs as root / in the background despite whatever user is logged in.
Any ideas?
Related
I am trying to connect my Django project to a PostgreSQL database I created on AWS but I keep getting this error message each time I run py manage.py runserver.
Here is the error message:
django.db.utils.OperationalError: connection to server at "database-1.ce7oz69tjzjc.us-east-1.rds.amazonaws.com" (52.3.150.111), port 5432 failed: Connection timed out (0x0000274C/10060)
Is the server running on that host and accepting TCP/IP connections?
I followed the tutorial on w3school and followed all instructions. I created a PostgreSQL database then I updated my settings with the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'codekeen',
'USER': 'baseuser',
'PASSWORD': 'database',
'HOST': 'database-1.ce7oz69tjzjc.us-east-1.rds.amazonaws.com',
'PORT': '5432'
}
}
as I was told to, but I keep getting the error each time try migrating or running the server.
What do I do to fix this?
First of all, make sure that postgresql is up and running. You can check with systemctl status postgresql-xx where xx is your postgresql version. After that,You need to allow TCP/IP connections to be able to connect postgresql database. Open the postgresql.conf file
vim /etc/postgresql/8.2/main/postgresql.conf
or
vim /var/lib/pgsql/data/postgresql.conf
And set the listen addresses to "*" or IP addresses.
listen_addresses='*'
or
listen_addresses='xxx.xx.x.x'
When I`m trying to connect Django Server to PostgreSQL db there is an error:
" port 5433 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? "
I`m using Windows 10, Pycharm, Debian
Settings in Django:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'ps_store_db',
'USER': 'zesshi',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '5433',
}
}
Tried to check connection with DBeaver and all`s good there, but still cant connect with Django
My firewall is off, i was trying to change from 5432 to 5433
Dbeaver connection
Dbeaver connection 2
Try restarting/reinstalling postgres. Most likely DBeaver has blocked the port that's why you are not able to connect from django.
(Sorry for posting answer, i am unable to comment yet)
The default port of the PG database is 5432. If you need to change this port, you need to edit the postgresql.conf file and restart the database service before the client can access it.
You also need to check the pg_hba.conf file. The recommended configuration is as follows:
host all all 0.0.0.0/0 md5
I am trying to connect my local django application to amazon RDS (tried with both MySQL and PostgreSQL) but I am not able to connect as it shows the following errors, Currently seeking answer for PostgreSQL.
In my Settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'database_name',
'USERNAME': 'my_username',
'PASSWORD': 'my_password',
'HOST': 'database-abc.xxx.us-region-yyy.rds.amazonaws.com',
'PORT': '5432',
}
}
In AWS database configuration:
I get this error:
django.db.utils.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "database-abc.xxx.us-region-yyy.rds.amazonaws.com" (69.420.00.121) and accepting TCP/IP connections on port 5432?
I referred to all the available data but still am unable to resolve this issue!
Thanks in advance!
In the VPC security group go to inbound settings create a new rule with the Postgres connection type, not HTTP and make it available from every.
Note: don't forget to make accessibility to the database to be public.
I have two Ubuntu servers A and B.
Initially I had Django, postgres, celery on single server A. Everything was working fine.
Now A has Django, postgres, and B has celery and Django project installed.
DB migrations are done on A, and database connectivity is proper on A. This I can say that because when I am trying to start the celery server on server A, I am able to successfully launch the celery through the command prompt. No problem.
As per the requirements, I have to only run Django and postgres on server A, and Celery on server B.
Since I am using the same Django server settings on server B that I have in A, so the Django settings.py has the same DB connectivity settings as shown below. i.e. the DB settings are same on A and B
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'xyz',
'USER': 'smthing',
'PASSWORD': 'smthing',
'HOST': 'some_IP',
'PORT': '5432',
}
}
To see if the postgres is running or not on server A. I executed the service command
$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Thu 2021-06-10 10:57:11 IST; 1 weeks 4 days ago
Main PID: 1276 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/postgresql.service
To see if the postgres is listing on 5432, I executed netstat command:
$ netstat -nl | grep postgres
unix 2 [ ACC ] STREAM LISTENING 17357 /var/run/postgresql/.s.PGSQL.5432
If all these are happening, then why server B is throwing error as below when I am trying to start the celery?
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "server A" and accepting
TCP/IP connections on port 5432?
One thing I noticed that when I tried to telnet server A from server B, I get failed output.
telnet server A 5432
[sudo] password for username:
Trying server A...
telnet: Unable to connect to remote host: Connection refused
_ Also, please let me know if I need to have the username and password created on server B as well? i.e. the username and password which is present as a postgres user on server A.
I am trying to deploy my django app on heroku server,i followed the instructions from this website https://devcenter.heroku.com/articles/getting-started-with-python#introduction .it worked fine till , "heroku open" command.When i came to the part where i need to host my database using " heroku run python manage.py syncdb" command , it failed showing the mesage "OperationalError: 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?". I tried lots of fixes including the one suggested here Deploying Django app's local postgres database to heroku? and http://www.cyberciti.biz/tips/postgres-allow-remote-access-tcp-connection.html .I tried all the solutions including editing the "listen_address" = '*' and tcpip_socket='true' in postgresql.conf and editing the ipv4 and v6 values in pg_hba.conf to
host all all 127.0.0.1 255.255.0.1 trust
host all all 10.0.0.99/32 md5
host all all 0.0.0.0/0 .
But none of them worked .I am guessing the problem arises because heroku can not connect to my local postgres server.This is strange because i'm able to access the postgres server via pgadmin.
And also in the django settings.py looks like this
DATABASES =
{
'default':
{
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_test',
'USER': 'postgres',
'PASSWORD': '******',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '5432',
}
}
Do i need to change this and use heroku's database settings instead??
localhost on the server points to the server not your local machine. The reason why is because the server running your django code will try and resolve the dns name localhost and it has a pointer to 127.0.0.1 which is local to the server resolving that name. That will NOT point to your computer you are working on.
You need to get an instance of postgres on heroku and change HOST: 'xxx.xxx.xxx.xxx to the IP address of your new postgres instance in your django settings.