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