In the example below I want to delay the execution of the createuser
command until the Postgres server is up and running.
if Exec('pg_ctl', 'start -D C:\ProgramData\PostgresQL\data', '', SW_SHOW, ewWaitUntilIdle, ResultCode) then
begin
Sleep(10000);
// Create our database user
if Exec('createuser', '-w -d -R -S testdb', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
Unfortunately using an arbitrary Sleep()
is the only way I've managed to achieve this. The exWaitUntilIdle
flag unsurprisingly doesn't do the trick and delay the execution long enough (if at all).
So does anyone have a more robust way of ensuring the createuser
is not executed until the Postgres ( pg_ctl start
) server command is running, idle and ready to accept commands?
Use ewWaitUntilTerminated
flag with -w
switch :
Wait for the startup or shutdown to complete. Waiting is the default option for shutdowns, but not startups. ...
pg_ctl
returns an exit code based on the success of the startup or shutdown.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.