Postgresql
Running temporary PostgreSQL database in SD Desktop
- Request access to the tools-for-sd-connect or upload your own PostgreSQL singularity container to SD Connect. Start a SD Desktop Vitrtual Machine that has data volume that is big enough for your data.
Login to your SD Desktop, open DataGateway connection to SD Connect and open a terminal session.
- In the terminal session, cereate drectory /media/volume/psql and move to there
mkdir/media/volume/psql
cd /media/volume/psql
- Import Apptainer container containing PostreSQL
cp $HOME/Projects/SD\ connect/*/tools-for-sd-desktop/apptainer/postgres_14.2-alpine3.15.sif ./
- Create PostgreSQL environment file (pg.env) to be used.
module load nano
nano pg.env
- Add following settings to the file
export TZ=Europe/Helsinki
export POSTGRES_USER=pguser
export POSTGRES_PASSWORD=pg123
export POSTGRES_DB=mydb
export POSTGRES_INITDB_ARGS="--encoding=UTF-8"
Then save and exit nano.
- Crate directories for PostgreSQL server
mkdir pgdata
mkdir pgrun
- Start a screen session in your terminal session and launch database server using the container:
screen
apptainer run -B pgdata:/var/lib/postgresql/data -B pgrun:/var/run/postgresql -e -C --env-file pg.env postgres_14.2-alpine3.15.sif
Ctrl-a-d
The server should now continue running in the screen session.
- Open a shell session into your postgresql-container. Remember to mount the directory where you have your data ( e.g /shared-directory)
apptainer shell -B /shared-directory:/shared-directory postgres_14.2-alpine3.15.sif
Inside container, move to your data directory and star working with your database:
cd /shared-directory
psql -h localhost -p 5432 -d mydb -U pguser
For example
psql -h localhost -p 5432 -d mydb -U pguser f psql_dump_file.sql