Skip to content
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

make it easier to run multiple clusters with the same extension installed #1736

Open
jyn514 opened this issue Jun 17, 2024 · 1 comment
Open

Comments

@jyn514
Copy link
Contributor

jyn514 commented Jun 17, 2024

postgres has a plethora of features that can only be tested with multiple clusters, the biggest one being replication. unfortunately, it is not easy to run multiple clusters with pgrx. @workingjubilee suggested setting PGRX_HOME to different values between invocations of pgrx, but that requires rebuilding and reinstalling lots of things. it would be nice to have this as a built-in feature.

i wrote a shell script to work around this in the meantime, which i look forward to burning.

i am so sorry
set -ex

data=$HOME/.pgrx/data-16
conf=$data/postgresql.conf
wal_backup=$(realpath ./wal-archive)
mkdir -p $wal_backup

cargo pgrx stop
rm -r $data ~/.pgrx/16.log standby.log
# recreate default config before we edit it
cargo pgrx start
cargo pgrx stop
# listen_addresses = ""  # already configured to localhost
echo \
"shared_preload_libraries = 'my-extension'
archive_command = 'test ! -f $wal_backup/%f && cp %p $wal_backup/%f'
archive_mode = on
archive_timeout = 5s  # this is unreasonably short, but we only use this database for testing
"  >> $conf

# create standby
rm -rf data-standby
cp -r $data data-standby
touch data-standby/standby.signal
cp $conf data-standby
echo "\
# restore_command = ''
primary_conninfo = 'postgresql://%2Fhome%2Fjyn%2F.pgrx'
port = 28817  # avoid conflicting with the primary
" >> data-standby/postgresql.conf

cargo pgrx stop
$(cargo pgrx info path 16)/bin/pg_ctl stop -D data-standby -o "-c unix_socket_directories=/home/jyn/.pgrx" || true
killall postgres || true # standby
cargo pgrx start  # make sure to do this before starting the standby so we load the right version of the .so
[ -e "/home/jyn/.pgrx/.s.PGSQL.28816" ] || exit 1
trap "cargo pgrx stop" EXIT
$(cargo pgrx info path 16)/bin/pg_ctl start -D data-standby -l standby.log -o "-c unix_socket_directories=/home/jyn/.pgrx"
trap "$(cargo pgrx info path 16)/bin/pg_ctl stop -D data-standby -o '-c unix_socket_directories=/home/jyn/.pgrx' >/dev/null" EXIT

# run queries with $(cargo pgrx info path 16)/bin/psql -p 28817 -d my-extension -h ~/.pgrx
@workingjubilee
Copy link
Member

that sure is bashed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants