-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support all postgres version + use server postgres version in client tools #2
base: main
Are you sure you want to change the base?
Conversation
set -euf -o pipefail | ||
|
||
cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit $rv; } | ||
trap cleanup EXIT | ||
|
||
NAME=${2:-$NAME} | ||
CONNECT_DB_URL="postgres://$USER@$HOST:$PORT/$NAME" | ||
# Extract database name from DATABASE_URL if not provided as an argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that having one variable as opposed to several ones will be easier. Plus, we try to extract the database name directly from the URL if it's not passed as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following. Where are we using several variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ipmb: The idea behind this change was to simplify things by combining multiple variables (like USER
, HOST
, PORT
, etc.) into one CONNECT_DB_URL
. This makes the code easier to manage and avoids dealing with too many individual variables.
The part where we extract the database name from DATABASE_URL
is just a fallback in case it's not passed explicitly, so it ensures everything still works without needing extra inputs.
If something's unclear or there’s a better way to handle this, happy to discuss!
postgres/Dockerfile
Outdated
@@ -1,9 +1,32 @@ | |||
FROM --platform=linux/amd64 python:3.12-alpine3.19 | |||
FROM ubuntu:22.04 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the latest debian slim
postgres/bin/dump-to-s3.sh
Outdated
|
||
if ! command -v "$PG_DUMP" &>/dev/null; then | ||
echo "Error: pg_dump for version $SERVER_VERSION is not installed." >&2 | ||
exit 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than failing hard here, let's make this a warning and default to the latest version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
postgres/bin/dump-to-s3.sh
Outdated
CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" | ||
|
||
# Get PostgreSQL server version | ||
SERVER_VERSION=$(psql "$CONNECT_DB_URL" -tAc "SHOW server_version;" | cut -d '.' -f 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to run this in the entrypoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I moved this to the entrypoint.sh
script.
postgres/bin/entrypoint.sh
Outdated
echo " PORT=$PORT" | ||
echo " NAME=$NAME" | ||
echo " USER=$USER" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to keep this DEBUG output in the final PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this is still in progress, because CI was failing. I'll fix this up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed now.
set -euf -o pipefail | ||
|
||
cleanup() { rv=$?; if [ -f /tmp/db.dump ]; then shred -u /tmp/db.dump; fi; exit $rv; } | ||
trap cleanup EXIT | ||
|
||
NAME=${2:-$NAME} | ||
CONNECT_DB_URL="postgres://$USER@$HOST:$PORT/$NAME" | ||
# Extract database name from DATABASE_URL if not provided as an argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not following. Where are we using several variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Left a few minor comments. Can you also add docs on how to update when new PG versions are released?
postgres/Dockerfile
Outdated
ln -s /usr/lib/postgresql/$version/bin/pg_dump /usr/bin/pg_dump-$version && \ | ||
ln -s /usr/lib/postgresql/$version/bin/pg_restore /usr/bin/pg_restore-$version; \ | ||
done && \ | ||
# Use a virtual environment to install Python packages |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the virtualenv here. You can install on the system. There may be an apt installable version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was an issue when I was trying to install it system-wide (but I might be wrong since it has been some time I did this). I'll give it another try.
CONNECT_DB_URL="${DATABASE_URL%/*}/$DBNAME" | ||
|
||
# Use SERVER_VERSION set by the entrypoint | ||
PG_DUMP="pg_dump-$SERVER_VERSION" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this work if $SERVER_VERSION
is not supplied? It can default to the latest version.
@ipmb Added the docs here: postgres/docs/support-newer-postgres-versions.md |
|
||
echo "Waiting for PostgreSQL server to be ready..." | ||
until psql "$DATABASE_URL" -c '\q' 2>/dev/null || [ "$retries" -eq 0 ]; do | ||
echo "PostgreSQL is unavailable - sleeping ($((retries--)) retries left)..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove " sleeping " please
done | ||
|
||
if [ "$retries" -eq 0 ]; then | ||
echo "ERROR: PostgreSQL server did not become ready in time." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ERROR: PostgreSQL server did not respond.
exit 1 | ||
fi | ||
|
||
echo "PostgreSQL server is ready!" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this one please
and running the script against a PostgreSQL 18 server. | ||
3. Ensure fallback compatibility: | ||
Test the script with no `SERVER_VERSION` set to confirm it falls back to the latest version. | ||
4. Update `dump-to-s3.sh` script's `SERVER_VERSION` default value if the new version becomes the default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's referenced in load-to-s3.sh
too
Verify that the new version works by setting `SERVER_VERSION` to the new version (e.g., `18`) | ||
and running the script against a PostgreSQL 18 server. | ||
3. Ensure fallback compatibility: | ||
Test the script with no `SERVER_VERSION` set to confirm it falls back to the latest version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the automated tests do 2 & 3?
Fixes #1