It can't connect to Database using default settings. #57

Open
opened 2025-12-28 23:24:55 +01:00 by adam · 4 comments
Owner

Originally created by @rhesadaiva on GitHub (Aug 24, 2025).

I installed WYGIWYH via docker-compose, using this docker-compose (totally copied from docker-compose.prod.yml)

services:
  web:
    image: eitchtee/wygiwyh:latest
    container_name: ${SERVER_NAME}
    command: /start-single
    ports:
      - "${OUTBOUND_PORT}:8000"
    env_file:
      - .env
    depends_on:
      - db
    restart: unless-stopped

  db:
    image: postgres:15
    container_name: ${DB_NAME}
    restart: unless-stopped
    volumes:
      - ./postgres_data:/var/lib/postgresql/data/
    environment:
      - POSTGRES_USER=${SQL_USER}
      - POSTGRES_PASSWORD=${SQL_PASSWORD}
      - POSTGRES_DB=${SQL_DATABASE}

and using this .env based on .env.example (almost identically except the SQL_PASSWORD and SECRET_KEY)

SERVER_NAME=wygiwyh_server
DB_NAME=wygiwyh_pg

TZ=UTC 

DEBUG=false
HTTPS_ENABLED=false
SECRET_KEY=HESOYAMZ
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
OUTBOUND_PORT=9005

SQL_DATABASE=wygiwyh
SQL_USER=wygiwyh
SQL_PASSWORD=klapaucius
SQL_HOST=${DB_NAME}
SQL_PORT=5432

WEB_CONCURRENCY=4

# App Configs
# Enable this if you want to keep deleted transactions in the database
ENABLE_SOFT_DELETE=false
# If ENABLE_SOFT_DELETE is true, transactions deleted for more than KEEP_DELETED_TRANSACTIONS_FOR days will be truly deleted. Set to 0 to keep all.
KEEP_DELETED_TRANSACTIONS_FOR=365

TASK_WORKERS=1 # This only work if you're using the single container option. Increase to have more open queues via procrastinate, you probably don't need to increase this.

# OIDC Configuration. Uncomment the lines below if you want to add OIDC login to your instance
#OIDC_CLIENT_NAME=""
#OIDC_CLIENT_ID=""
#OIDC_CLIENT_SECRET=""
#OIDC_SERVER_URL=""
#OIDC_ALLOW_SIGNUP=true

and i'm running it using docker-compose up -d. When i want to continue to next step, which is docker compose exec -it web python manage.py createsuperuser, i got this error

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 256, in connect
    self.connection = self.get_new_connection(conn_params)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 332, in get_new_connection
    connection = self.Database.connect(**conn_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/psycopg/connection.py", line 118, in connect
    raise last_ex.with_traceback(None)
psycopg.OperationalError: connection failed: connection to server at "172.18.0.2", port 5432 failed: FATAL:  password authentication failed for user "wygiwyh"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/app/manage.py", line 22, in <module>
    main()
  File "/usr/src/app/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 416, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 90, in execute
    return super().execute(*args, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute
    self.check_migrations()
  File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 587, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 58, in __init__
    self.build_graph()
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 235, in build_graph
    self.applied_migrations = recorder.applied_migrations()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 89, in applied_migrations
    if self.has_table():
       ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 63, in has_table
    with self.connection.cursor() as cursor:
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 320, in cursor
    return self._cursor()
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 296, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 278, in ensure_connection
    with self.wrap_database_errors:
  File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 256, in connect
    self.connection = self.get_new_connection(conn_params)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 332, in get_new_connection
    connection = self.Database.connect(**conn_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/psycopg/connection.py", line 118, in connect
    raise last_ex.with_traceback(None)
django.db.utils.OperationalError: connection failed: connection to server at "172.18.0.2", port 5432 failed: FATAL:  password authentication failed for user "wygiwyh"

It seems the dockerhub images can't acknowledge the env. Is there any step maybe i've missed?

Originally created by @rhesadaiva on GitHub (Aug 24, 2025). I installed WYGIWYH via docker-compose, using this docker-compose (totally copied from docker-compose.prod.yml) ``` services: web: image: eitchtee/wygiwyh:latest container_name: ${SERVER_NAME} command: /start-single ports: - "${OUTBOUND_PORT}:8000" env_file: - .env depends_on: - db restart: unless-stopped db: image: postgres:15 container_name: ${DB_NAME} restart: unless-stopped volumes: - ./postgres_data:/var/lib/postgresql/data/ environment: - POSTGRES_USER=${SQL_USER} - POSTGRES_PASSWORD=${SQL_PASSWORD} - POSTGRES_DB=${SQL_DATABASE} ``` and using this .env based on .env.example (almost identically except the SQL_PASSWORD and SECRET_KEY) ``` SERVER_NAME=wygiwyh_server DB_NAME=wygiwyh_pg TZ=UTC DEBUG=false HTTPS_ENABLED=false SECRET_KEY=HESOYAMZ DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] OUTBOUND_PORT=9005 SQL_DATABASE=wygiwyh SQL_USER=wygiwyh SQL_PASSWORD=klapaucius SQL_HOST=${DB_NAME} SQL_PORT=5432 WEB_CONCURRENCY=4 # App Configs # Enable this if you want to keep deleted transactions in the database ENABLE_SOFT_DELETE=false # If ENABLE_SOFT_DELETE is true, transactions deleted for more than KEEP_DELETED_TRANSACTIONS_FOR days will be truly deleted. Set to 0 to keep all. KEEP_DELETED_TRANSACTIONS_FOR=365 TASK_WORKERS=1 # This only work if you're using the single container option. Increase to have more open queues via procrastinate, you probably don't need to increase this. # OIDC Configuration. Uncomment the lines below if you want to add OIDC login to your instance #OIDC_CLIENT_NAME="" #OIDC_CLIENT_ID="" #OIDC_CLIENT_SECRET="" #OIDC_SERVER_URL="" #OIDC_ALLOW_SIGNUP=true ``` and i'm running it using `docker-compose up -d`. When i want to continue to next step, which is `docker compose exec -it web python manage.py createsuperuser`, i got this error ``` Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection self.connect() File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 256, in connect self.connection = self.get_new_connection(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 332, in get_new_connection connection = self.Database.connect(**conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/psycopg/connection.py", line 118, in connect raise last_ex.with_traceback(None) psycopg.OperationalError: connection failed: connection to server at "172.18.0.2", port 5432 failed: FATAL: password authentication failed for user "wygiwyh" The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/src/app/manage.py", line 22, in <module> main() File "/usr/src/app/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 416, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 90, in execute return super().execute(*args, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 459, in execute self.check_migrations() File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 587, in check_migrations executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 18, in __init__ self.loader = MigrationLoader(self.connection) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 58, in __init__ self.build_graph() File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 235, in build_graph self.applied_migrations = recorder.applied_migrations() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 89, in applied_migrations if self.has_table(): ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 63, in has_table with self.connection.cursor() as cursor: ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 320, in cursor return self._cursor() ^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 296, in _cursor self.ensure_connection() File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 278, in ensure_connection with self.wrap_database_errors: File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 279, in ensure_connection self.connect() File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 256, in connect self.connection = self.get_new_connection(conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 332, in get_new_connection connection = self.Database.connect(**conn_params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/psycopg/connection.py", line 118, in connect raise last_ex.with_traceback(None) django.db.utils.OperationalError: connection failed: connection to server at "172.18.0.2", port 5432 failed: FATAL: password authentication failed for user "wygiwyh" ``` It seems the dockerhub images can't acknowledge the env. Is there any step maybe i've missed?
adam added the question label 2025-12-28 23:24:55 +01:00
Author
Owner

@eitchtee commented on GitHub (Aug 24, 2025):

That's weird... everything seems to be right. Maybe you created the database with another password and then changed it in the env file?

Try deleting or moving ./postgres_data so we can get a fresh database instance:

docker compose down
rm -rf ./postgres_data 
docker compose up -d

Make sure you're in WYGIWYH's folder. This will delete any data you have, but you probably don't have any. Let me know how it goes.

@eitchtee commented on GitHub (Aug 24, 2025): That's weird... everything seems to be right. Maybe you created the database with another password and then changed it in the env file? Try deleting or moving `./postgres_data` so we can get a fresh database instance: ```bash docker compose down rm -rf ./postgres_data docker compose up -d ``` Make sure you're in WYGIWYH's folder. This will delete any data you have, but you probably don't have any. Let me know how it goes.
Author
Owner

@rhesadaiva commented on GitHub (Aug 25, 2025):

I've done all the steps, but it still can't acknowledge the .env. The steps i've done:

  1. Copy all the docker-compose.prod.yml content into file called docker-compose.yml , and the .env.example into .env (i'm not cloning the repo)
  2. run it using docker compose up -d

I've tried to delete the ./postgres_data folder to create a fresh database instance again, and yep still got the same error. Is there any step i've missed?

@rhesadaiva commented on GitHub (Aug 25, 2025): I've done all the steps, but it still can't acknowledge the .env. The steps i've done: 1. Copy all the `docker-compose.prod.yml` content into file called `docker-compose.yml` , and the `.env.example` into `.env` (i'm not cloning the repo) 2. run it using docker compose up -d I've tried to delete the `./postgres_data` folder to create a fresh database instance again, and yep still got the same error. Is there any step i've missed?
Author
Owner

@eitchtee commented on GitHub (Aug 25, 2025):

I've tried setting up an instance using your provided docker-compose.yml and .env files, and it worked out of the box. So there's something strange going on with your setup.

Try doing this (make sure you're on the same folder as your docker-compose):

  1. Run docker compose exec -it db bash
  2. Something like root@4597f3dfc838:/# will appear, type psql -U wygiwyh and press Enter
  3. Something like wygiwyh=# will appear, type: ALTER ROLE wygiwyh WITH PASSWORD 'klapaucius'; and press Enter
  4. Type exit, press enter, then type exit again and press enter, this will return you to your normal enviroment.

This will change the password of the database user wygiwyh to 'klapaucius' as you set on your .env. Restart the containers and see if the connection is working again.


If the steps below still doesn't work:

  1. Delete everything from your existing WYGIWYH folder, preferebly delete the entire folder and recreate it
  2. Recreate the docker-compose.yml and .env files with the content you specified in this issue
  3. Run docker compose up -d
  4. Wait a few minutes
  5. Run docker compose logs
  6. Copy the full output and paste it here
@eitchtee commented on GitHub (Aug 25, 2025): I've tried setting up an instance using your provided docker-compose.yml and .env files, and it worked out of the box. So there's something strange going on with your setup. Try doing this (make sure you're on the same folder as your docker-compose): 1. Run `docker compose exec -it db bash` 2. Something like `root@4597f3dfc838:/#` will appear, type `psql -U wygiwyh` and press Enter 3. Something like `wygiwyh=#` will appear, type: `ALTER ROLE wygiwyh WITH PASSWORD 'klapaucius';` and press Enter 4. Type `exit`, press enter, then type `exit` again and press enter, this will return you to your normal enviroment. This will change the password of the database user wygiwyh to 'klapaucius' as you set on your .env. Restart the containers and see if the connection is working again. --- If the steps below still doesn't work: 1. **Delete everything** from your existing WYGIWYH folder, preferebly delete the entire folder and recreate it 2. Recreate the docker-compose.yml and .env files with the content you specified in this issue 3. Run `docker compose up -d` 4. Wait a few minutes 5. Run `docker compose logs` 6. Copy the full output and paste it here
Author
Owner

@doody commented on GitHub (Oct 5, 2025):

Just an update from my side, I was facing the same issue setting up my WYGIWYH instance, and I was having the exact same error yesterday, trying remove folders, restart containers etc., after a while, I realize it's because my container is running on a HDD based NAS and it took a while for PostgreSQL DB to initialize, you can try waiting for few min and take a look at the logs, mine took 5 min until my app entering into READY state. Hope this helps

@doody commented on GitHub (Oct 5, 2025): Just an update from my side, I was facing the same issue setting up my WYGIWYH instance, and I was having the exact same error yesterday, trying remove folders, restart containers etc., after a while, I realize it's because my container is running on a HDD based NAS and it took a while for PostgreSQL DB to initialize, you can try waiting for few min and take a look at the logs, mine took 5 min until my app entering into READY state. Hope this helps
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#57