Painted-Fox / docker-postgresql

A dockerfile that produces a docker image that runs postgresql.
MIT License
72 stars 57 forks source link

If dbserver too slow to start, post_start_action() fails #9

Open paoloantinori opened 10 years ago

paoloantinori commented 10 years ago

Hi, I want to report a problem that happens on my system but not on a constant base.

Sometimes the scripts are not creating correctly the user.

I have tracked down the reason of the problem to this script

wait_for_postgres_and_run_post_start_action() {
  # Wait for postgres to finish starting up first.
  while [[ ! -e /run/postgresql/9.3-main.pid ]] ; do
inotifywait -q -e create /run/postgresql/ >> /dev/null
  done

post_start_action
}

Apparently the presence of /run/postgresql/9.3-main.pid is not enough to identify Postgres as ready to accept connections.

I have random error and logs shows that post_start_action before all the startup log entries are displayed.

I have also notice that the logic in this fork https://github.com/waterlink/docker-postgresql/blob/master/scripts/first_run.sh helps to avoid the problem.

Could you consider to change the "wait" logic?

Painted-Fox commented 10 years ago

Thank you very much for reporting this. I can't reproduce this on my environments, so please give this a try and let me know if it fixes it.

waterlink commented 10 years ago

@paoloantinori @Painted-Fox Thanks for referencing me. I think I should have created PR, but I though it was only my environment being weird.

Painted-Fox commented 10 years ago

No problem, @waterlink. I try to give credit where it's due.

paoloantinori commented 10 years ago

Working well now for me!

Thank you!

Painted-Fox commented 10 years ago

@paoloantinori Thank you for reporting and verifying!

Painted-Fox commented 10 years ago

I took this fix out, so this issue might be back. I was getting into an infinite loop, so I'm going to need to find a more elegant way to fix this.

waterlink commented 9 years ago

@Painted-Fox recently I had similar problem with other rdbms and solved it by using linux watch utility

something like: watch -e "! $COMMAND_TO_CREATE_USER" <>/dev/null. This will try to execute command each 2 seconds and will exit once it is a success.