1 | <?xml version="1.0" encoding="UTF-8"?>
|
---|
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 |
|
---|
12 | <title>Important Notes About Upgrading Database Server Software</title>
|
---|
13 |
|
---|
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
|
---|
17 | the package being updated, but users should read through it
|
---|
18 | to become aware of issues that can arise in the future.</para></note>
|
---|
19 |
|
---|
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>
|
---|
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 |
|
---|
31 | Oct 26 17:11:53 SVRNAME systemd[1]: Starting PostgreSQL database server...
|
---|
32 | Oct 26 17:11:53 SRVNAME postgres[17338]: 2021-10-26 17:11:53.420 CDT [17338] FATAL:
|
---|
33 | database files are incompatible with server
|
---|
34 | Oct 26 17:11:53 SRVNAME postgres[17338]: 2021-10-26 17:11:53.420 CDT [17338] DETAIL:
|
---|
35 | The data directory was initialized by PostgreSQL version 13,
|
---|
36 | which is not compatible with this version 14.0.
|
---|
37 | Oct 26 17:11:53 SRVNAME postgres[17336]: pg_ctl: could not start server
|
---|
38 | Oct 26 17:11:53 SRVNAME postgres[17336]: Examine the log output.
|
---|
39 | Oct 26 17:11:53 SRVNAME systemd[1]: postgresql.service: Control process exited, code=exited, status=1/FAILURE
|
---|
40 | Oct 26 17:11:53 SRVNAME systemd[1]: postgresql.service: Failed with result 'exit-code'.
|
---|
41 | Oct 26 17:11:53 SRVNAME systemd[1]: Failed to start PostgreSQL database server.</screen>
|
---|
42 |
|
---|
43 | <para>
|
---|
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).
|
---|
47 | </para>
|
---|
48 |
|
---|
49 | <para>
|
---|
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.
|
---|
54 | </para>
|
---|
55 |
|
---|
56 | <para>
|
---|
57 | Even if you are doing an initial DBMS install, read through this
|
---|
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
|
---|
61 | of your data.
|
---|
62 | </para>
|
---|
63 |
|
---|
64 | <sect2>
|
---|
65 | <title>Upgrade Database Server Packages</title>
|
---|
66 |
|
---|
67 | <para>
|
---|
68 | Database systems work on files which hold the database metadata and the
|
---|
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
|
---|
73 | work with the old format as well as the new one—but without the
|
---|
74 | performance improvements the new format provides.
|
---|
75 | Other times, the new server software will
|
---|
76 | reformat the data files automatically after the upgrade.
|
---|
77 | </para>
|
---|
78 |
|
---|
79 | <para>
|
---|
80 | Unfortunately, the most likely case is that the new server software
|
---|
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.
|
---|
84 | </para>
|
---|
85 |
|
---|
86 | <para>
|
---|
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
|
---|
90 | require reformatting the database.
|
---|
91 | </para>
|
---|
92 |
|
---|
93 | <para>
|
---|
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
|
---|
97 | another backup.
|
---|
98 | </para>
|
---|
99 |
|
---|
100 | <sect3>
|
---|
101 | <title>Upgrade by Backup and Restore</title>
|
---|
102 |
|
---|
103 | <note>
|
---|
104 | <para>
|
---|
105 | A backup is useless if there is no verified process
|
---|
106 | to restore the data from this backup. When running a
|
---|
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.
|
---|
112 | </para>
|
---|
113 | </note>
|
---|
114 |
|
---|
115 | <para>
|
---|
116 | Most database server software provides some basic
|
---|
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
|
---|
119 | restore tool). Using older restore tools with newer backup data is
|
---|
120 | a bad idea; you should <emphasis>never</emphasis> blindly assume that
|
---|
121 | it will work. It might, but usually it doesn't.
|
---|
122 | </para>
|
---|
123 |
|
---|
124 | <para>
|
---|
125 | The easiest way to upgrade your database files is to
|
---|
126 | </para>
|
---|
127 |
|
---|
128 | <itemizedlist>
|
---|
129 | <listitem>
|
---|
130 | <para>Create a full database backup using the old tools.</para>
|
---|
131 |
|
---|
132 | <para>This step creates an offline copy of the database files—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
|
---|
137 | Oracle® terminology, it is called "Continuous Archiving" or
|
---|
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
|
---|
144 | (which can be used for subsequent incremental backups) should be
|
---|
145 | created; but if there is a lot of data, an incremental backup will
|
---|
146 | suffice. The best strategy for you depends on
|
---|
147 | the amount of data stored in your database (is it a few hundred table
|
---|
148 | rows, or is it hundreds of terabytes?). A full backup in the latter case
|
---|
149 | can't be done quickly. To
|
---|
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>
|
---|
154 | </listitem>
|
---|
155 |
|
---|
156 | <listitem>
|
---|
157 | <para>Upgrade the server software</para>
|
---|
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
|
---|
162 | the software as usual using BLFS instructions.</para>
|
---|
163 | </listitem>
|
---|
164 |
|
---|
165 | <listitem>
|
---|
166 | <para>Restore the database by using the new tools.</para>
|
---|
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
|
---|
171 | new software requires. It is assumed that newer software is capable of
|
---|
172 | reading old data.</para>
|
---|
173 | </listitem>
|
---|
174 | </itemizedlist>
|
---|
175 |
|
---|
176 | <para>
|
---|
177 | Since you already have a backup procedure in place (and you
|
---|
178 | have tested your restore procedure, right?), this might
|
---|
179 | be the easiest way to upgrade as you can use your well known
|
---|
180 | processes to upgrade just as you always do—at least in terms
|
---|
181 | of the backup and restore.
|
---|
182 | </para>
|
---|
183 |
|
---|
184 | </sect3>
|
---|
185 |
|
---|
186 | <sect3>
|
---|
187 | <title>Upgrade the Database Files by Using System Tools</title>
|
---|
188 |
|
---|
189 | <para>
|
---|
190 | Some database systems (for instance Postgresql) provide
|
---|
191 | a tool which can reformat (upgrade) the existing database
|
---|
192 | files to the new format.
|
---|
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.
|
---|
196 | </para>
|
---|
197 |
|
---|
198 | <para>
|
---|
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.
|
---|
202 | </para>
|
---|
203 |
|
---|
204 | </sect3>
|
---|
205 |
|
---|
206 | </sect2>
|
---|
207 |
|
---|
208 | <sect2>
|
---|
209 | <title>Notes for Specific DBMS</title>
|
---|
210 |
|
---|
211 | <sect3>
|
---|
212 | <title>PostgreSQL</title>
|
---|
213 |
|
---|
214 | <!-- might add some advanced notes for the DBMS here -->
|
---|
215 |
|
---|
216 | <para>Upstream documentation for Backup/Restore:
|
---|
217 | <ulink url="https://www.postgresql.org/docs/current/backup.html"/>
|
---|
218 | </para>
|
---|
219 |
|
---|
220 | </sect3>
|
---|
221 |
|
---|
222 | <sect3>
|
---|
223 | <title>MariaDB</title>
|
---|
224 |
|
---|
225 | <!-- might add some advanced notes for the DBMS here -->
|
---|
226 |
|
---|
227 | <para>Upstream documentation for Backup/Restore:
|
---|
228 | <ulink url="https://mariadb.com/kb/en/backup-and-restore-overview/"/>
|
---|
229 | </para>
|
---|
230 |
|
---|
231 | </sect3>
|
---|
232 |
|
---|
233 | <sect3>
|
---|
234 | <title>Sqlite</title>
|
---|
235 |
|
---|
236 | <!-- might add some advanced notes for the DBMS here -->
|
---|
237 |
|
---|
238 | <para>Do not underestimate <application>Sqlite</application>. It is a
|
---|
239 | feature-rich DBMS. The main difference from the two big players above is
|
---|
240 | that Sqlite does not provide access via a network API. Sqlite databases
|
---|
241 | are always stored on the machine running the program which
|
---|
242 | uses the database. The manipulation of data content is done via API calls
|
---|
243 | to library functions directly within the program.</para>
|
---|
244 |
|
---|
245 | <para>In the upstream documentation you may find the following
|
---|
246 | useful:</para>
|
---|
247 |
|
---|
248 | <para>Documentation of the sqlite3 command line tool:
|
---|
249 | <ulink url="https://www.sqlite.org/cli.html"/>
|
---|
250 | </para>
|
---|
251 |
|
---|
252 | <para>Documentation of backup API calls:
|
---|
253 | <ulink url="https://www.sqlite.org/backup.html"/>
|
---|
254 | </para>
|
---|
255 |
|
---|
256 | <para>Unfortunately, there is no dedicated chapter in the
|
---|
257 | upstream documentation talking about backup/restore, but
|
---|
258 | there are several articles about it on the
|
---|
259 | Internet. Here is an example.</para>
|
---|
260 |
|
---|
261 | <para>Documentation for Backup/Restore:
|
---|
262 | <ulink url="https://database.guide/backup-sqlite-database/"/>
|
---|
263 | </para>
|
---|
264 |
|
---|
265 | </sect3>
|
---|
266 |
|
---|
267 | <sect3>
|
---|
268 | <title>LMDB</title>
|
---|
269 |
|
---|
270 | <!-- might add some advanced notes for the DBMS here -->
|
---|
271 |
|
---|
272 | <para>Like <application>Sqlite</application>, this
|
---|
273 | software acts on local database files; there is no
|
---|
274 | network interface.</para>
|
---|
275 |
|
---|
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>
|
---|
279 |
|
---|
280 | </sect3>
|
---|
281 | </sect2>
|
---|
282 |
|
---|
283 | </sect1>
|
---|