Skip to content
Snippets Groups Projects
Commit 7e36e068 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added script for correctly restoring the database from a dump recreating the generated columns

parent 611eaa8b
No related branches found
No related tags found
No related merge requests found
...@@ -5,3 +5,15 @@ ...@@ -5,3 +5,15 @@
This repository defines the VOSpace database structure. This repository defines the VOSpace database structure.
It consists in a PostgreSQL database with the [ltree](https://www.postgresql.org/docs/12/ltree.html) extension. SQL files are named starting with a number because they are put in a Docker image where they have to be executed in order. It consists in a PostgreSQL database with the [ltree](https://www.postgresql.org/docs/12/ltree.html) extension. SQL files are named starting with a number because they are put in a Docker image where they have to be executed in order.
## Dump and restore
To restore the file catalog from a dump it is necessary to drop the generated columns and regenerate them after the import. This can be done using the restore_db.sh script located in the dump_and_restore folder of this repository.
To obtain a data only dump of the database use the following command:
pg_dump -h <hostname> -U postgres --data-only --format=tar vospace_testdb > mydump.tar
Then you can use the restore script in the following way:
./restore_db.sh -U postgres -h 127.0.0.1 -p 5432 -d vospace_testdb mydump.tar
\ No newline at end of file
ALTER TABLE node ADD COLUMN path ltree GENERATED ALWAYS AS (path(parent_path, node_id)) STORED;
CREATE INDEX file_path_gist_idx ON node USING GIST(path);
CREATE UNIQUE INDEX file_path_idx ON node USING btree(path);
ALTER TABLE node ADD COLUMN relative_path ltree GENERATED ALWAYS AS (path(parent_relative_path, node_id)) STORED;
CREATE INDEX file_rel_path_gist_idx ON node USING GIST(relative_path);
DELETE FROM node;
ALTER SEQUENCE node_node_id_seq RESTART WITH 1;
-- Generated columns need to be dropped and generated again. This causes also path support views to be dropped
ALTER TABLE node DROP COLUMN path CASCADE;
ALTER TABLE node DROP COLUMN relative_path CASCADE;
#!/bin/bash
user="postgres"
host="localhost"
port="5432"
database="postgres"
while [[ "$#" -gt 0 ]]; do
case $1 in
-U) user="$2"; shift ;;
-h) host="$2"; shift ;;
-p) port="$2"; shift ;;
-d) database="$2"; shift ;;
*) dump_file="$1" ;;
esac
shift
done
if [ -z "$dump_file" ]; then
echo "Specify dump file as last argument"
exit 1
fi
psql -U $user -h $host -p $port $database < pre-restore.sql
pg_restore -U $user -h $host -p $port -d $database $dump_file
psql -U $user -h $host -p $port $database < path-indexes.sql
psql -U $user -h $host -p $port $database < ../02-views.sql
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment