{"id":17454129,"url":"https://github.com/palfrey/wait-for-db","last_synced_at":"2025-09-22T07:31:39.911Z","repository":{"id":36432488,"uuid":"217764627","full_name":"palfrey/wait-for-db","owner":"palfrey","description":"Tool to wait until a database is up and responding to a query","archived":false,"fork":false,"pushed_at":"2024-11-07T23:20:40.000Z","size":278,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T15:35:23.724Z","etag":null,"topics":["database","docker","odbc","postgres"],"latest_commit_sha":null,"homepage":"https://tevps.net/blog/2019/11/22/solving-dockers-wait-for-database-problem/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palfrey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-26T20:19:43.000Z","updated_at":"2025-02-25T12:05:58.000Z","dependencies_parsed_at":"2024-04-05T17:29:18.532Z","dependency_job_id":"004389e8-f889-461f-87c4-0cbdc7b8cf24","html_url":"https://github.com/palfrey/wait-for-db","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/palfrey/wait-for-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palfrey%2Fwait-for-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palfrey%2Fwait-for-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palfrey%2Fwait-for-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palfrey%2Fwait-for-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palfrey","download_url":"https://codeload.github.com/palfrey/wait-for-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palfrey%2Fwait-for-db/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276367042,"owners_count":25629964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-22T02:00:08.972Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","docker","odbc","postgres"],"created_at":"2024-10-18T01:15:02.470Z","updated_at":"2025-09-22T07:31:39.657Z","avatar_url":"https://github.com/palfrey.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"wait-for-db\n===========\n[![Linux](https://github.com/palfrey/wait-for-db/workflows/Linux/badge.svg)](https://github.com/palfrey/wait-for-db/actions?query=workflow%3ALinux)\n\nBasically, [wait-for-it](https://github.com/vishnubob/wait-for-it) but for databases.\n\nOften ([especially within Dockerised configurations](https://docs.docker.com/compose/startup-order/)) there is the problem of \"I need the database to be up before step X will work\". Now, if all you need is \"up\" then generally wait-for-it and the database port is enough. If on the other hand you've got migration scripts or other such things you need to run on your database, up isn't enough.\n\nwait-for-db lets you wait for a particular database to be both up (in the sense of \"will let you connect without errors\") and optionally \"returns at least one row to a particular query\". It will also attempt to fail immediately for permanent failures (e.g. syntax errors)\n\nUsage\n-----\n1. Download static binary from https://github.com/palfrey/wait-for-db/releases into your Docker image\n2. `./wait-for-db \u003coptions\u003e`\n\nOptions\n-------\n* `-m/--mode`: `postgres` or `odbc`\n* `-c/--connection-string`: Mode-appropriate connection string. So `postgresql://\u003cusername\u003e:\u003cpassword\u003e@\u003chost\u003e:\u003cport\u003e` or `Driver=\u003cpath to driver\u003e;\u003cvarious ODBC options\u003e` depending on your driver\n* `-s/--sql-query`: SQL query to run once connected. It should return at least one row, or will be regarded as failing. Default is no query, just be regarded as succeeding the moment it connects.\n* `-p/--pause`: Pause between attempts for non-permanent failures. Default is 3 seconds\n* `-t/--timeout`: Time to wait before failing entirely. Default is wait forever.\n\nDatabase support\n----------------\n* Anything you've got an [ODBC](https://en.wikipedia.org/wiki/Open_Database_Connectivity) driver for (which should be most SQL databases)\n* Postgres\n\nDevelopment\n-----------\nTo test the Postgres/ODBC support do the following\n\n1. Generate a server.key and server.crt (so we can test TLS links)\n\n```\nopenssl req -new -text -passout pass:abcd -subj /CN=localhost -out server.req\nopenssl rsa -in privkey.pem -passin pass:abcd -out server.key\nopenssl req -x509 -in server.req -text -key server.key -out server.crt\n```\n\n2. Set postgres (alpine) user as owner of the server.key and permissions to 600\n\n```\nsudo chown 0:70 server.key\nsudo chmod 640 server.key\n```\n\n3. Start a postgres docker container, mapping the .key and .crt into the image.\n\n```\ndocker run -p 5432 \\\n  -v \"$PWD/server.crt:/var/lib/postgresql/server.crt:ro\" \\\n  -v \"$PWD/server.key:/var/lib/postgresql/server.key:ro\" \\\n  -e POSTGRES_HOST_AUTH_METHOD=trust \\\n  postgres:11-alpine \\\n  -c ssl=on \\\n  -c ssl_cert_file=/var/lib/postgresql/server.crt \\\n  -c ssl_key_file=/var/lib/postgresql/server.key\n```\n\n4. Find the port exported by the docker container and export it as `POSTGRES_PORT` e.g. `export POSTGRES_PORT=32768`\n\nOn macOS:\n\n5. `brew install psqlodbc sqliteodbc`\n6. ``POSTGRES_SERVER=localhost POSTGRES_USERNAME=postgres POSTGRES_PASSWORD= RUST_BACKTRACE=1 POSTGRES_DRIVER=`brew --prefix psqlodbc`/lib/psqlodbca.so SQLITE_DRIVER=`brew --prefix sqliteodbc`/lib/libsqlite3odbc-0.9996.dylib cargo test -- --nocapture``\n\nOn Debian\n\n5. `sudo apt-get install odbc-postgresql libsqliteodbc`\n6. ``ODBC_SYS_STATIC_PATH=/usr/lib/x86_64-linux-gnu/ POSTGRES_SERVER=localhost POSTGRES_USERNAME=postgres POSTGRES_PASSWORD= RUST_BACKTRACE=1 POSTGRES_DRIVER=/usr/lib/x86_64-linux-gnu/odbc/psqlodbca.so SQLITE_DRIVER=/usr/lib/x86_64-linux-gnu/odbc/libsqlite3odbc-0.9996.so cargo test -- --nocapture``\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalfrey%2Fwait-for-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalfrey%2Fwait-for-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalfrey%2Fwait-for-db/lists"}