rm -fr orig_pgdata copy_pgdata 93archive
mkdir 93archive
initdb -D orig_pgdata
cat >> orig_pgdata/postgresql.conf << EOF
  wal_level = archive
  archive_command = 'test ! -f ~/tmp/93archive/%f  && cp %p ~/tmp/93archive/%f'
  archive_mode = on
  log_checkpoints = on
  log_line_prefix = '%m %p '
EOF
pg_ctl -D orig_pgdata -w start
createdb mxact

psql mxact << EOF
  UPDATE pg_database set datallowconn = true;
  CREATE EXTENSION pageinspect;
  SELECT pg_burn_multixact(2048 * 32 * 2);
EOF
psql mxact -c "SELECT pg_start_backup('foo', true)"

cp -pr orig_pgdata/ copy_pgdata/
rm -fr copy_pgdata/pg_multixact

PGOPTIONS="-c vacuum_multixact_freeze_min_age=$((2048 * 32)) \
  -c vacuum_multixact_freeze_table_age=0" vacuumdb --all

psql mxact -c CHECKPOINT

cp -pr orig_pgdata/pg_multixact copy_pgdata
psql mxact -c "SELECT pg_stop_backup()"

pg_ctl -D orig_pgdata stop

cat >> copy_pgdata/recovery.conf << EOF
restore_command = 'cp ~/tmp/93archive/%f %p'
standby_mode = on
EOF

cat >> copy_pgdata/postgresql.conf << EOF
log_error_verbosity = verbose
lc_messages = C
EOF

pg_ctl -D copy_pgdata -w start
pg_ctl -D copy_pgdata stop


