4 ms·
Here is my script to create a test instance in about 5 seconds (albeit without any tables define yet, just space for them, with a running server on that space,
by Roboprog 11y ago
Here is my script to create a test instance in about 5 seconds (albeit without any tables define yet, just space for them, with a running server on that space, and an account to create and use the tables in the DB):
(puts tablespace in folder under current directory)
<code>
#!/bin/sh -x
# create and run an empty database
# note: fails miserably if there are spaces in directory names
PGDATA=`pwd`/pgdata
export PGDATA
# make it if not there
mkdir -p $PGDATA
# clean it out if anything there
/bin/rm -rf $PGDATA/*
# set up the database directory layout
initdb
# start the server process
nohup postgres 2>&1 > postgres.log &
sleep 2
# create an empty DB/schema
createdb edrs_test_db
# create a user and password ("demo") to use for connections
psql -d edrs_test_db -c "create user guest password 'guest'"
ps auxww | grep '[p]ostgres'
echo run tail -f postgres.log to monitor database
# vi: nu ai ts=4 sw=4
# * EOF *
</code>
"edrs" is the name of an app - sub in something more applicable. I'm running this on OXS, but should work on Linux as well.
- viraptor 11y agoprotip: indent with 4 spaces to get code formatting
- AlterEgo20 11y agoWhy `nohup postgres 2>&1 > postgres.log &` instead of `pg_ctl start`? You could also use `pg_ctl -w start` to wait for proper server startup instead of `sleep 2`
- Roboprog 11y agoWhy? Ignorance. I'm used to running postmaster from years past (when not starting from an /etc script). Postmaster is now just called postgres, and it works for a disposable test instance setup. I'll look into that, though, as it sounds like the right thing vs the sleep hack.
- Roboprog 11y ago... and I put the 2>&1 in the wrong place :-( (before the file redirection instead of after)