]> git.sur5r.net Git - bacula/docs/blob - docs/manuals/de/catalog/postgresql.tex
bc2afa713ebf6e63a3aa30565a14d6849ac85b14
[bacula/docs] / docs / manuals / de / catalog / postgresql.tex
1 %%
2 %%
3
4 \chapter{PostgreSQL Installation und Konfiguration}
5 \label{PostgreSqlChapter}
6 \index[general]{PostgreSQL!Installation und Konfiguration }
7 \index[general]{PostgreSQL Installation und Konfiguration }
8 \index[general]{Update}
9
10 Wenn Sie sich dazu entschlie{\ss}en PostgreSQL zu verwenden,
11 sollten Sie sich \"{u}ber den Aufwand, den ein Datenbank-Update
12 mit sich bringt, im Klaren sein. Grunds\"{a}tzlich werden Sie bei
13 jeder neuen Hauptversion von PostgreSQL Ihre alte Datenbank
14 exportieren m\"{u}ssen, um sie dann in die neue Version einzupflegen.
15 Das wird dadurch erforderlich, dass sich regelm\"{a}{\ss}ig 
16 einige internen "`Datenformate"' \"{a}ndern und von den
17 PostgreSQL-Entwicklern keine Tools zu Verf\"{u}gung gestellt
18 werden, um den Update-Vorgang zu automatisieren. Falls Sie den
19 Daten-Ex- und -Import vergessen sollten, kann es sein das Sie
20 auf die Datenbank nicht mehr zugreifen k\"{o}nnen, da die neue
21 PostgreSQL-Version nicht mit den alten Datenbank-Dateien
22 zusammenarbeitet.
23
24 Sollten Sie PostgreSQL aus dem Quelltext selbst
25 kompilieren, m\"{u}ssen Sie dem configure-Kommando die
26 Option {\bf \verb:--:enable-thread-safety} \"{u}bergeben.
27
28 \section{PostgreSQL Installation}
29 \index[general]{PostgreSQL!Installation }
30 Wenn Sie bei der Konfiguration des Bacula-Quelltextes{\bf ./configure
31 \verb:--:with-postgresql=PostgreSQL-Verzeichnis} angeben, m\"{u}ssen Sie
32 PostgreSQL mindestens in Version 7.4 installiert haben. \"{A}ltere
33 PostgreSQL-Versionen finktionieren mit bacula nicht. Falls PostgreSQL
34 in einem Standard-Verzeichnis installiert ist, brauchen Sie das
35 "`PostgreSQL-Verzeichnis"' nicht angeben. Wenn es aber zum Beispiel in
36 Ihrem Home-Verzeichnis installiert ist, m\"{u}ssen Sie den kompletten
37 Pfad angeben.
38
39 Die Konfiguration und Installation von PostgreSQL ist zwar nicht sehr
40 schwer, kann aber beim ersten Mal etwas verwirrend sein. Wenn Sie es vorziehen,
41 k\"{o}nnen Sie PostgreSQL auch \"{u}ber die Paket-Verwaltung Ihres Betriebssystems
42 installieren. Vorkompilierte Pakete finden Sie auf www.postgresql.org
43 unter \elink{Downloads}{http://www.postgresql.org/download/}
44
45 Wenn Sie PostgreSQL lieber aus dem Quelltext selbst kompilieren m\"{o}chten,
46 empfehlen wir Ihnen den Anweisungen in der \elink{PostgreSQL
47 Dokumentation}{http://www.postgresql.org/docs/} zu folgen.
48
49 Benutzer von FreeBSD finden in diesem \elink{FreeBSD Diary
50 Artikel}{http://www.freebsddiary.org/postgresql.php} weitere n\"{u}tzliche
51 Informationen. Selbstverst\"{a}ndlich enth\"{a}lt der Artikel auch f\"{u}r
52 Nicht-FreeBSD-Benutzer wissenswertes bez\"{u}glich der Installation und
53 Konfiguration von PostgreSQL
54
55 Falls Sie die Bacula "`Batch-Insert"'-Funktion benutzen wollen, die
56 standardm\"{a}{\ss}ig aktiviert ist und f\"{u}r eine schnelle Verarbeitung
57 der Attribute der gesicherten Datein sorgt, m\"{u}ssen Sie unbedingt darauf
58 achten, dass PostgreSQL mit der Option {\bf \verb:--:enable-thread-safety}
59 kompiliert wurde. Bei den meisten gro{\ss}en Linux-Distributionen ist das
60 der Fall. Aber falls Sie nicht sichert sind k\"{o}nnen Sie mit folgendem
61 Kommando feststellen, ob Ihr PostgreSQL gegen die pthreads-Bibliothek
62 gelinked ist:
63
64 \footnotesize
65 \begin{verbatim}
66   nm /usr/lib/libpq.a | grep pthread_mutex_lock
67 \end{verbatim}
68 \normalsize
69
70 Die Kommandos m\"{u}ssen in etwa eine Zeile wie diese zur\"{u}ckgeben:
71
72 \footnotesize
73 \begin{verbatim}
74          U pthread_mutex_lock
75 \end{verbatim}
76 \normalsize
77
78 wenn das der Fall ist, ist alles in Ordnung. Wenn keine Zeilen zur\"{u}ckgegeben
79 werden, wird Bacula beim kompilieren die "`Batch-Insert"`-Funktion deaktivieren.
80 Wenn Sie sie trotzdem benutzen wollen, m\"{u}ssen Sie PostgreSQL mit der Option
81 \verb:--:enable-thread-safety neu kompilieren.
82
83 Nach der PostgreSQL-Installation fahren Sie bitte mit der Installation von Bacula
84 fort. Sp\"{a}ter wenn Sie diese abgeschlossen haben, lesen Sie hier weiter, um
85 die Konfiguration von PostgreSQL zu beenden. Bitte beachten Sie, dass einige
86 Schritte im weiteren Verlauf der PostgreSQL-Konfiguration Scripte ben\"{o}tigen,
87 die erst bei der Installation von Bacula erstellt werden. Auch wenn Sie f\"{u}r
88 die Installation von PostgreSQL vorkompilierte Pakete verwendet haben (zum
89 Beispiel rpm oder deb) m\"{u}ssen Sie sp\"{a}ter hier weitermachen, um die
90 Konfiguration von PostgreSQL zu vervollst\"{a}ndigen.
91
92 \label{PostgreSQL_configure}
93 \section{Configuring PostgreSQL}
94 \index[general]{PostgreSQL!Configuring PostgreSQL -- }
95
96 At this point, you should have built and installed PostgreSQL, or already have
97 a running PostgreSQL, and you should have configured, built and installed {\bf
98 Bacula}. If not, please complete these items before proceeding. 
99
100 Please note that the {\bf ./configure} used to build {\bf Bacula} will need to
101 include {\bf \verb:--:with-postgresql=PostgreSQL-directory}, where {\bf
102 PostgreSQL-directory} is the directory name that you specified on the
103 ./configure command for configuring PostgreSQL (if you didn't specify a
104 directory or PostgreSQL is installed in a default location, you do not need to
105 specify the directory). This is needed so that Bacula can find the necessary
106 include headers and library files for interfacing to PostgreSQL. 
107
108 {\bf Bacula} will install scripts for manipulating the database (create,
109 delete, make tables etc) into the main installation directory. These files
110 will be of the form *\_bacula\_* (e.g. create\_bacula\_database). These files
111 are also available in the \lt{}bacula-src\gt{}/src/cats directory after
112 running ./configure. If you inspect create\_bacula\_database, you will see
113 that it calls create\_postgresql\_database. The *\_bacula\_* files are
114 provided for convenience. It doesn't matter what database you have chosen;
115 create\_bacula\_database will always create your database. 
116
117 Now you will create the Bacula PostgreSQL database and the tables that Bacula
118 uses. These instructions assume that you already have PostgreSQL running. You
119 will need to perform these steps as a user that is able to create new
120 databases. This can be the PostgreSQL user (on most systems, this is the pgsql
121 user). 
122
123 \begin{enumerate}
124 \item cd \lt{}install-directory\gt{}
125
126    This directory contains the Bacula catalog  interface routines.  
127
128 \item ./create\_bacula\_database
129
130    This script creates the PostgreSQL {\bf bacula} database.  
131    Before running this command, you should carefully think about
132    what encoding sequence you want for the text fields (paths, files, ...).
133    Ideally, the encoding should be set to UTF8. However, many Unix systems
134    have filenames that are not encoded in UTF8, either because you have
135    not set UTF8 as your default character set or because you have imported
136    files from elsewhere (e.g. MacOS X).  For this reason, Bacula uses
137    SQL\_ASCII as the default encoding.  If you want to change this,
138    please modify the script before running it, but be forewarned that
139    Bacula backups will fail if PostgreSQL finds any non-UTF8 sequences.
140
141    If running the script fails, it is probably because the database is
142    owned by a user other than yourself.  On many systems, the database
143    owner is {\bf pgsql} and on others such as Red Hat and Fedora it is {\bf
144    postgres}.  You can find out which it is by examining your /etc/passwd
145    file.  To create a new user under either your name or with say the name
146    {\bf bacula}, you can do the following:
147
148 \begin{verbatim}
149    su
150    (enter root password)
151    su pgsql (or postgres)
152    createuser kern (or perhaps bacula)
153    Shall the new user be allowed to create databases? (y/n) y
154    Shall the new user be allowed to create more new users? (y/n) (choose
155          what you want)
156    exit
157 \end{verbatim}
158     
159     At this point, you should be able to execute the
160     ./create\_bacula\_database command.
161
162 \item ./make\_bacula\_tables
163
164    This script creates the PostgreSQL tables used by {\bf Bacula}.  
165 \item ./grant\_bacula\_privileges
166
167    This script creates the database user {\bf bacula}  with restricted access
168 rights. You may  want to modify it to suit your situation. Please note that 
169 this database is not password protected.  
170
171 \end{enumerate}
172
173 Each of the three scripts (create\_bacula\_database, make\_bacula\_tables, and
174 grant\_bacula\_privileges) allows the addition of a command line argument.
175 This can be useful for specifying the user name. For example, you might need
176 to add {\bf -h hostname} to the command line to specify a remote database
177 server. 
178
179 To take a closer look at the access privileges that you have setup with the
180 above, you can do: 
181
182 \footnotesize
183 \begin{verbatim}
184 PostgreSQL-directory/bin/psql --command \\dp bacula
185 \end{verbatim}
186 \normalsize
187
188 Also, I had an authorization problem with the password. In the end,
189 I had to modify my {\bf pg\_hba.conf} file (in /var/lib/pgsql/data on my machine)
190 from:
191
192 \footnotesize
193 \begin{verbatim}
194   local   all    all        ident  sameuser
195 to
196   local   all    all        trust  sameuser
197 \end{verbatim}
198 \normalsize
199
200 This solved the problem for me, but it is not always a good thing
201 to do from a security standpoint.  However, it allowed me to run
202 my regression scripts without having a password.
203
204 A more secure way to perform database authentication is with md5
205 password hashes.  Begin by editing the {\bf pg\_hba.conf} file, and
206 just prior the the existing ``local'' and ``host'' lines, add the line:
207
208 \footnotesize
209 \begin{verbatim}
210   local bacula bacula md5
211 \end{verbatim}
212 \normalsize
213
214 and restart the Postgres database server (frequently, this can be done
215 using "`/etc/init.d/postgresql restart"' or "`service postgresql restart"') to
216 put this new authentication rule into effect.
217
218 Next, become the Postgres administrator, postgres, either by logging
219 on as the postgres user, or by using su to become root and then using
220 su - postgres to become postgres.  Add a password to the bacula
221 database for the bacula user using:
222
223 \footnotesize
224 \begin{verbatim}
225   \$ psql bacula
226   bacula=# alter user bacula with password 'secret';
227   ALTER USER
228   bacula=# \\q
229 \end{verbatim}
230 \normalsize
231
232 You'll have to add this password to two locations in the
233 bacula-dir.conf file: once to the Catalog resource and once to the
234 RunBeforeJob entry in the BackupCatalog Job resource.  With the
235 password in place, these two lines should look something like:
236
237 \footnotesize
238 \begin{verbatim}
239   dbname = bacula; user = bacula; password = "secret"
240     ... and ...
241   # WARNING!!! Passing the password via the command line is insecure.
242   # see comments in make_catalog_backup for details.
243   RunBeforeJob = "/etc/make_catalog_backup bacula bacula secret"
244 \end{verbatim}
245 \normalsize
246
247 Naturally, you should choose your own significantly more random
248 password, and ensure that the bacula-dir.conf file containing this
249 password is readable only by the root.
250
251 Even with the files containing the database password properly
252 restricted, there is still a security problem with this approach: on
253 some platforms, the environment variable that is used to supply the
254 password to Postgres is available to all users of the
255 local system.  To eliminate this problem, the Postgres team have
256 deprecated the use of the environment variable password-passing
257 mechanism and recommend the use of a .pgpass file instead.  To use
258 this mechanism, create a file named .pgpass containing the single
259 line:
260
261 \footnotesize
262 \begin{verbatim}
263   localhost:5432:bacula:bacula:secret
264 \end{verbatim}
265 \normalsize
266
267 This file should be copied into the home directory of all accounts
268 that will need to gain access to the database: typically, root,
269 bacula, and any users who will make use of any of the console
270 programs.  The files must then have the owner and group set to match
271 the user (so root:root for the copy in ~root, and so on), and the mode
272 set to 600, limiting access to the owner of the file.
273
274 \section{Re-initializing the Catalog Database}
275 \index[general]{Database!Re-initializing the Catalog }
276 \index[general]{Re-initializing the Catalog Database }
277
278 After you have done some initial testing with {\bf Bacula}, you will probably
279 want to re-initialize the catalog database and throw away all the test Jobs
280 that you ran. To do so, you can do the following: 
281
282 \footnotesize
283 \begin{verbatim}
284   cd <install-directory>
285   ./drop_bacula_tables
286   ./make_bacula_tables
287   ./grant_bacula_privileges
288 \end{verbatim}
289 \normalsize
290
291 Please note that all information in the database will be lost and you will be
292 starting from scratch. If you have written on any Volumes, you must write an
293 end of file mark on the volume so that Bacula can reuse it. Do so with: 
294
295 \footnotesize
296 \begin{verbatim}
297    (stop Bacula or unmount the drive)
298    mt -f /dev/nst0 rewind
299    mt -f /dev/nst0 weof
300 \end{verbatim}
301 \normalsize
302
303 Where you should replace {\bf /dev/nst0} with the appropriate tape drive
304 device name for your machine. 
305
306 \section{Installing PostgreSQL from RPMs}
307 \index[general]{PostgreSQL!Installing from RPMs}
308 \index[general]{Installing PostgreSQL from RPMs}
309 If you are installing PostgreSQL from RPMs, you will need to install
310 both the PostgreSQL binaries and the client libraries.  The client
311 libraries are usually found in a devel package, so you must
312 install:
313
314 \footnotesize
315 \begin{verbatim}
316   postgresql
317   postgresql-devel
318   postgresql-server
319   postgresql-libs
320 \end{verbatim}
321 \normalsize
322
323 These will be similar with most other package managers too.  After
324 installing from rpms, you will still need to run the scripts that set up
325 the database and create the tables as described above.
326
327
328 \section{Converting from MySQL to PostgreSQL}
329 \index[general]{PostgreSQL!Converting from MySQL to }
330 \index[general]{Converting from MySQL to PostgreSQL }
331
332 The conversion procedure presented here was worked out by Norm Dressler
333 \lt{}ndressler at dinmar dot com\gt{} 
334
335 This process was tested using the following software versions: 
336
337 \begin{itemize}
338 \item Linux Mandrake 10/Kernel 2.4.22-10 SMP 
339 \item Mysql Ver 12.21 Distrib 4.0.15, for mandrake-linux-gnu (i586) 
340 \item PostgreSQL 7.3.4 
341 \item Bacula 1.34.5 
342    \end{itemize}
343
344 WARNING: Always as a precaution, take a complete backup of your databases
345 before proceeding with this process! 
346
347 \begin{enumerate}
348 \item Shutdown bacula (cd /etc/bacula;./bacula stop)  
349 \item Run the following command to dump your Mysql database:  
350
351    \footnotesize
352 \begin{verbatim}
353        mysqldump -f -t -n >bacula-backup.dmp
354     
355 \end{verbatim}
356 \normalsize
357
358 \item Make a backup of your /etc/bacula directory (but leave the  original in
359    place).  
360 \item Go to your Bacula source directory and rebuild it to include  PostgreSQL
361    support rather then Mysql support. Check the  config.log file for your
362    original configure command and replace  enable-mysql with enable-postgresql.  
363 \item Recompile Bacula with a make and if everything compiles  completely,
364    perform a make install.  
365 \item Shutdown Mysql. 
366 \item Start PostgreSQL on your system.  
367 \item Create a bacula user in Postgres with the createuser command.  Depending on
368    your Postgres install, you may have to SU to the  user who has privileges to
369    create a user.  
370 \item Verify your pg\_hba.conf file contains sufficient permissions to  allow
371    bacula to access the server. Mine has the following since  it's on a secure
372    network:  
373
374 \footnotesize
375 \begin{verbatim}
376 local all all trust
377                 
378 host all all 127.0.0.1 255.255.255.255 trust
379                 
380 NOTE: you should restart your postgres server if you
381       made changes
382       
383 \end{verbatim}
384 \normalsize
385
386 \item Change into the /etc/bacula directory and prepare the database  and
387    tables with the following commands:  
388
389 \footnotesize
390 \begin{verbatim}
391 ./create_postgresql_database
392                                 
393 ./make_postgresql_tables
394                                 
395 ./grant_postgresql_privileges
396        
397 \end{verbatim}
398 \normalsize
399
400 \item Verify you have access to the database:  
401
402    \footnotesize
403 \begin{verbatim}
404   
405 psql -Ubacula bacula
406       
407 \end{verbatim}
408 \normalsize
409
410 You should not get any errors.  
411 \item Load your database from the Mysql database dump with:  
412
413    \footnotesize
414 \begin{verbatim}
415 psql -Ubacula bacula <bacula-backup.dmp>
416       
417 \end{verbatim}
418 \normalsize
419
420 \item Resequence your tables with the following commands:  
421
422    \footnotesize
423 \begin{verbatim}
424 psql -Ubacula bacula
425                 
426 SELECT SETVAL('basefiles_baseid_seq', (SELECT
427 MAX(baseid) FROM basefiles));
428 SELECT SETVAL('client_clientid_seq', (SELECT
429 MAX(clientid) FROM client));
430 SELECT SETVAL('file_fileid_seq', (SELECT MAX(fileid)
431 FROM file));
432 SELECT SETVAL('filename_filenameid_seq', (SELECT
433 MAX(filenameid) FROM filename));
434                 
435 SELECT SETVAL('fileset_filesetid_seq', (SELECT
436 MAX(filesetid) FROM fileset));
437                 
438 SELECT SETVAL('job_jobid_seq', (SELECT MAX(jobid) FROM job));
439 SELECT SETVAL('jobmedia_jobmediaid_seq', (SELECT
440 MAX(jobmediaid) FROM jobmedia));
441 SELECT SETVAL('media_mediaid_seq', (SELECT MAX(mediaid) FROM media));
442 SELECT SETVAL('path_pathid_seq', (SELECT MAX(pathid) FROM path));
443                 
444 SELECT SETVAL('pool_poolid_seq', (SELECT MAX(poolid) FROM pool));
445        
446 \end{verbatim}
447 \normalsize
448
449 \item At this point, start up Bacula, verify your volume library and  perform
450    a test backup to make sure everything is working  properly. 
451 \end{enumerate}
452
453 \section{Upgrading PostgreSQL}
454 \index[general]{Upgrading PostgreSQL }
455 \index[general]{Upgrading!PostgreSQL }
456 \index[general]{Upgrading}
457 If you upgrade PostgreSQL, you must reconfigure, rebuild, and re-install 
458 Bacula otherwise you are likely to get bizarre failures.  If you
459 to modify the bacula.spec file to account for the new PostgreSQL version.
460 You can do so by rebuilding from the source rpm. To do so, you may need
461 install from rpms and you upgrade PostgreSQL, you must also rebuild Bacula.
462
463
464 \section{Credits}
465 \index[general]{Credits }
466 Many thanks to Dan Langille for writing the PostgreSQL driver. This will
467 surely become the most popular database that Bacula supports.