[Postgres Bash] Wait for database
Server wait for database get ready
# From https://docs.docker.com/compose/startup-order/
#!/bin/sh
# wait-for-postgres.sh
set -e
host="$1"
shift
# Login for user (`-U`) and once logged in execute quit ( `-c \q` )
# If we can not login sleep for 1 sec
until PGPASSWORD=<password> psql -h "$host" -U "<username>" -d <database> -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
# Print and execute all other arguments starting with `$1`
exec "$@"
This is a shell script written in /bin/sh
syntax. The script is designed to wait for a PostgreSQL database to become available before executing a specified command. The script takes two arguments: the hostname of the database server and the command to be executed.
The script sets an exit on error flag with set -e
. It then assigns the hostname argument to the host
variable and discards the first argument with shift
.
The script enters a loop with until
that tries to connect to the PostgreSQL server using psql
with a specific username, database name, and password. The -c '\q'
option is used to exit immediately after connecting to the database. The loop will repeat until a successful connection is made, and sleep for one second between each iteration.
When a successful connection is made, the script prints a message and uses the exec
command to execute the remaining arguments as a separate process.
Client wait for server get ready:
#!/bin/sh
set -e
until curl --silent -X GET http://server:3001/api/health ; do
echo "Waiting server container ready"
sleep 1
done
exec "$@"
相关文章
- ORA-01668: standby database requires DROP option for offline of data file ORACLE 报错 故障修复 远程处理
- ORA-01698: a clone database may only have SYSTEM rollback segment online ORACLE 报错 故障修复 远程处理
- ORA-02041: client database did not begin a transaction ORACLE 报错 故障修复 远程处理
- ORA-19966: ALTER DATABASE RECOVER STANDBY DATAFILE has been deprecated ORACLE 报错 故障修复 远程处理
- ORA-23501: refresh template cannot be instantiated for database with compatibilty equal to or less than 8.0 ORACLE 报错 故障修复 远程处理
- ORA-38700: Limit of string flashback database logs has been exceeded. ORACLE 报错 故障修复 远程处理
- ORA-38708: not enough space for first flashback database log file ORACLE 报错 故障修复 远程处理
- ORA-47962: Oracle Scheduler Job authorization for Oracle Database Vault to string on schema string already exists ORACLE 报错 故障修复 远程处理
- ORA-00090: failed to allocate memory for cluster database ORADEBUG command ORACLE 报错 故障修复 远程处理
- ORA-56934: database property DST_UPGRADE_STATE for datapump job is in an inconsistent state ORACLE 报错 故障修复 远程处理
- ORA-00402: database changes by release string cannot be used by release string ORACLE 报错 故障修复 远程处理
- ORA-00701: object necessary for warmstarting database cannot be altered ORACLE 报错 故障修复 远程处理
- ORA-01300: writable database required for specified LogMiner options ORACLE 报错 故障修复 远程处理
- ORA-02165: invalid option for CREATE DATABASE ORACLE 报错 故障修复 远程处理
- ORA-12922: concurrent ALTER DATABASE [NO] FORCE LOGGING command is running ORACLE 报错 故障修复 远程处理
- ORA-16012: database identifier mismatch ORACLE 报错 故障修复 远程处理
- ORA-16602: database must be disabled to perform this operation ORACLE 报错 故障修复 远程处理
- ORA-16621: database name for ADD DATABASE must be unique ORACLE 报错 故障修复 远程处理
- ORA-16743: cannot determine status of redo transport service for standby database “string” ORACLE 报错 故障修复 远程处理
- ORA-16794: database guard is on for primary database ORACLE 报错 故障修复 远程处理
- ORA-16801: redo transport-related property is inconsistent with database setting ORACLE 报错 故障修复 远程处理
- Oracle 视图 V$DATABASE_KEY_INFO 官方解释,作用,如何使用详细说明
- Maximizing Oracle Database Performance through Proactive Dumping(adumporacle)
- loopOracle中的循环编程:For Loop游标(oracle游标for)
- Exploring Oracle Chunk – A Database Storage Solution(oraclechunk)
- “Bin vs Oracle:The Battle for Database Supremacy”(binoracle)
- MySQL: TCP/IP Protocol for Database Management(mysqltcp)
- Oracle 00011:Unlock Your Database Potential(oracle00011)
- Oracle Database: The Ultimate Connection Guide for .NET Developers(net连接oracle)
- Maximizing Efficiency with MySQL Database Interface: A Comprehensive Guide(mysql数据库接口)