I am trying to determine whether a database has been initialised by executing a query and examining the exit code. If the exit code is 0 then I know that the database query has been accepted and the database should be initialised.
I cannot use
pg_isready because the postgres version is prior to 9.3 so I have developed the following code:
while (( $(su -l postgres -c "psql -d db_name -c 'select count(1) from table_name' > /dev/null 2>&1") != 0 )) do echo "waiting for database to initialise" sleep 10 done
$(su -l postgres -c "psql -d db_name -c 'select count(1) from table_name' > /dev/null 2>&1" on its own returns an exit code of 0 however I am getting an error message when it is used within the loop:
((: != 0 : syntax error: operand expected (error token is "!= 0 ")