Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for the database to be ready #1019

Open
jogobeny opened this issue Oct 9, 2022 · 0 comments
Open

Checking for the database to be ready #1019

jogobeny opened this issue Oct 9, 2022 · 0 comments
Labels
backend Backend related task/PR nice to have nice to have things, not urgent for the milestone

Comments

@jogobeny
Copy link
Contributor

jogobeny commented Oct 9, 2022

Sometimes I get this error:

(txmatching) [jogobeny@archlinux txmatching]$ make setup-small-non-empty-db
make setup-empty-db
make[1]: Entering directory '/home/jogobeny/Documents/txmatching'
docker-compose stop db || true
[+] Running 1/0
 ⠿ Container txmatching-db-1  Stopped                                                                                                                                                                    0.0s
docker-compose rm -f db || true
Going to remove txmatching-db-1
[+] Running 1/0
 ⠿ Container txmatching-db-1  Removed                                                                                                                                                                    0.0s
docker volume rm txmatching_txmatching-postgres || true
txmatching_txmatching-postgres
docker-compose up -d db
[+] Running 2/2
 ⠿ Volume "txmatching_txmatching-postgres"  Created                                                                                                                                                      0.0s
 ⠿ Container txmatching-db-1                Started                                                                                                                                                      1.0s
sleep 2
make migrate-db
make[2]: Entering directory '/home/jogobeny/Documents/txmatching'
cd txmatching && PYTHONPATH=${PYTHONPATH:-..} POSTGRES_USER=super-cool-txmatching POSTGRES_PASSWORD=super-secret-pwd POSTGRES_DB=txmatching POSTGRES_URL=localhost:5432 python database/migrate_db.py
Traceback (most recent call last):
  File "/home/jogobeny/Documents/txmatching/txmatching/database/migrate_db.py", line 60, in <module>
    migrate_db()
  File "/home/jogobeny/Documents/txmatching/txmatching/database/migrate_db.py", line 43, in migrate_db
    backend = get_backend(acceptable_db_uri)
  File "/home/jogobeny/.conda/envs/txmatching/lib/python3.10/site-packages/yoyo/connections.py", line 99, in get_backend
    backend = backend_class(parsed, migration_table)
  File "/home/jogobeny/.conda/envs/txmatching/lib/python3.10/site-packages/yoyo/backends.py", line 165, in __init__
    self._connection = self.connect(dburi)
  File "/home/jogobeny/.conda/envs/txmatching/lib/python3.10/site-packages/yoyo/backends.py", line 706, in connect
    return self.driver.connect(**kwargs)
  File "/home/jogobeny/.conda/envs/txmatching/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL:  the database system is starting up

Maybe we can add checking for the database to be ready?

https://stackoverflow.com/questions/62904304/psycopg2-operationalerror-fatal-the-database-system-is-starting-up-docker

https://www.postgresql.org/docs/current/app-pg-isready.html

@jogobeny jogobeny added backend Backend related task/PR nice to have nice to have things, not urgent for the milestone labels Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related task/PR nice to have nice to have things, not urgent for the milestone
Projects
None yet
Development

No branches or pull requests

1 participant