I am using PostgreSql as database in my Django project. When I run it locally via pgAdmin, the data appears, but when I run it on the server, the data does not come in pgAdmin.
Django settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'xxxx',
'USER' : 'xxx',
'PASSWORD': 'xxx',
'HOST': 'pgdb',
'PORT': 5432,
}
}
docker-compose.yaml
services:
# CaddyServer reverse proxy
caddy:
restart: always
image: caddy:2-alpine
ports:
- "443:443"
command: caddy reverse-proxy --from https://xxxxxx.com --to http://0.0.0.0:8000
#volumes:
# - /local/path/to/Caddyfile:/path/inside/continer/to/Caddyfile
# networks:
# - web
# - bridge
# Django web app
django:
restart: always
build: .
ports:
- "80:8000"
depends_on:
- pgdb
#environment:
# - url=https://api.backend.example.com
#command: "gunicorn config.wsgi:application --bind 0.0.0.0:8000"
#networks:
# - bridge
pgdb:
image: postgres
container_name: pgdb
environment:
- POSTGRES_DB=xxxx
- POSTGRES_USER=xxxx
- POSTGRES_PASSWORD=xxxx
volumes:
- pg-data:/var/lib/postgresql/data/
volumes: pg-data:
I am connecting via pgAdmin server ip. The pgAdmin connection is established, but the data I entered into the system is not visible on pgAdmin.
CodePudding user response:
That's because it's not inside your postgres database, but only in pg_admin
What I'd suggest you to do is to run this command via ssh to get a list of databases:
psql -l
Once you get all the db names, and its owners, check if your db appears. If it does, try accessing it with:
psql -U your_db_username || psql -U your_db_username -d your_db_name
Access and query your tables to see if the data is indeed there.
If it's not there, what I would suggest is to dump the db with:
pg_dump -U db_username db_name > your_backup.pgsql
Afterwards, you should restore that dump through the terminal into postgres:
psql -U db_username --set ON_ERROR_STOP=on -f your_backup.pgsql
Let me know if this helped you. I can further assist you on this one if it does help in the end but you face new/other problems.