docker icon indicating copy to clipboard operation
docker copied to clipboard

Improve PSQL wait script

Open thatnerdjosh opened this issue 10 months ago • 8 comments

Follow up to #292

  • Fix cleanup of connections while testing
  • Migrate to pg_isready

thatnerdjosh avatar Mar 31 '24 21:03 thatnerdjosh

@lathama - apologies for the back and forth - was struggling with the symlinks a bit.

This is ready for review :)

thatnerdjosh avatar Mar 31 '24 22:03 thatnerdjosh

@lathama - I don't think it's really ideal to maintain copy and paste of all those scripts, but I struggled to find a solution for that. I've ported all of the changes from the previous PR to all the new images

thatnerdjosh avatar Mar 31 '24 22:03 thatnerdjosh

The installed package postgresql-client includes a tool called pg_isready which could be used to remove a ton of complexity. I had the cycles to take a look into this. The pg_isready could be added to the entrypoint.sh and the extra Python file could be removed.

$ pg_isready --help
pg_isready issues a connection check to a PostgreSQL database.

Usage:
  pg_isready [OPTION]...

Options:
  -d, --dbname=DBNAME      database name
  -q, --quiet              run quietly
  -V, --version            output version information, then exit
  -?, --help               show this help, then exit

Connection options:
  -h, --host=HOSTNAME      database server host or socket directory
  -p, --port=PORT          database server port
  -t, --timeout=SECS       seconds to wait when attempting connection, 0 disables (default: 3)
  -U, --username=USERNAME  user name to connect as

Report bugs to <[email protected]>.
PostgreSQL home page: <https://www.postgresql.org/>

lathama avatar Apr 01 '24 00:04 lathama

Amazing - thank you @lathama - I'll migrate to this shortly

thatnerdjosh avatar Apr 01 '24 00:04 thatnerdjosh

@lathama - can you confirm if the below items are ok:

  1. This returns 0 even in the case of failed authentication
  2. There is no option to pass a DB password

This is fine if all we need to do is verify the DB is ready to accept connections, but seems less so if we want to validate a connection is actually established.

Please advise - thanks!

thatnerdjosh avatar Apr 01 '24 00:04 thatnerdjosh

Pending your feedback, I've completed the migration.

thatnerdjosh avatar Apr 01 '24 01:04 thatnerdjosh

Looking now

lathama avatar Apr 01 '24 13:04 lathama

@amh-mw - I've removed the DB_NAME override from this PR since the bulk of the changes was adding the pg_isready support. Once that is reviewed, I'll start working on the DB_NAME override :)

thatnerdjosh avatar Apr 07 '24 23:04 thatnerdjosh

I know this PR is pretty old, but I will come out against removing the python file for pg_isready in the bash script.

The Python file allows us to use configparser to read the actual odoo.conf easily and connect to the databases listed.

While this can be accomplished via bash, Python has built-in native support for reading configuration files and also gives us access to logging libraries.

I have reworked the psql wait file to do this, although the changes are included as part of a broader change to how this library functions. See #538 and https://github.com/odoo/docker/pull/539

codebykyle avatar Feb 10 '25 19:02 codebykyle