-
Notifications
You must be signed in to change notification settings - Fork 513
Support async replicas #1097
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
Merged
Merged
Support async replicas #1097
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5540128
Support async replicas
N2D4 c43192b
Improvements
N2D4 cc4d3c9
Merge remote-tracking branch 'origin/dev' into async-replica
N2D4 4b6e1f5
f
N2D4 ffd466d
Delete Claude Code review
N2D4 a39a074
Merge branch 'dev' into async-replica
N2D4 f6da04c
fixes
N2D4 66694e2
Better error logging
N2D4 9e9f637
Fix tests
N2D4 b9f3d37
Fixes
N2D4 9a7601e
Merge branch 'dev' into async-replica
N2D4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| FROM postgres:15 | ||
|
|
||
| # Copy the entrypoint script | ||
| COPY entrypoint.sh /entrypoint.sh | ||
| RUN chmod +x /entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/entrypoint.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Configuration from environment variables | ||
| PRIMARY_HOST="${PRIMARY_HOST:-db}" | ||
| PRIMARY_PORT="${PRIMARY_PORT:-5432}" | ||
| REPLICATOR_USER="${REPLICATOR_USER:-replicator}" | ||
| REPLICATOR_PASSWORD="${REPLICATOR_PASSWORD:-PASSWORD-PLACEHOLDER--replicatorpass}" | ||
| RECOVERY_MIN_APPLY_DELAY="${RECOVERY_MIN_APPLY_DELAY:-100ms}" | ||
|
|
||
| echo "Starting PostgreSQL replica with ${RECOVERY_MIN_APPLY_DELAY} apply delay..." | ||
|
|
||
| # Wait for primary to be ready | ||
| echo "Waiting for primary at ${PRIMARY_HOST}:${PRIMARY_PORT}..." | ||
| until PGPASSWORD="${REPLICATOR_PASSWORD}" pg_isready -h "${PRIMARY_HOST}" -p "${PRIMARY_PORT}" -U "${REPLICATOR_USER}" 2>/dev/null; do | ||
| echo "Primary not ready yet, waiting..." | ||
| sleep 2 | ||
| done | ||
| echo "Primary is ready!" | ||
|
|
||
| # If PGDATA is empty, do a base backup from primary | ||
| if [ -z "$(ls -A ${PGDATA} 2>/dev/null)" ]; then | ||
|
N2D4 marked this conversation as resolved.
|
||
| echo "PGDATA is empty, performing base backup from primary..." | ||
|
|
||
| # Perform base backup | ||
| PGPASSWORD="${REPLICATOR_PASSWORD}" pg_basebackup \ | ||
| -h "${PRIMARY_HOST}" \ | ||
| -p "${PRIMARY_PORT}" \ | ||
| -U "${REPLICATOR_USER}" \ | ||
| -D "${PGDATA}" \ | ||
| -Fp \ | ||
| -Xs \ | ||
| -P \ | ||
| -R | ||
|
|
||
| echo "Base backup completed!" | ||
|
|
||
| # Configure recovery settings with apply delay | ||
| cat >> "${PGDATA}/postgresql.auto.conf" <<EOF | ||
|
|
||
| # Replica configuration | ||
| primary_conninfo = 'host=${PRIMARY_HOST} port=${PRIMARY_PORT} user=${REPLICATOR_USER} password=${REPLICATOR_PASSWORD}' | ||
|
N2D4 marked this conversation as resolved.
N2D4 marked this conversation as resolved.
|
||
| recovery_min_apply_delay = ${RECOVERY_MIN_APPLY_DELAY} | ||
| hot_standby = on | ||
| EOF | ||
|
|
||
| # Create standby.signal to indicate this is a standby | ||
| touch "${PGDATA}/standby.signal" | ||
|
|
||
| # Set proper permissions | ||
| chmod 700 "${PGDATA}" | ||
| chown -R postgres:postgres "${PGDATA}" | ||
|
|
||
| echo "Replica configured with ${RECOVERY_MIN_APPLY_DELAY} apply delay" | ||
| else | ||
| echo "PGDATA already initialized, starting replica..." | ||
| fi | ||
|
|
||
| # Start PostgreSQL | ||
| exec gosu postgres postgres | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.