2021-12-14 12:20:06 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
BIN = "/usr/lib/postgresql/#{ENV["PG_MAJOR"]}/bin"
|
|
|
|
DATA = "/tmp/test_data/pg"
|
|
|
|
|
|
|
|
def run(*args)
|
|
|
|
system(*args, exception: true)
|
|
|
|
end
|
|
|
|
|
2022-01-17 12:45:39 -05:00
|
|
|
should_setup = true
|
|
|
|
should_run = true
|
2021-12-14 12:20:06 -05:00
|
|
|
should_exec = false
|
|
|
|
while a = ARGV.pop
|
2022-01-17 12:45:39 -05:00
|
|
|
if a == "--skip-setup"
|
|
|
|
should_setup = false
|
|
|
|
elsif a == "--skip-run"
|
|
|
|
should_run = false
|
|
|
|
elsif a == "--exec"
|
2021-12-14 12:20:06 -05:00
|
|
|
should_exec = true
|
|
|
|
else
|
|
|
|
raise "Unknown argument #{a}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-17 12:45:39 -05:00
|
|
|
if should_setup
|
2023-09-07 01:46:23 -04:00
|
|
|
run "rm -rf #{DATA}"
|
|
|
|
run "mkdir -p #{DATA}"
|
2022-01-17 12:45:39 -05:00
|
|
|
run "#{BIN}/initdb -D #{DATA}"
|
2021-12-14 12:20:06 -05:00
|
|
|
|
2022-01-17 12:45:39 -05:00
|
|
|
run "echo fsync = off >> #{DATA}/postgresql.conf"
|
|
|
|
run "echo full_page_writes = off >> #{DATA}/postgresql.conf"
|
|
|
|
run "echo shared_buffers = 500MB >> #{DATA}/postgresql.conf"
|
|
|
|
end
|
2021-12-14 12:20:06 -05:00
|
|
|
|
|
|
|
if should_exec
|
2023-09-07 01:46:23 -04:00
|
|
|
exec "#{BIN}/postgres -D #{DATA}"
|
2022-01-17 12:45:39 -05:00
|
|
|
elsif should_run
|
2021-12-14 12:20:06 -05:00
|
|
|
run "#{BIN}/pg_ctl -D #{DATA} start"
|
|
|
|
end
|