Skip to content

Commit

Permalink
update readme and pgbouncer
Browse files Browse the repository at this point in the history
  • Loading branch information
simi committed Nov 26, 2023
1 parent d14b44b commit dd98e4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
35 changes: 19 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Online PostgreSQL migration

## testing

- get latest dump for testing, unpack and copy to rubygems.sql


## setup

- `pgbouncer` and `psql` executables must be installed (`apt-get install postgresql-client pgbouncer`)
- for local test also `tar` and `gunzip` is needed

Fill in `vars` file (per https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS).

- `OLD_CONNECTION` = connection to current DB
Expand All @@ -20,27 +18,32 @@ $ cp vars.example vars
$ source vars
```

## setup clusters (for dev testing)
## migration

```bash
./scripts/init.sh
```

## start replication
`pgbouncer` is temporarily needed for migration to hand over opened connections. Initially, it needs to be pointing to old DB. For simple setup, it is enough to reuse example config from this repository.

```bash
./scripts/replicate.sh
useradd pgbouncer
mkdir /tmp/pgb
chown -R pgbouncer:pgbouncer /tmp/pgb

cp configs/pgbouncer.ini pgbouncer.ini
echo "db = $OLD_CONNECTION" >> pgbouncer.ini
pgbouncer -d pgbouncer.ini
```

## wait unless initial replication is in sync

## testing migration locally

```bash
# download latest public_postgresql.tar from https://rubygems.org/pages/data into root folder
./scripts/init.sh # start local pg instances and pgbouncer
./scripts/replicate.sh # start replication
# wait unless initial replication is in sync, for example with following command
psql "$NEW_CONNECTION" -c "SELECT * FROM pg_stat_subscription" # only one line should be present
```

## migrate
# once ready

```bash
./scripts/pause.sh # pause old cluster and wait unless connections are gone
./scripts/lag.sh # wait unless replication is in sync
./scripts/sequences.sh # sync sequences manually
Expand Down
1 change: 0 additions & 1 deletion configs/pgbouncer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ listen_port = 5557

;; any, trust, plain, md5, cert, hba, pam
auth_type = trust
auth_file = userlist.txt

;; comma-separated list of users who are allowed to change settings
admin_users = postgres, pgbouncer
Expand Down

0 comments on commit dd98e4c

Please sign in to comment.