]> git.sur5r.net Git - bacula/docs/blobdiff - docs/manuals/en/main/postgresql.tex
main ok but web
[bacula/docs] / docs / manuals / en / main / postgresql.tex
index 0d22a7bedeed318c632fb5366b0ab24d1f3060d4..66dcdcb0a6394a8103195ff7f1ddc9a771ad45c9 100644 (file)
@@ -8,66 +8,66 @@
 \index[general]{Upgrading}
 
 If you are considering using PostreSQL, you should be aware
-of their philosophy of upgrades, which could be 
+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, 
+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   
+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.
 
 If you are building PostgreSQL from source, please be sure to add
-the {\bf \verb:--:enable-thread-safety} option when doing the ./configure
-for PostgreSQL.  
+the {\bf \lstinline:--:enable-thread-safety} option when doing the ./configure
+for PostgreSQL.
 
 \section{Installing PostgreSQL}
 \index[general]{PostgreSQL!Installing }
 
-If you use the {\bf ./configure \verb:--:with-postgresql=PostgreSQL-Directory}
+If you use the {\bf ./configure \lstinline:--:with-postgresql=PostgreSQL-Directory}
 statement for configuring {\bf Bacula}, 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 {\bf \verb:--:with-postgresql} since the configure program will
+need only enter {\bf \lstinline:--:with-postgresql} 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 {\bf \verb:--:with-postgresql} option. 
+full path with the {\bf \lstinline:--:with-postgresql} option.
 
 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. 
+mirrors.
 
 If you prefer to install from source, we recommend following the instructions
-found in the 
-\elink{PostgreSQL documentation}{http://www.postgresql.org/docs/}. 
+found in the
+\elink{PostgreSQL documentation}{http://www.postgresql.org/docs/}.
 
-If you are using FreeBSD, 
+If you are using FreeBSD,
 \elink{this FreeBSD Diary article}{http://www.freebsddiary.org/postgresql.php}
 will be useful. Even if you are not using FreeBSD, the article will contain
-useful configuration and setup information. 
+useful configuration and setup information.
 
 If you configure the Batch Insert code in Bacula (attribute inserts are
 10 times faster), you {\bf must} be using a PostgreSQL that was built with
-the {\bf \verb:--:enable-thread-safety} option, otherwise you will get
+the {\bf \lstinline:--:enable-thread-safety} 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:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   nm /usr/lib/libpq.a | grep pthread_mutex_lock
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 The above command should print a line that looks like:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
          U pthread_mutex_lock
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 if does, then everything is OK. If it prints nothing, do not enable batch
@@ -77,9 +77,9 @@ After installing PostgreSQL, you should return to completing the installation
 of {\bf Bacula}. 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 
+Installation. You must still come back to complete the second phase of the
 PostgreSQL installation even if you installed binaries (e.g. rpm, deb,
-...).
+\ldots{}).
 
 
 \label{PostgreSQL_configure}
@@ -88,15 +88,15 @@ PostgreSQL installation even if you installed binaries (e.g. rpm, deb,
 
 At this point, you should have built and installed PostgreSQL, or already have
 a running PostgreSQL, and you should have configured, built and installed {\bf
-Bacula}. If not, please complete these items before proceeding. 
+Bacula}. If not, please complete these items before proceeding.
 
 Please note that the {\bf ./configure} used to build {\bf Bacula} will need to
-include {\bf \verb:--:with-postgresql=PostgreSQL-directory}, where {\bf
+include {\bf \lstinline:--:with-postgresql=PostgreSQL-directory}, where {\bf
 PostgreSQL-directory} 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. 
+include headers and library files for interfacing to PostgreSQL.
 
 An important thing to note here is that {\bf Bacula} makes two connections
 to the PostgreSQL server for each backup job that is currently running.  If
@@ -113,27 +113,27 @@ are also available in the \lt{}bacula-src\gt{}/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. 
+create\_bacula\_database will always create your database.
 
 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). 
+user).
 
 \begin{enumerate}
 \item cd \lt{}install-directory\gt{}
 
-   This directory contains the Bacula catalog interface routines.  
+   This directory contains the Bacula catalog interface routines.
 
 \item Create the database owner ({\bf bacula})
-   On many systems, the PostreSQL master 
+   On many systems, the PostreSQL master
    owner is {\bf pgsql} and on others such as Red Hat and Fedora it is {\bf
    postgres}.  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
    {\bf bacula}, you can do the following:
 
-\begin{verbatim}
+\begin{lstlisting}
    su
    (enter root password)
    su pgsql (or postgres)
@@ -142,37 +142,37 @@ user).
    Shall the new user be allowed to create more new users? (y/n) (choose
          what you want)
    exit
-\end{verbatim}
+\end{lstlisting}
    Normally the {\bf bacula} 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 
+   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.
 
 \item ./create\_bacula\_database
 
-   This script creates the PostgreSQL {\bf bacula} database.  
+   This script creates the PostgreSQL {\bf bacula} database.
    Before running this command, you should carefully think about
-   what encoding sequence you want for the text fields (paths, files, ...).
+   what encoding sequence you want for the text fields (paths, files, \ldots{}).
    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:
 
-\begin{verbatim}
+\begin{lstlisting}
    psql -l
-\end{verbatim}
+\end{lstlisting}
 
    and the column marked {\bf Encoding} should be {\bf SQL\_ASCII} for
    all your Bacula databases (normally {\bf bacula}).
 
 \item ./make\_bacula\_tables
 
-   This script creates the PostgreSQL tables used by {\bf Bacula}.  
+   This script creates the PostgreSQL tables used by {\bf Bacula}.
 \item ./grant\_bacula\_privileges
 
    This script creates the database user {\bf bacula}  with restricted access
-rights. You may  want to modify it to suit your situation. Please note that 
-this database is not password protected.  
+rights. You may  want to modify it to suit your situation. Please note that
+this database is not password protected.
 
 \end{enumerate}
 
@@ -180,15 +180,15 @@ 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 {\bf -h hostname} to the command line to specify a remote database
-server. 
+server.
 
 To take a closer look at the access privileges that you have setup with the
-above, you can do: 
+above, you can do:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
 PostgreSQL-directory/bin/psql --command \\dp bacula
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 Also, I had an authorization problem with the password. In the end,
@@ -197,11 +197,11 @@ in /var/lib/postgresql/8.x on others, and in /etc/postgres/8.x/main on
 still others -- what a mess!) from:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   local   all    all        ident  sameuser
 to
   local   all    all        trust
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 This solved the problem for me, but it is not always a good thing
@@ -213,9 +213,9 @@ password hashes.  Begin by editing the {\bf pg\_hba.conf} file, and
 above the existing ``local'' and ``host'' lines, add the line:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   local bacula bacula md5
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 then restart the Postgres database server (frequently, this can be done
@@ -224,16 +224,16 @@ put this new authentication rule into effect.
 
 Next, become the Postgres administrator, postgres, either by logging
 on as the postgres user, or by using su to become root and then using
-{\bf su - postgres} or {\bf su - pgsql} to become postgres.  
+{\bf su - postgres} or {\bf su - pgsql} to become postgres.
 Add a password to the {\bf bacula} database for the {\bf bacula} user using:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   \$ psql bacula
   bacula=# alter user bacula with password 'secret';
   ALTER USER
   bacula=# \\q
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 You'll have to add this password to two locations in the
@@ -242,13 +242,13 @@ RunBeforeJob entry in the BackupCatalog Job resource.  With the
 password in place, these two lines should look something like:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   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"
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 Naturally, you should choose your own significantly more random
@@ -266,9 +266,9 @@ this mechanism, create a file named .pgpass containing the single
 line:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   localhost:5432:bacula:bacula:secret
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 This file should be copied into the home directory of all accounts
@@ -284,31 +284,31 @@ set to 600, limiting access to the owner of the file.
 
 After you have done some initial testing with {\bf Bacula}, 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: 
+that you ran. To do so, you can do the following:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   cd <install-directory>
   ./drop_bacula_tables
   ./make_bacula_tables
   ./grant_bacula_privileges
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 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: 
+end of file mark on the volume so that Bacula can reuse it. Do so with:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
    (stop Bacula or unmount the drive)
    mt -f /dev/nst0 rewind
    mt -f /dev/nst0 weof
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 Where you should replace {\bf /dev/nst0} with the appropriate tape drive
-device name for your machine. 
+device name for your machine.
 
 \section{Installing PostgreSQL from RPMs}
 \index[general]{PostgreSQL!Installing from RPMs}
@@ -319,26 +319,26 @@ libraries are usually found in a {\bf devel} or {\bf dev} package, so you must
 install the following for rpms:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   postgresql
   postgresql-devel
   postgresql-server
   postgresql-libs
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 
 and the following for debs:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
   postgresql
   postgresql-common
   postgresql-client
   postgresql-client-common
   libpq5
   libpq-dev
-\end{verbatim}
+\end{lstlisting}
 \normalsize
 
 
@@ -352,148 +352,157 @@ the database and create the tables as described above.
 \index[general]{Converting from MySQL to PostgreSQL }
 
 The conversion procedure presented here was worked out by Norm Dressler
-\lt{}ndressler at dinmar dot com\gt{} 
+\lt{}ndressler at dinmar dot com\gt{}
 
-This process was tested using the following software versions: 
+This process was tested using the following software versions:
 
-\begin{itemize}
-\item Linux Mandrake 10/Kernel 2.4.22-10 SMP 
-\item Mysql Ver 12.21 Distrib 4.0.15, for mandrake-linux-gnu (i586) 
-\item PostgreSQL 7.3.4 
-\item Bacula 1.34.5 
-   \end{itemize}
+\begin{bsysitemize}
+\item Linux Ubuntu Lucid
+\item Mysql Ver 5.0.83
+\item PostgreSQL 8.4.4
+\item Bacula 5.0
+   \end{bsysitemize}
 
 WARNING: Always as a precaution, take a complete backup of your databases
-before proceeding with this process! 
+before proceeding with this process!
 
 \begin{enumerate}
-\item Shutdown bacula (cd /etc/bacula;./bacula stop)  
-\item Run the following command to dump your Mysql database:  
+\item Shutdown bacula (cd /etc/bacula;./bacula stop)
+\item Run the following command to dump your Mysql database:
 
    \footnotesize
-\begin{verbatim}
-       mysqldump -f -t -n >bacula-backup.dmp
-    
-\end{verbatim}
+\begin{lstlisting}
+mysqldump -t -n -c --compatible=postgresql --skip-quote-names --skip-opt \
+          --disable-keys --lock-tables -u bacula -ppassword bacula \
+  | grep -v "INSERT INTO Status" \
+  | sed -e 's/0000-00-00 00:00:00/1970-01-01 00:00:00/g' \
+  | sed -e 's/\\0//' > bacula-backup.sql
+\end{lstlisting}
 \normalsize
 
 \item Make a backup of your /etc/bacula directory (but leave the  original in
-   place).  
+   place).
 \item 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.  
+   original configure command and replace  enable-mysql with enable-postgresql.
 \item Recompile Bacula with a make and if everything compiles  completely,
-   perform a make install.  
-\item Shutdown Mysql. 
-\item Start PostgreSQL on your system.  
+   perform a make install.
+\item Shutdown Mysql.
+\item Start PostgreSQL on your system.
 \item 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.  
+   create a user, you can also have to change permissions on catalog scripts
+   to fit your situation.
 \item 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:  
+   network:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
 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
-      
-\end{verbatim}
+
+NOTE: you should reload (or restart) your postgres server if you  made changes
+
+\end{lstlisting}
 \normalsize
 
 \item Change into the /etc/bacula directory and prepare the database  and
-   tables with the following commands:  
+   tables with the following commands:
 
 \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
 ./create_postgresql_database
-                                
+
 ./make_postgresql_tables
-                                
+
 ./grant_postgresql_privileges
-       
-\end{verbatim}
+
+\end{lstlisting}
 \normalsize
 
-\item Verify you have access to the database:  
+\item Verify you have access to the database:
 
    \footnotesize
-\begin{verbatim}
-  
+\begin{lstlisting}
+
 psql -Ubacula bacula
-      
-\end{verbatim}
+
+\end{lstlisting}
 \normalsize
 
-You should not get any errors.  
-\item Load your database from the Mysql database dump with:  
+You should not get any errors.
+\item Load your database from the Mysql database dump with:
 
    \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
 psql -Ubacula bacula <bacula-backup.dmp>
-      
-\end{verbatim}
+
+\end{lstlisting}
 \normalsize
 
-\item Resequence your tables with the following commands:  
+\item Resequence your tables with the following commands:
 
    \footnotesize
-\begin{verbatim}
+\begin{lstlisting}
 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('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('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('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));
-       
-\end{verbatim}
+
+SELECT SETVAL('device_deviceid_seq', (SELECT MAX(deviceid) FROM device));
+SELECT SETVAL('location_locationid_seq', (SELECT MAX(locationid) FROM location));
+SELECT SETVAL('locationlog_loclogid_seq', (SELECT MAX(loclogid) FROM locationlog));
+SELECT SETVAL('log_logid_seq', (SELECT MAX(logid) FROM log));
+SELECT SETVAL('mediatype_mediatypeid_seq', (SELECT MAX(mediatypeid) FROM mediatype));
+SELECT SETVAL('storage_storageid_seq', (SELECT MAX(storageid) FROM storage));
+\end{lstlisting}
 \normalsize
 
 \item At this point, start up Bacula, verify your volume library and  perform
-   a test backup to make sure everything is working  properly. 
+   a test backup to make sure everything is working  properly.
 \end{enumerate}
 
 \section{Upgrading PostgreSQL}
 \index[general]{Upgrading PostgreSQL }
 \index[general]{Upgrading!PostgreSQL }
 \index[general]{Upgrading}
-If you upgrade PostgreSQL, you must reconfigure, rebuild, and re-install 
+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.
 
 \section{Tuning PostgreSQL}
-\index[general]{Tuning} 
+\index[general]{Tuning}
 
 If you despool attributes for many jobs at the same time, you can tune the
 sequence object for the \texttt{FileId} field.
-\begin{verbatim}
+\begin{lstlisting}
 psql -Ubacula bacula
 
 ALTER SEQUENCE file_fileid_seq CACHE 1000;
-\end{verbatim}
+\end{lstlisting}
 
 \section{Credits}
 \index[general]{Credits }
 Many thanks to Dan Langille for writing the PostgreSQL driver. This will
-surely become the most popular database that Bacula supports. 
+surely become the most popular database that Bacula supports.