Project

General

Profile

Db-support » History » Version 9

Philippe May, 24/10/2018 12:01

1 1 Philippe May
h1. Database
2 1 Philippe May
3 3 Philippe May
This documentation assumes that the Postgis package has been installed (see [[CSR_server#Database]]).
4 3 Philippe May
5 5 Philippe May
h2. Configure the server
6 5 Philippe May
7 5 Philippe May
h3. Allow connections from other hosts in the local network
8 5 Philippe May
9 9 Philippe May
Set the server to listen to addresses, set listen_addresses to @*@ in @/etc/postgresql/9.6/main/postgresql.conf@.
10 9 Philippe May
11 9 Philippe May
12 9 Philippe May
Allow the connections, add in @/etc/postgresql/9.6/main/pg_hba.conf@:
13 5 Philippe May
14 5 Philippe May
<pre>
15 5 Philippe May
host all all 192.168.0.0/24 md5
16 5 Philippe May
</pre>
17 5 Philippe May
18 3 Philippe May
h2. Creation of the database
19 4 Philippe May
20 3 Philippe May
As @postgres@ user:
21 4 Philippe May
22 5 Philippe May
<pre>
23 3 Philippe May
createdb -E utf8 -T template0 avgis
24 5 Philippe May
</pre>
25 1 Philippe May
26 1 Philippe May
h2. Backups
27 1 Philippe May
28 1 Philippe May
h3. Primary
29 1 Philippe May
30 7 Philippe May
The database is backed up every day at midnight. The dump file is located in @/var/backups/postgres/@.
31 7 Philippe May
32 8 Philippe May
h3. Secondary
33 8 Philippe May
34 1 Philippe May
There are other backups (daily, weekly, monthly) thanks to Debian package @autopostgresqlbackup@), located (default) in @/var/lib/autopostgresqlbackup@.
35 1 Philippe May
36 8 Philippe May
h3. Tertiary (dom0)
37 1 Philippe May
38 1 Philippe May
The whole virtual machine is backed up by BackupNinja on the "dom0" controller, using:
39 1 Philippe May
- rdiff backups every day
40 1 Philippe May
- tar files on Saturdays.
41 1 Philippe May
42 1 Philippe May
See @/etc/backups.d@ on the dom0 (192.168.0.12).
43 1 Philippe May
44 8 Philippe May
h3. Remote
45 1 Philippe May
46 1 Philippe May
TODO: remote backup.
47 1 Philippe May
48 1 Philippe May
49 1 Philippe May
h2. Restoration
50 1 Philippe May
51 1 Philippe May
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.
52 1 Philippe May
53 1 Philippe May
After the restoration, restart gisaf:
54 1 Philippe May
<pre>
55 1 Philippe May
systemctl restart uwsgi.service
56 1 Philippe May
</pre>
57 1 Philippe May
58 1 Philippe May
h3. From primary backup
59 1 Philippe May
60 8 Philippe May
*Note*: the roles aren't restored with this method.
61 8 Philippe May
62 1 Philippe May
With user @postgres@:
63 1 Philippe May
<pre>
64 2 Philippe May
# Optionally, rename the corrupt database (selecting a name for a database like "avgis_c2")...
65 1 Philippe May
psql -c "ALTER DATABASE avgis RENAME TO avgis_c2;"
66 2 Philippe May
# ... or drop the existing database
67 1 Philippe May
psql -c "drop database avgis;"
68 1 Philippe May
# Create a new database:
69 1 Philippe May
createdb -E utf8 -T template0 avgis
70 1 Philippe May
# Restore the database
71 1 Philippe May
pg_restore -d avgis /var/backups/postgres/avgis.pg_dump
72 8 Philippe May
</pre>
73 8 Philippe May
74 8 Philippe May
h3. From secondary backup
75 8 Philippe May
76 8 Philippe May
@autopostgresqlbackup@ backs up the roles in @postgres_globals@.
77 8 Philippe May
78 8 Philippe May
<pre>
79 8 Philippe May
zcat /var/lib/autopostgresqlbackup/daily/postgres_globals/postgres_globals_2018-10-24_06h25m.Wednesday.sql.gz | psql
80 8 Philippe May
zcat /var/lib/autopostgresqlbackup/daily/avgis/avgis_2018-10-24_06h25m.Wednesday.sql.gz | psql
81 1 Philippe May
</pre>