Backup and Restore¶
This document describes backup and restore processes for JChem PostgreSQL Cartridge.
Application side¶
See here the recommended methods for archiving the application side (the service jchem-psql) of JChem PostgreSQL Cartridge.
Database side¶
Here we describe three methods - SQL dump, File system backup and Online backup - as possible backup and restore processes for the database side of JChem PostgreSQL Cartridge.
SQL dump method¶
A user has to be created with *superuser *privilege to perform the processes on the database and to use it with the database instances.
In the following scripts these parameters have to be adjusted accordingly:
- user_name → the database user to use
- some_password → password for the created user
- input_db → the name of the source database
- some_database → the name of the target database
- schema_name → the schema name of the original database where the objects are stored
- table_name → the name of the table to be imported
/path/to/dump_file.dmp→ path to the directory and the file name to store the dump- molecule_column_name→ the name of the molecule type column where the index has to be created
Database dump¶
-
Backup creation
Compressed archive dump
This dump is compressed by default.Schema dump
If -Fc is not given, it will result a plain text file.Table dump
If -Fc is not given, it will result a plain text file.
-
Restore
Overriding existing database
This scenario has to be followed if the restore process is to overwrite an existing database. If there are some missing objects in the existing database, the -e switch has to be removed and just the -vc switch has to be applied instead of -vce, otherwise the command will fail.
Schema restorePrerequisites:
- schema has to be created or exists
- extensions need to be created
Table restore
Prerequisites:
- schema has to be created or exists
- extensions need to be created
-
Post-processing
After overriding existing database and after schema restore
Indexes are automatically recreated. The restored cartridge is working without requiring any post-processing.
After table restore
Manual index creation is needed.
or
File system backup method¶
-
Backup creation
Backup the PostgreSQL data from the data directory of the database and backup also the cartridge data using file system backup.
Example for PostgreSQL 17 on Ubuntu:
-
Restore
Delete the current PostgreSQL and cartridge data directories and extract the backed up tar files to restore the state:
- Post-processing
The restored cartridge is working without requiring any post-processing.
Online backup method¶
-
Backup creation
You need to set uppostgres.conf. This will tell the database to archive WAL logs into the given folder.Also you need to set up
pg_hba.confto enable replication privilege. If it is not happening from local, set up accordingly.To create an online backup you need a database user with replication or superuser privilege.
First you need to open a
psqlwindow with the above mentioned user and run the command below. This will tell the database that you are about to create a backup and stay in a consistent state from now. Until the finish command all changes go into WAL files.Then with
postgreslinux user create a base backup.After backup is done, go back to
psqland close the backup session:
-
Restore
To restore from backup, you need to copy the content of the base backup folder to the database’s data folder. In the same folder, create arecovery.signalempty file.In
postgres.conffile insertIf you have the WAL archive and want to roll database to an exact point in time also add:
Restart the database. After the recovery is done remove
recovery.signaland the recovery related lines frompostgresql.confand restart the database.
- Post-processing
If you are recovering into a new database be sure that the servicejchem-psqlis initialized by running the serviceinitcommand and then starting the service by thestartcommand.
Modification of the host and port data of the PostgreSQL server and of the application server may also be necessary before initializing the servicejchem-psql. See configuration instructions here.
After the recovery, the database will not be in sync with the cartridge index data, so you need to *reindex all the tables *containing chemindexes or sortedchemindexes.