69π
It can be some issues:
- PostgreSQL is not running. Check it with sudo
service postgresql status
-
Your PostgresSQl is not running on port 5432. You can check it typing
sudo netstat -nl | grep postgres
-
You have something wrong trying to connect to your db like the username, the password or the databasename. Check that they are what postgres ask for you to connect it and that is the db_name that you want to access to.
-
Problems with postmaster.pid in postgres. It can happen because of a shutdown unproperly done. It makes to remind a pid alive that doesnβt allow your server start. To fix it you have to:
* rm /usr/local/var/postgres/postmaster.pid * pg_resetxlog -f /usr/local/var/postgres
After this it should run properly if you make the runserver of postgres
Help in Mac OSX: How to start PostgreSQL server on Mac OS X?
7π
Try killing all postgres processes. Im on a MAC and this solution that Iβve found on ubuntus forum really works.
https://askubuntu.com/questions/547434/how-to-nicely-stop-all-postgres-processes
- [Django]-Managing static files for multiple apps in Django
- [Django]-Handle `post_save` signal in celery
- [Django]-Set language within a django view
7π
For Windows
Go to search bar and just write βOpen psql
β and hit Enter.
Once screen is opened, rerun django project.
- [Django]-Django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))
- [Django]-What is the use of PYTHONUNBUFFERED in docker file?
- [Django]-ImproperlyConfiguredError about app_name when using namespace in include()
5π
In my case, all was set up well and Postgres had the right port, PostgreSQL was running normally, but the 5432 port was being shared with phppgadmin, I could access the phppgadmin that gives me web access to Postgres database server, but my Django application was not working it would return Connection refused error. so I changed the port number on the phppgadmin config file (/etc/phppgadmin/config.inc.php) to 5433 from 5432 and all worked fine.
- [Django]-How do I drop a table from SQLite3 in DJango?
- [Django]-Django query filter combining AND and OR with Q objects don't return the expected results
- [Django]-In Django β Model Inheritance β Does it allow you to override a parent model's attribute?
4π
In MacOS I stopped and restarted postgresql according to the advice given in this StackExchange answer:
https://dba.stackexchange.com/a/171580/182403
brew services stop postgresql
rm /usr/local/var/postgres/postmaster.pid # adjust path accordingly to your install
brew services start postgresql
- [Django]-How do I display the Django '__all__' form errors in the template?
- [Django]-What's the difference between ContentType and MimeType?
- [Django]-Django rest framework serializing many to many field
3π
In project_folder/settings.py under DATABASE
β HOST
settings you should use local IP (127.0.0.1) not your public IP.
Correct
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'yourdb',
'USER': 'youruser',
'PASSWORD': 'yourpass',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}
Incorrect
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'yourdb',
'USER': 'youruser',
'PASSWORD': 'yourpass',
'HOST': '188.252.196.234 ',
'PORT': '5432'
}
}
- [Django]-How can I use redis with Django?
- [Django]-Detect django testing mode
- [Django]-ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0
3π
I had the same issue. This error occurs when an improper system shutdown has been done. Iβm on an M1, and Iβve installed PostgreSQL via Homebrew.
I tried to start PostgreSQL after receiving an error identical to yours using brew services start postgresql
, but I got this error:
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/adithraghav/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` exited with 5.
So, I tried to stop the running instance and start it again with brew services restart postgresql
.
This line gave me the following output:
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
I checked the port on which PostgreSQL was running with sudo netstat -nl | grep postgres
, but received no output.
So I deleted the existing postmaster.pid
file with this:
rm /opt/homebrew/var/postgres/postmaster.pid
NOTE: If you are not on an M1 Mac, you have to run rm /usr/local/var/postgres/postmaster.pid
.
Then, I ran pg_resetwal -f /opt/homebrew/var/postgres
to reset the write-ahead log. (NOTE: From Postgres 10 and onwards, pg_resetxlog
has been renamed to pg_resetwal
).
Now, python3 manage.py runserver
works with no issues π
- [Django]-How to mix queryset results?
- [Django]-How to change the Django admin filter to use a dropdown instead of list?
- [Django]-Django most efficient way to count same field values in a query
2π
The following command works for me (Windows)-
pg_ctl -D "C:\Program Files\PostgreSQL\11\data" restart
Then run server again-
python manage.py runserver
- [Django]-Django: show a ManyToManyField in a template?
- [Django]-Profiling Django
- [Django]-Non-global middleware in Django
- [Django]-Django: Calculate the Sum of the column values through query
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
- [Django]-How can I handle Exceptions raised by dango-social-auth?
2π
In case you are seeing this error while using PostgresSQL from Google Cloud follow all configurations as mentioned in
https://cloud.google.com/python/django/flexible-environment#macos-64-bit
Also separate the HOST configuration as below
DATABASES[βdefaultβ][βHOSTβ] = β/cloudsql/β
if os.getenv(βGAE_INSTANCEβ):
pass
else:
DATABASES[βdefaultβ][βHOSTβ] = β127.0.0.1β
This helps in resolving this error.
- [Django]-Where should signal handlers live in a django project?
- [Django]-Django removing object from ManyToMany relationship
- [Django]-Django β makemigrations β No changes detected
- [Django]-Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'
- [Django]-How to stop autopep8 not installed messages in Code
- [Django]-Django ModelForm to have a hidden input
1π
You might not connecting to the right database. If you are using Docker be sure you are using 5432 as port at the outside of the image.
eg:
db:
image: postgres:12.0-alpine
volumes:
β postgres_data:/var/lib/postgresql/data/
env_file:
β ./postgres/.env
ports:
β 5432:5432
- [Django]-Django: using more than one database with inspectdb?
- [Django]-Django Selective Dumpdata
- [Django]-In Django, how does one filter a QuerySet with dynamic field lookups?
1π
One problem that I found common with Django/Postgres (especially with Docker) is that your Django Web App maybe starting up before your Postgres server starts up. If the other solutions donβt work, try to restart your Django App after start up. With Docker, the command would be docker restart <web-app container name>
- [Django]-Efficient way to update multiple fields of Django model object
- [Django]-ImportError: cannot import name 'six' from 'django.utils'
- [Django]-Empty Label ChoiceField Django
1π
You have to enable listen addresses if you are using remote database.
cd /etc/postgresql/12.x/main/
open file named postgresql.conf
sudo nano postgresql.conf
add this line to that file
listen_addresses = '*'
then an open a file named pg_hba.conf
sudo nano pg_hba.conf
and add this line to that file
host all all 0.0.0.0/0 md5
restart your server
sudo /etc/init.d/postgresql restart
- [Django]-Django: Catching Integrity Error and showing a customized message using template
- [Django]-How can I allow django admin to set a field to NULL?
- [Django]-Render HTML to PDF in Django site
0π
check if the port is in use. I fixed this stopping my postgre service in windows from services.msc
- [Django]-What is the best location to put templates in django project?
- [Django]-How can I modify Procfile to run Gunicorn process in a non-standard folder on Heroku?
- [Django]-Custom validation in Django admin