Db-support » History » Version 5
Version 4 (Philippe May, 24/10/2018 11:01) → Version 5/13 (Philippe May, 24/10/2018 11:08)
h1. Database
This documentation assumes that the Postgis package has been installed (see [[CSR_server#Database]]).
h2. Configure the server
h3. Allow connections from other hosts in the local network
Add in @/etc/postgresql/9.6/main/pg_hba.conf@:
<pre>
host all all 192.168.0.0/24 md5
</pre>
h2. Creation of the database
As @postgres@ user:
<pre>
createdb -E utf8 -T template0 avgis
</pre>
h2. Backups
h3. Primary
The database is backed up every day at midnight (Thanks to Debian package @autopostgresqlbackup@). midnight. The dump file is located in @/var/backups/postgres/@.
h3. Secondary
The whole virtual machine is backed up by BackupNinja on the "dom0" controller, using:
- rdiff backups every day
- tar files on Saturdays.
See @/etc/backups.d@ on the dom0 (192.168.0.12).
h3. Tertiary
TODO: remote backup.
h2. Restoration
If the VM is not shutdown properly, there's a chance that the database is corrupt, and needs to be restored from one of the backups.
After the restoration, restart gisaf:
<pre>
systemctl restart uwsgi.service
</pre>
h3. From primary backup
With user @postgres@:
<pre>
# Optionally, rename the corrupt database (selecting a name for a database like "avgis_c2")...
psql -c "ALTER DATABASE avgis RENAME TO avgis_c2;"
# ... or drop the existing database
psql -c "drop database avgis;"
# Create a new database:
createdb -E utf8 -T template0 avgis
# Restore the database
pg_restore -d avgis /var/backups/postgres/avgis.pg_dump
</pre>
This documentation assumes that the Postgis package has been installed (see [[CSR_server#Database]]).
h2. Configure the server
h3. Allow connections from other hosts in the local network
Add in @/etc/postgresql/9.6/main/pg_hba.conf@:
<pre>
host all all 192.168.0.0/24 md5
</pre>
h2. Creation of the database
As @postgres@ user:
<pre>
createdb -E utf8 -T template0 avgis
</pre>
h2. Backups
h3. Primary
The database is backed up every day at midnight (Thanks to Debian package @autopostgresqlbackup@). midnight. The dump file is located in @/var/backups/postgres/@.
h3. Secondary
The whole virtual machine is backed up by BackupNinja on the "dom0" controller, using:
- rdiff backups every day
- tar files on Saturdays.
See @/etc/backups.d@ on the dom0 (192.168.0.12).
h3. Tertiary
TODO: remote backup.
h2. Restoration
If the VM is not shutdown properly, there's a chance that the database is corrupt, and needs to be restored from one of the backups.
After the restoration, restart gisaf:
<pre>
systemctl restart uwsgi.service
</pre>
h3. From primary backup
With user @postgres@:
<pre>
# Optionally, rename the corrupt database (selecting a name for a database like "avgis_c2")...
psql -c "ALTER DATABASE avgis RENAME TO avgis_c2;"
# ... or drop the existing database
psql -c "drop database avgis;"
# Create a new database:
createdb -E utf8 -T template0 avgis
# Restore the database
pg_restore -d avgis /var/backups/postgres/avgis.pg_dump
</pre>