source: server/databases/upgradedb.xml

lazarus
Last change on this file was ab4fdfc, checked in by Pierre Labastie <pierre.labastie@…>, 4 months ago

Change all xml decl to encoding=utf-8

  • Property mode set to 100644
File size: 11.3 KB
RevLine 
[ab4fdfc]1<?xml version="1.0" encoding="UTF-8"?>
[bcdfc53]2<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
4 <!ENTITY % general-entities SYSTEM "../../general.ent">
5 %general-entities;
6]>
7
8<sect1 id="upgradedb" xreflabel="Upgrade Database">
9 <?dbhtml filename="upgradedb.html"?>
10
11
[fe9a4337]12 <title>Important Notes About Upgrading Database Server Software</title>
[7f6bf79b]13
[d86ea4b]14 <note><para>This section is about reinstalling database software
15 when an existing database is in use. It is not applicable for
16 initial installations or if there is no existing database for
[7a9a7b26]17 the package being updated, but users should read through it
[b3ba4f9]18 to become aware of issues that can arise in the future.</para></note>
[d86ea4b]19
[fe9a4337]20 <para>Let's start this chapter with a dramatic screenshot of an error that
21 really happened. This error will not occur if you are installing database
22 software for the first time:</para>
[bcdfc53]23
24<screen>$ sudo systemctl status postgresql
25-- postgresql.service - PostgreSQL database server
26 Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
27 Active: failed (Result: exit-code) since Tue 2021-10-26 17:11:53 CDT; 2min 49s ago
28 Process: 17336 ExecStart=/usr/bin/pg_ctl -s -D ${PGROOT}/data start -w -t 120 (code=exited, status=1/FAILURE)
29 CPU: 7ms
30
31Oct 26 17:11:53 SVRNAME systemd[1]: Starting PostgreSQL database server...
[7a9a7b26]32Oct 26 17:11:53 SRVNAME postgres[17338]: 2021-10-26 17:11:53.420 CDT [17338] FATAL:
[d86ea4b]33 database files are incompatible with server
[7a9a7b26]34Oct 26 17:11:53 SRVNAME postgres[17338]: 2021-10-26 17:11:53.420 CDT [17338] DETAIL:
[d86ea4b]35 The data directory was initialized by PostgreSQL version 13,
36 which is not compatible with this version 14.0.
[bcdfc53]37Oct 26 17:11:53 SRVNAME postgres[17336]: pg_ctl: could not start server
38Oct 26 17:11:53 SRVNAME postgres[17336]: Examine the log output.
39Oct 26 17:11:53 SRVNAME systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
40Oct 26 17:11:53 SRVNAME systemd[1]: postgresql.service: Failed with result 'exit-code'.
41Oct 26 17:11:53 SRVNAME systemd[1]: Failed to start PostgreSQL database server.</screen>
42
43 <para>
[fe9a4337]44 To avoid situations like this (i.e., your database server
45 software refuses to start), read the following discussion of the best way to
46 upgrade a DBMS (Database Management System).
[bcdfc53]47 </para>
[d86ea4b]48
[bcdfc53]49 <para>
[fe9a4337]50 The root cause of the error shown above was an upgrade
51 of the server software to a newer major version which left the
52 data files untouched. In this case, the administrator was able to recover
53 the DBMS without any loss of data.
[7f6bf79b]54 </para>
[d86ea4b]55
[7f6bf79b]56 <para>
[a1743b1]57 Even if you are doing an initial DBMS install, read through this
[fe9a4337]58 section. It provides information about implementing backup
59 and restore procedures (or at least a strategy for creating
60 them) which will satisfy your needs and guarantee the safety
[bcdfc53]61 of your data.
62 </para>
[8986fa9]63
[bcdfc53]64 <sect2>
[fe9a4337]65 <title>Upgrade Database Server Packages</title>
[bcdfc53]66
67 <para>
[d86ea4b]68 Database systems work on files which hold the database metadata and the
[fe9a4337]69 data itself. The internal structure of these files is optimized for use
70 by the server software. When such server software is upgraded,
71 the new software may utilize a different file format than
72 had previously been used. Sometimes the new software can
[a1743b1]73 work with the old format as well as the new one&mdash;but without the
[fe9a4337]74 performance improvements the new format provides.
75 Other times, the new server software will
76 reformat the data files automatically after the upgrade.
[bcdfc53]77 </para>
78
79 <para>
[b9c353b]80 Unfortunately, the most likely case is that the new server software
[fe9a4337]81 complains about out of date file formats and exits. When this happens,
82 and you have overwritten the old server software, you may end up
83 with a broken system and lost data.
[bcdfc53]84 </para>
85
86 <para>
[fe9a4337]87 Changes in data file formats usually happen at major version changes, but
88 they can also occur at other times. Before upgrading any DBMS
89 software, check the documentation to see if this upgrade makes changes which
[d86ea4b]90 require reformatting the database.
[bcdfc53]91 </para>
92
93 <para>
[fe9a4337]94 Of course, if you have databases with content that is not easily
95 rebuilt, it is always a good idea to create backups of the database from
96 time to time. Before upgrading the server software, you should run
[d86ea4b]97 another backup.
[bcdfc53]98 </para>
99
100 <sect3>
[fe9a4337]101 <title>Upgrade by Backup and Restore</title>
[bcdfc53]102
103 <note>
104 <para>
[fe9a4337]105 A backup is useless if there is no verified process
[bcdfc53]106 to restore the data from this backup. When running a
[fe9a4337]107 database server, you should not only create backups; you
108 should also verify that the restore process
109 really works. The time to test the restore procedure
110 is <emphasis>before</emphasis> you urgently need
111 to recover lost data.
[bcdfc53]112 </para>
113 </note>
114
115 <para>
[fe9a4337]116 Most database server software provides some basic
[d86ea4b]117 tools to create backups of your data. Usually the backups created with
118 those tools can be read by newer versions of the software (via a
[54d58907]119 restore tool). Using older restore tools with newer backup data is
[fe9a4337]120 a bad idea; you should <emphasis>never</emphasis> blindly assume that
[d86ea4b]121 it will work. It might, but usually it doesn't.
[bcdfc53]122 </para>
123
124 <para>
[d86ea4b]125 The easiest way to upgrade your database files is to
[bcdfc53]126 </para>
127
128 <itemizedlist>
[4e207bb]129 <listitem>
[bcdfc53]130 <para>Create a full database backup using the old tools.</para>
[7a9a7b26]131
[fe9a4337]132 <para>This step creates an offline copy of the database files&mdash;for
133 long term archiving, for disaster recovery, or as
134 preparation for an upgrade. This offline backup consists of either (1) a full
135 one-to-one copy of the current database files, or (2) a full backup of the
136 database files from a certain point in time, plus all the journal data (that is
[d86ea4b]137 Oracle&reg; terminology, it is called "Continuous Archiving" or
[fe9a4337]138 "write ahead log (WAL)" in Postgresql) describing the
139 changes made after that point in time. This second form takes less time to create
140 (if the DB software provides this type of journaling) because you only have
141 to save the data that have changed since the last full backup was created.</para>
142
143 <para>When upgrading database server software, a full backup
[d86ea4b]144 (which can be used for subsequent incremental backups) should be
[fe9a4337]145 created; but if there is a lot of data, an incremental backup will
146 suffice. The best strategy for you depends on
[d86ea4b]147 the amount of data stored in your database (is it a few hundred table
[fe9a4337]148 rows, or is it hundreds of terabytes?). A full backup in the latter case
[54d58907]149 can't be done quickly. To
[fe9a4337]150 fully protect your data, create a backup of the old
151 programs (and/or their sources) and save it, along with the data
152 files, to be certain there is a fallback solution if
153 the new software cannot read the old data.</para>
[7a9a7b26]154 </listitem>
[d86ea4b]155
[7a9a7b26]156 <listitem>
157 <para>Upgrade the server software</para>
[d86ea4b]158
159 <para>In this step, instructions to build the database server
160 software are executed just as they are shown in subsequent sections
161 talking about the DBMs like MariaDB or Postgresql. That is, build
[7a9a7b26]162 the software as usual using BLFS instructions.</para>
163 </listitem>
[d86ea4b]164
[7a9a7b26]165 <listitem>
166 <para>Restore the database by using the new tools.</para>
[d86ea4b]167
168 <para>To restore the data, the tools of the newly installed server
169 software should be used. During the restoration process, the new
170 tools will create and/or upgrade the data files in the format the
[fe9a4337]171 new software requires. It is assumed that newer software is capable of
[d86ea4b]172 reading old data.</para>
[7a9a7b26]173 </listitem>
[d86ea4b]174 </itemizedlist>
[bcdfc53]175
176 <para>
[fe9a4337]177 Since you already have a backup procedure in place (and you
[d86ea4b]178 have tested your restore procedure, right?), this might
[fe9a4337]179 be the easiest way to upgrade as you can use your well known
[5f729f8]180 processes to upgrade just as you always do&mdash;at least in terms
[bcdfc53]181 of the backup and restore.
182 </para>
183
184 </sect3>
185
186 <sect3>
[fe9a4337]187 <title>Upgrade the Database Files by Using System Tools</title>
[bcdfc53]188
189 <para>
[d86ea4b]190 Some database systems (for instance Postgresql) provide
191 a tool which can reformat (upgrade) the existing database
[54d58907]192 files to the new format.
[fe9a4337]193 If you need to restore from a backup (for example, running
194 the upgrade tool failed) you will have to reinstall the old software
195 to recover your data.
[bcdfc53]196 </para>
197
198 <para>
[fe9a4337]199 Even though the reformatting tools might work as advertised,
200 you should create a full backup before running them. A failure
201 could cause serious damage to the database.
[bcdfc53]202 </para>
203
204 </sect3>
205
206 </sect2>
207
208 <sect2>
[fe9a4337]209 <title>Notes for Specific DBMS</title>
[8986fa9]210
[bcdfc53]211 <sect3>
212 <title>PostgreSQL</title>
[8986fa9]213
[bcdfc53]214 <!-- might add some advanced notes for the DBMS here -->
215
[d86ea4b]216 <para>Upstream documentation for Backup/Restore:
[bcdfc53]217 <ulink url="https://www.postgresql.org/docs/current/backup.html"/>
218 </para>
[8986fa9]219
[bcdfc53]220 </sect3>
221
222 <sect3>
223 <title>MariaDB</title>
[8986fa9]224
[bcdfc53]225 <!-- might add some advanced notes for the DBMS here -->
226
[d86ea4b]227 <para>Upstream documentation for Backup/Restore:
[bcdfc53]228 <ulink url="https://mariadb.com/kb/en/backup-and-restore-overview/"/>
229 </para>
[8986fa9]230
231 </sect3>
232
233 <sect3>
234 <title>Sqlite</title>
235
236 <!-- might add some advanced notes for the DBMS here -->
237
[d86ea4b]238 <para>Do not underestimate <application>Sqlite</application>. It is a
[fe9a4337]239 feature-rich DBMS. The main difference from the two big players above is
[d86ea4b]240 that Sqlite does not provide access via a network API. Sqlite databases
[fe9a4337]241 are always stored on the machine running the program which
[d86ea4b]242 uses the database. The manipulation of data content is done via API calls
[8986fa9]243 to library functions directly within the program.</para>
244
[d86ea4b]245 <para>In the upstream documentation you may find the following
246 useful:</para>
[8986fa9]247
248 <para>Documentation of the sqlite3 command line tool:
249 <ulink url="https://www.sqlite.org/cli.html"/>
250 </para>
[d86ea4b]251
[8986fa9]252 <para>Documentation of backup API calls:
253 <ulink url="https://www.sqlite.org/backup.html"/>
254 </para>
255
[2c87187]256 <para>Unfortunately, there is no dedicated chapter in the
[fe9a4337]257 upstream documentation talking about backup/restore, but
[d86ea4b]258 there are several articles about it on the
[fe9a4337]259 Internet. Here is an example.</para>
[8986fa9]260
[d86ea4b]261 <para>Documentation for Backup/Restore:
[8986fa9]262 <ulink url="https://database.guide/backup-sqlite-database/"/>
263 </para>
264
[bcdfc53]265 </sect3>
266
[8986fa9]267 <sect3>
[89c2d25]268 <title>LMDB</title>
[8986fa9]269
270 <!-- might add some advanced notes for the DBMS here -->
271
[fe9a4337]272 <para>Like <application>Sqlite</application>, this
273 software acts on local database files; there is no
[d86ea4b]274 network interface.</para>
[8986fa9]275
[89c2d25]276 <para>The relevant resources to back up/restore a LMDB database
277 are the man pages for <filename>mdb_dump</filename> and its
278 counterpart <filename>mdb_load</filename>.</para>
[8986fa9]279
280 </sect3>
[bcdfc53]281 </sect2>
[8986fa9]282
[bcdfc53]283</sect1>
Note: See TracBrowser for help on using the repository browser.