Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 614 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
django.db.utils.OperationalError Could not connect to server

#11
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
Reply

#12
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>```
Reply

#13
## 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'
}
}
Reply

#14
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 :)

Reply

#15
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
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through