Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > df754e4e6f7f5fc8ab9d6ed8559f3e3d > files > 164

bacula-docs-5.0.3-19.fc16.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<!--Converted with LaTeX2HTML 2008 (1.71)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Installing and Configuring PostgreSQL</TITLE>
<META NAME="description" CONTENT="Installing and Configuring PostgreSQL">
<META NAME="keywords" CONTENT="main">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META NAME="Generator" CONTENT="LaTeX2HTML v2008">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<LINK REL="STYLESHEET" HREF="main.css">

<LINK REL="next" HREF="Installing_Configuring_SQLi.html">
<LINK REL="previous" HREF="Installing_Configuring_MySQ.html">
<LINK REL="up" HREF="Bacula_Main_Reference.html">
<LINK REL="next" HREF="Installing_Configuring_SQLi.html">
</HEAD>

<BODY >
<!--Navigation Panel-->
<A NAME="tex2html1966"
  HREF="Installing_Configuring_SQLi.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html1960"
  HREF="Bacula_Main_Reference.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html1954"
  HREF="Installing_Configuring_MySQ.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html1962"
  HREF="Contents.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html1964"
  HREF="Thanks.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html1967"
  HREF="Installing_Configuring_SQLi.html">Installing and Configuring SQLite</A>
<B> Up:</B> <A NAME="tex2html1961"
  HREF="Bacula_Main_Reference.html">Bacula Main Reference</A>
<B> Previous:</B> <A NAME="tex2html1955"
  HREF="Installing_Configuring_MySQ.html">Installing and Configuring MySQL</A>
 &nbsp; <B>  <A NAME="tex2html1963"
  HREF="Contents.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html1965"
  HREF="Thanks.html">Index</A></B> 
<BR>
<BR>
<!--End of Navigation Panel-->
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html1968"
  HREF="Installing_Configuring_Post.html#SECTION004310000000000000000">Installing PostgreSQL</A>
<LI><A NAME="tex2html1969"
  HREF="Installing_Configuring_Post.html#SECTION004320000000000000000">Configuring PostgreSQL</A>
<LI><A NAME="tex2html1970"
  HREF="Installing_Configuring_Post.html#SECTION004330000000000000000">Re-initializing the Catalog Database</A>
<LI><A NAME="tex2html1971"
  HREF="Installing_Configuring_Post.html#SECTION004340000000000000000">Installing PostgreSQL from RPMs</A>
<LI><A NAME="tex2html1972"
  HREF="Installing_Configuring_Post.html#SECTION004350000000000000000">Converting from MySQL to PostgreSQL</A>
<LI><A NAME="tex2html1973"
  HREF="Installing_Configuring_Post.html#SECTION004360000000000000000">Upgrading PostgreSQL</A>
<LI><A NAME="tex2html1974"
  HREF="Installing_Configuring_Post.html#SECTION004370000000000000000">Tuning PostgreSQL</A>
<LI><A NAME="tex2html1975"
  HREF="Installing_Configuring_Post.html#SECTION004380000000000000000">Credits</A>
</UL>
<!--End of Table of Child-Links-->
<HR>

<H1><A NAME="SECTION004300000000000000000"></A>
<A NAME="PostgreSqlChapter"></A>
<BR>
Installing and Configuring PostgreSQL
</H1>
<A NAME="20774"></A>
<A NAME="20775"></A>
<A NAME="20776"></A>

<P>
If you are considering using PostreSQL, you should be aware
of their philosophy of upgrades, which could be 
destabilizing for a production shop.  Basically at every major version
upgrade, you are required to dump your database in an ASCII format, 
do the upgrade, and then reload your database (or databases). This is
because they frequently update the "data format" from version to   
version, and they supply no tools to automatically do the conversion.
If you forget to do the ASCII dump, your database may become totally
useless because none of the new tools can access it due to the format
change, and the PostgreSQL server will not be able to start.

<P>
If you are building PostgreSQL from source, please be sure to add
the <B><code>--</code>enable-thread-safety</B> option when doing the ./configure
for PostgreSQL.  

<P>

<H1><A NAME="SECTION004310000000000000000">
Installing PostgreSQL</A>
</H1>
<A NAME="20779"></A>

<P>
If you use the <B>./configure <code>--</code>with-postgresql=PostgreSQL-Directory</B>
statement for configuring <B>Bacula</B>, you will need PostgreSQL version 7.4
or later installed. NOTE! PostgreSQL versions earlier than 7.4 do not work
with Bacula. If PostgreSQL is installed in the standard system location, you
need only enter <B><code>--</code>with-postgresql</B> since the configure program will
search all the standard locations. If you install PostgreSQL in your home
directory or some other non-standard directory, you will need to provide the
full path with the <B><code>--</code>with-postgresql</B> option. 

<P>
Installing and configuring PostgreSQL is not difficult but can be confusing
the first time. If you prefer, you may want to use a package provided by your
chosen operating system. Binary packages are available on most PostgreSQL
mirrors. 

<P>
If you prefer to install from source, we recommend following the instructions
found in the 
PostgreSQL documentationhttp://www.postgresql.org/docs/. 

<P>
If you are using FreeBSD, 
this FreeBSD Diary articlehttp://www.freebsddiary.org/postgresql.php
will be useful. Even if you are not using FreeBSD, the article will contain
useful configuration and setup information. 

<P>
If you configure the Batch Insert code in Bacula (attribute inserts are
10 times faster), you <B>must</B> be using a PostgreSQL that was built with
the <B><code>--</code>enable-thread-safety</B> option, otherwise you will get
data corruption. Most major Linux distros have thread safety turned on, but
it is better to check.  One way is to see if the PostgreSQL library that
Bacula will be linked against references pthreads.  This can be done
with a command such as:

<P>
<PRE>
  nm /usr/lib/libpq.a | grep pthread_mutex_lock
</PRE>
<P>
The above command should print a line that looks like:

<P>
<PRE>
         U pthread_mutex_lock
</PRE>
<P>
if does, then everything is OK. If it prints nothing, do not enable batch
inserts when building Bacula.

<P>
After installing PostgreSQL, you should return to completing the installation
of <B>Bacula</B>. Later, after Bacula is installed, come back to this chapter
to complete the installation. Please note, the installation files used in the
second phase of the PostgreSQL installation are created during the Bacula
Installation. You must still come back to complete the second phase of the 
PostgreSQL installation even if you installed binaries (e.g. rpm, deb,
...).

<P>
<A NAME="PostgreSQL_configure"></A>
<H1><A NAME="SECTION004320000000000000000">
Configuring PostgreSQL</A>
</H1>
<A NAME="20797"></A>

<P>
At this point, you should have built and installed PostgreSQL, or already have
a running PostgreSQL, and you should have configured, built and installed <B>Bacula</B>. If not, please complete these items before proceeding. 

<P>
Please note that the <B>./configure</B> used to build <B>Bacula</B> will need to
include <B><code>--</code>with-postgresql=PostgreSQL-directory</B>, where <B>PostgreSQL-directory</B> is the directory name that you specified on the
./configure command for configuring PostgreSQL (if you didn't specify a
directory or PostgreSQL is installed in a default location, you do not need to
specify the directory). This is needed so that Bacula can find the necessary
include headers and library files for interfacing to PostgreSQL. 

<P>
An important thing to note here is that <B>Bacula</B> makes two connections
to the PostgreSQL server for each backup job that is currently running.  If
you are intending to run a large number of concurrent jobs, check the value
of <B>max_connections</B> in your PostgreSQL configuration file to ensure
that it is larger than the setting <B>Maximum Concurrent Jobs</B>
in your director configuration.  <B>Setting this too low will result in
some backup jobs failing to run correctly!</B>

<P>
<B>Bacula</B> will install scripts for manipulating the database (create,
delete, make tables etc) into the main installation directory. These files
will be of the form *_bacula_* (e.g. create_bacula_database). These files
are also available in the bacula-src/src/cats directory after
running ./configure. If you inspect create_bacula_database, you will see
that it calls create_postgresql_database. The *_bacula_* files are
provided for convenience. It doesn't matter what database you have chosen;
create_bacula_database will always create your database. 

<P>
Now you will create the Bacula PostgreSQL database and the tables that Bacula
uses. These instructions assume that you already have PostgreSQL running. You
will need to perform these steps as a user that is able to create new
databases. This can be the PostgreSQL user (on most systems, this is the pgsql
user). 

<P>

<OL>
<LI>cd install-directory

<P>
This directory contains the Bacula catalog interface routines.  

<P>
</LI>
<LI>Create the database owner (<B>bacula</B>)
   On many systems, the PostreSQL master 
   owner is <B>pgsql</B> and on others such as Red Hat and Fedora it is <B>   postgres</B>.  You can find out which it is by examining your /etc/passwd
   file.  To create a new user under either your name or with say the name
   <B>bacula</B>, you can do the following:

<P>
<PRE>
   su
   (enter root password)
   su pgsql (or postgres)
   createuser bacula
   Shall the new user be allowed to create databases? (y/n) y
   Shall the new user be allowed to create more new users? (y/n) (choose
         what you want)
   exit
</PRE>
   Normally the <B>bacula</B> user must be able to create new databases,
   if you use the script in the next item, 
   or you will have to create one for it, but it does not need to 
   create new users.

<P>
</LI>
<LI>./create_bacula_database

<P>
This script creates the PostgreSQL <B>bacula</B> database.  
   Before running this command, you should carefully think about
   what encoding sequence you want for the text fields (paths, files, ...).
   We strongly recommend that you use the default value of SQL_ASCII
   that is in the create_bacula_database script.  Please be warned
   that if you change this value, your backups may fail.  After running
   the script, you can check with the command:

<P>
<PRE>
   psql -l
</PRE>

<P>
and the column marked <B>Encoding</B> should be <B>SQL_ASCII</B> for
   all your Bacula databases (normally <B>bacula</B>).

<P>
</LI>
<LI>./make_bacula_tables

<P>
This script creates the PostgreSQL tables used by <B>Bacula</B>.  
</LI>
<LI>./grant_bacula_privileges

<P>
This script creates the database user <B>bacula</B>  with restricted access
rights. You may  want to modify it to suit your situation. Please note that 
this database is not password protected.  

<P>
</LI>
</OL>

<P>
Each of the three scripts (create_bacula_database, make_bacula_tables, and
grant_bacula_privileges) allows the addition of a command line argument.
This can be useful for specifying the user name. For example, you might need
to add <B>-h hostname</B> to the command line to specify a remote database
server. 

<P>
To take a closer look at the access privileges that you have setup with the
above, you can do: 

<P>
<PRE>
PostgreSQL-directory/bin/psql --command \\dp bacula
</PRE>
<P>
Also, I had an authorization problem with the password. In the end,
I had to modify my <B>pg_hba.conf</B> file (in /var/lib/pgsql/data on my machine
in /var/lib/postgresql/8.x on others, and in /etc/postgres/8.x/main on
still others - what a mess!) from:

<P>
<PRE>
  local   all    all        ident  sameuser
to
  local   all    all        trust
</PRE>
<P>
This solved the problem for me, but it is not always a good thing
to do from a security standpoint.  However, it allowed me to run
my regression scripts without having a password.

<P>
A more secure way to perform database authentication is with md5
password hashes.  Begin by editing the <B>pg_hba.conf</B> file, and
above the existing ``local'' and ``host'' lines, add the line:

<P>
<PRE>
  local bacula bacula md5
</PRE>
<P>
then restart the Postgres database server (frequently, this can be done
using "/etc/init.d/postgresql restart" or "service postgresql restart") to
put this new authentication rule into effect.

<P>
Next, become the Postgres administrator, postgres, either by logging
on as the postgres user, or by using su to become root and then using
<B>su - postgres</B> or <B>su - pgsql</B> to become postgres.  
Add a password to the <B>bacula</B> database for the <B>bacula</B> user using:

<P>
<PRE>
  \$ psql bacula
  bacula=# alter user bacula with password 'secret';
  ALTER USER
  bacula=# \\q
</PRE>
<P>
You'll have to add this password to two locations in the
bacula-dir.conf file: once to the Catalog resource and once to the
RunBeforeJob entry in the BackupCatalog Job resource.  With the
password in place, these two lines should look something like:

<P>
<PRE>
  dbname = bacula; user = bacula; password = "secret"
    ... and ...
  # WARNING!!! Passing the password via the command line is insecure.
  # see comments in make_catalog_backup for details.
  RunBeforeJob = "/etc/make_catalog_backup bacula bacula secret"
</PRE>
<P>
Naturally, you should choose your own significantly more random
password, and ensure that the bacula-dir.conf file containing this
password is readable only by the root.

<P>
Even with the files containing the database password properly
restricted, there is still a security problem with this approach: on
some platforms, the environment variable that is used to supply the
password to Postgres is available to all users of the
local system.  To eliminate this problem, the Postgres team have
deprecated the use of the environment variable password-passing
mechanism and recommend the use of a .pgpass file instead.  To use
this mechanism, create a file named .pgpass containing the single
line:

<P>
<PRE>
  localhost:5432:bacula:bacula:secret
</PRE>
<P>
This file should be copied into the home directory of all accounts
that will need to gain access to the database: typically, root,
bacula, and any users who will make use of any of the console
programs.  The files must then have the owner and group set to match
the user (so root:root for the copy in&nbsp;root, and so on), and the mode
set to 600, limiting access to the owner of the file.

<P>

<H1><A NAME="SECTION004330000000000000000">
Re-initializing the Catalog Database</A>
</H1>
<A NAME="20849"></A>
<A NAME="20850"></A>

<P>
After you have done some initial testing with <B>Bacula</B>, you will probably
want to re-initialize the catalog database and throw away all the test Jobs
that you ran. To do so, you can do the following: 

<P>
<PRE>
  cd &lt;install-directory&gt;
  ./drop_bacula_tables
  ./make_bacula_tables
  ./grant_bacula_privileges
</PRE>
<P>
Please note that all information in the database will be lost and you will be
starting from scratch. If you have written on any Volumes, you must write an
end of file mark on the volume so that Bacula can reuse it. Do so with: 

<P>
<PRE>
   (stop Bacula or unmount the drive)
   mt -f /dev/nst0 rewind
   mt -f /dev/nst0 weof
</PRE>
<P>
Where you should replace <B>/dev/nst0</B> with the appropriate tape drive
device name for your machine. 

<P>

<H1><A NAME="SECTION004340000000000000000">
Installing PostgreSQL from RPMs</A>
</H1>
<A NAME="20858"></A>
<A NAME="20859"></A>
If you are installing PostgreSQL from RPMs, you will need to install
both the PostgreSQL binaries and the client libraries.  The client
libraries are usually found in a <B>devel</B> or <B>dev</B> package, so you must
install the following for rpms:

<P>
<PRE>
  postgresql
  postgresql-devel
  postgresql-server
  postgresql-libs
</PRE>
<P>
and the following for debs:

<P>
<PRE>
  postgresql
  postgresql-common
  postgresql-client
  postgresql-client-common
  libpq5
  libpq-dev
</PRE>
<P>
These will be similar with most other package managers too.  After
installing from rpms, you will still need to run the scripts that set up
the database and create the tables as described above.

<P>

<H1><A NAME="SECTION004350000000000000000">
Converting from MySQL to PostgreSQL</A>
</H1>
<A NAME="20867"></A>
<A NAME="20868"></A>

<P>
The conversion procedure presented here was worked out by Norm Dressler
ndressler at dinmar dot com 

<P>
This process was tested using the following software versions: 

<P>

<UL>
<LI>Linux Mandrake 10/Kernel 2.4.22-10 SMP 
</LI>
<LI>Mysql Ver 12.21 Distrib 4.0.15, for mandrake-linux-gnu (i586) 
</LI>
<LI>PostgreSQL 7.3.4 
</LI>
<LI>Bacula 1.34.5 
   
</LI>
</UL>

<P>
WARNING: Always as a precaution, take a complete backup of your databases
before proceeding with this process! 

<P>

<OL>
<LI>Shutdown bacula (cd /etc/bacula;./bacula stop)  
</LI>
<LI>Run the following command to dump your Mysql database:  

<P>
<PRE>
       mysqldump -f -t -n &gt;bacula-backup.dmp
</PRE>
<P>
</LI>
<LI>Make a backup of your /etc/bacula directory (but leave the  original in
   place).  
</LI>
<LI>Go to your Bacula source directory and rebuild it to include  PostgreSQL
   support rather then Mysql support. Check the  config.log file for your
   original configure command and replace  enable-mysql with enable-postgresql.  
</LI>
<LI>Recompile Bacula with a make and if everything compiles  completely,
   perform a make install.  
</LI>
<LI>Shutdown Mysql. 
</LI>
<LI>Start PostgreSQL on your system.  
</LI>
<LI>Create a bacula user in Postgres with the createuser command.  Depending on
   your Postgres install, you may have to SU to the  user who has privileges to
   create a user.  
</LI>
<LI>Verify your pg_hba.conf file contains sufficient permissions to  allow
   bacula to access the server. Mine has the following since  it's on a secure
   network:  

<P>
<PRE>
local all all trust
                
host all all 127.0.0.1 255.255.255.255 trust
                
NOTE: you should restart your postgres server if you
      made changes
</PRE>
<P>
</LI>
<LI>Change into the /etc/bacula directory and prepare the database  and
   tables with the following commands:  

<P>
<PRE>
./create_postgresql_database
                                
./make_postgresql_tables
                                
./grant_postgresql_privileges
</PRE>
<P>
</LI>
<LI>Verify you have access to the database:  

<P>
<PRE>
  
psql -Ubacula bacula
</PRE>
<P>
You should not get any errors.  
</LI>
<LI>Load your database from the Mysql database dump with:  

<P>
<PRE>
psql -Ubacula bacula &lt;bacula-backup.dmp&gt;
</PRE>
<P>
</LI>
<LI>Resequence your tables with the following commands:  

<P>
<PRE>
psql -Ubacula bacula
                
SELECT SETVAL('basefiles_baseid_seq', (SELECT
MAX(baseid) FROM basefiles));
SELECT SETVAL('client_clientid_seq', (SELECT
MAX(clientid) FROM client));
SELECT SETVAL('file_fileid_seq', (SELECT MAX(fileid)
FROM file));
SELECT SETVAL('filename_filenameid_seq', (SELECT
MAX(filenameid) FROM filename));
                
SELECT SETVAL('fileset_filesetid_seq', (SELECT
MAX(filesetid) FROM fileset));
                
SELECT SETVAL('job_jobid_seq', (SELECT MAX(jobid) FROM job));
SELECT SETVAL('jobmedia_jobmediaid_seq', (SELECT
MAX(jobmediaid) FROM jobmedia));
SELECT SETVAL('media_mediaid_seq', (SELECT MAX(mediaid) FROM media));
SELECT SETVAL('path_pathid_seq', (SELECT MAX(pathid) FROM path));
                
SELECT SETVAL('pool_poolid_seq', (SELECT MAX(poolid) FROM pool));
</PRE>
<P>
</LI>
<LI>At this point, start up Bacula, verify your volume library and  perform
   a test backup to make sure everything is working  properly. 
</LI>
</OL>

<P>

<H1><A NAME="SECTION004360000000000000000">
Upgrading PostgreSQL</A>
</H1>
<A NAME="20888"></A>
<A NAME="20889"></A>
<A NAME="20890"></A>
If you upgrade PostgreSQL, you must reconfigure, rebuild, and re-install 
Bacula otherwise you are likely to get bizarre failures.  If you
to modify the bacula.spec file to account for the new PostgreSQL version.
You can do so by rebuilding from the source rpm. To do so, you may need
install from rpms and you upgrade PostgreSQL, you must also rebuild Bacula.

<P>

<H1><A NAME="SECTION004370000000000000000">
Tuning PostgreSQL</A>
</H1>
<A NAME="20892"></A> 

<P>
If you despool attributes for many jobs at the same time, you can tune the
sequence object for the <TT>FileId</TT> field.
<PRE>
psql -Ubacula bacula

ALTER SEQUENCE file_fileid_seq CACHE 1000;
</PRE>

<P>

<H1><A NAME="SECTION004380000000000000000">
Credits</A>
</H1>
<A NAME="20897"></A>
Many thanks to Dan Langille for writing the PostgreSQL driver. This will
surely become the most popular database that Bacula supports. 

<P>
<HR>
<!--Navigation Panel-->
<A NAME="tex2html1966"
  HREF="Installing_Configuring_SQLi.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A> 
<A NAME="tex2html1960"
  HREF="Bacula_Main_Reference.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A> 
<A NAME="tex2html1954"
  HREF="Installing_Configuring_MySQ.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A> 
<A NAME="tex2html1962"
  HREF="Contents.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A> 
<A NAME="tex2html1964"
  HREF="Thanks.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html1967"
  HREF="Installing_Configuring_SQLi.html">Installing and Configuring SQLite</A>
<B> Up:</B> <A NAME="tex2html1961"
  HREF="Bacula_Main_Reference.html">Bacula Main Reference</A>
<B> Previous:</B> <A NAME="tex2html1955"
  HREF="Installing_Configuring_MySQ.html">Installing and Configuring MySQL</A>
 &nbsp; <B>  <A NAME="tex2html1963"
  HREF="Contents.html">Contents</A></B> 
 &nbsp; <B>  <A NAME="tex2html1965"
  HREF="Thanks.html">Index</A></B> 
<!--End of Navigation Panel-->
<ADDRESS>

2012-01-24
</ADDRESS>
</BODY>
</HTML>