################################################################
#                       VDT-dCache Package                     #
#		Postgres/PNFS Upgrade Instructions             #	
################################################################
The latest VDT-dCache package provides dCache Server 1.9.2-11. It also contains new gratia probe release
that will need to be upgraded.
If you want to upgrade from 2.3.x version proceed to the step 

7) Upgrade dCache software on all nodes (following instructions mentioned
in README file)


If you are upgrading from 2.2.8. Please read the following very carefullu:
**********************************************************************************
Since this is a significant upgrade that also requires upgrade of Postgres 
and PNFS Server software, we have provided this document.

The purpose of this document is to provide instructions for

o Upgrade of Postgres from version 8.1.4 to version 8.3.7
o Upgrade of PNFS Server software 

Finally, you need to upgrade all dCache-1.8.0-15 nodes to dCache-1.9.2-11

Order in which this should be done
++++++++++++++++++++++++++++++++++
1) Upgrade Postgres on PNFS node
2) Upgrade PNFS Server software on PNFS node
3) Upgrade Postgres on Admin and SRM node
4) Upgrade dCache software on all nodes (following instructions mentioned 
in README file)

Assumptions
+++++++++++
o INSTALL_DIR -  directory in which new vdt-dcache tarball is to be installed
/usr/local/
o OLD_INSTALL_DIR - directory in which previous vdt-dcache tarball is installed
/usr/local/vdt-dcache-SL4_32-2.2.8
o Special database user account name is "postgres". Yours may be different.

Note: 

o Following upgrade is performed on SL4 32 bit node. The name of rpms
will be different for a different OS/Arch. 
o Postgres upgrade may take several hours depending on size of the database.
So, "be patient".

Ok, Lets Begin
++++++++++++++

1) On all nodes, download the vdt-dcache-2.4.x tarball and untar it. I assume
its installed in /usr/local so our INSTALL_DIR is 
/usr/local/vdt-dcache-SL4_32-2.4.x

2) On all nodes, stop all currently running dCache services and Postgres

On Pool Nodes:		    /etc/init.d/pool stop
On Gridftp/dCap door Nodes: /etc/init.d/dcache stop
On SRM node: 		    /etc/init.d/dcache stop
On Admin node: 		    /etc/init.d/dcache stop
On PNFS node: 		    /etc/init.d/dcache stop
			    /etc/init.d/pnfs stop
			    /etc/init.d/postgresql stop
On Admin node: 		    /etc/init.d/postgresql stop
On SRM node: 		    /etc/init.d/postgresql stop

3) Upgrade Postgres on PNFS node  

a. Set the value of PGDATA variable to location of your Postgres data directory
   example:
	# export PGDATA=/opt/pgsql/data
	or
	# export PGDATA=/var/lib/pgsql/data
b. Start the Postgres server 
   # /etc/init.d/postgresql start

c. cd in to INSTALL_DIR/vdt-dcache-SLx_y-2.4.x/install and backup the old data 
   # cd /usr/local/vdt-dcache-SL4_32-2.4.x/install/
   # pg_dumpall -U postgres > backup.sql
   Note: If you need to preserve OIDs (such as when using them as foreign keys),
   then use the -o option when running pg_dumpall.

d. Stop the Postgres server
   # /etc/init.d/postgresql stop

e. Backup the old Postgres base directory, just in case you need it later
   #mv ${PGDATA} ${PGDATA}.old

f. Preserve old postgresql.conf and old pg_hba.conf for reference 
   in location of your choice

g. Install the new rpms 
   Note: I had to use the --nodeps option below because old PNFS server 
	 requires libpq.so.4, which is provided by the old postgres library. 
	 This is okay, since we will be upgrading the PNFS software anyways.

   # cd /usr/local/vdt-dcache-SL4_32-2.4.x/RPMS 
   # For 32 bit machines:
     rpm -Uvh --nodeps --nosignature postgresql-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-devel-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-libs-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-server-8.3.5-1PGDG.rhel4.i386.rpm 

     For 64 bit machines:
     rpm -Uvh --nodeps --nosignature postgresql-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-devel-8.3.5-1PGDG.rhel4.i386.rpm
     postgresql-libs-8.3.5-1PGDG.rhel4.i386.rpm
     postgresql-server-8.3.5-1PGDG.rhel4.i386.rpm	
     compat-postgresql-libs-4-1PGDG.rhel"x".i686.rpm 
     compat-postgresql-libs-4-1PGDG.rhel"x".x86_64.rpm

	where "x" can be 4 or 5

h. If user other than "postgres" is used, make following change in the 
   startup script /etc/init.d/postgresql: 
	change username "postgres" to "your_dbadmin_username" everywhere.

i. As root, change permissions on old Postgres base directory
   # chown postgres:postgres /var/lib/pgsql 

j. Make sure PGDATA variable points to location of your Postgres data directory
   example:
	# export PGDATA=/opt/pgsql/data
	or
	# export PGDATA=/var/lib/pgsql/data
   As user postgres, create new data directory and initialize it
	#initdb -D ${PGDATA} --locale=C

k. Make sure you adjust postgresql.conf file according to your node resources. 
   Make sure you have autovacuuming enabled! 

		example settings - 
			.........
			shared_buffers = 256MB # You need at least 256MB
			.........
			work_mem = 128MB
			.........
			max_fsm_pages = 1000000
			.........

    Note: It's important that you set the above values according to what's available 
	  on your machine. Else, the Postgres startup will fail due to error indicating 
	  that the shared memory segment exceeded your kernel's SHMMAX parameter.

l. Make sure all needed entries are present in pg_hba.conf 
   (most likely you can just copy the old pg_hba.conf on top of the new one, 
   but make sure syntax has not changed) 

m. As root, start postgres to make sure it starts up with all config changes 
   you made
   # /etc/init.d/postgresql start

n. Restore the data from backup
   # cd /usr/local/vdt-dcache-SL4_32-2.4.x/install/ 
   # psql -U postgres -f backup.sql template1

4) Upgrade PNFS Server software on PNFS node

a. cd in to INSTALL_DIR/vdt-dcache-SLx_y-2.4.x
# cd /usr/local/vdt-dcache-SL4_32-2.4.x

b. cd in to RPMS dir
# cd RPMS/

c. Install the new rpm
# rpm -Uvh pnfs-postgresql-3-1-12-2f-i386.rpm 
# rpm -qa | grep pnfs

d. At this stage, you can start the PNFS server to verify that all the 
   data is there. But, make sure to stop it before proceeding.

#/opt/pnfs/bin/pnfs start
# ls /pnfs/....
# verify data exists
#/opt/pnfs/bin/pnfs stop

5) Upgrade Postgres on Admin node (Only if, admin and PNFS nodes are different)

a. Start the Postgres server
   # /etc/init.d/postgresql start

b. cd in to INSTALL_DIR/vdt-dcache-SLx_y-2.4.x directory and backup the old data
   # cd /usr/local/vdt-dcache-SL4_32-2.4.x/install/
   # pg_dumpall -U postgres > outputfile
   Note: If you need to preserve OIDs (such as when using them as foreign keys),
   then use the -o option when running pg_dumpall. 

c. Stop the Postgres server
   # /etc/init.d/postgresql stop

d. Backup the old Postgres base directory, just in case you need it later
   # mv /var/lib/pgsql /var/lib/pgsql.old

e. cd in to INSTALL_DIR/RPMS directory
   # cd /usr/local/vdt-dcache-SL4_32-2.4.x/RPMS/

f. Preserve old postgresql.conf and old pg_hba.conf for reference
   in location of your choice

g. Install the new rpms
   # rpm -Uvh postgresql-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-devel-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-libs-8.3.5-1PGDG.rhel4.i386.rpm 
     postgresql-server-8.3.5-1PGDG.rhel4.i386.rpm
   # rpm -qa | grep postgres

h. As root, change permissions on Postgres base directory
   # chown postgres:postgres /var/lib/pgsql

i. As user postgres, create new data directory and initialize it
   # initdb -D /var/lib/pgsql/data

j. Make sure you adjust postgresql.conf file according to your node resources.
   Make sure you have autovacuuming enabled!

		example settings -
			.........
			shared_buffers = 256MB # You need at least 256MB
			.........
			work_mem = 128MB
			.........
			max_fsm_pages = 1000000
			.........
   Note: It's important that you set the above values according to what's available 
	 on your machine. Else, the Postgres startup will fail due to error indicating 
	 that the shared memory segment exceeded your kernel's SHMMAX parameter.

k. Make sure all needed entries are present in pg_hba.conf
   (most likely you can just copy the old pg_hba.conf on top of the new one,
   but make sure syntax has not changed)

l. As root, start postgres to make sure it starts up with all config changes 
   you made
   # /etc/init.d/postgresql start

m. Restore the data from backup
   # psql -U postgres -d postgres -f outputfile

6) Upgrade Postgres on SRM node (Only if its not an admin or PNFS node)

Follow exactly same instructions as mentioned in step 4 above.

Note: Please ignore the postgres error message that says
"You are now connected to database "postgres".
psql:outputfile:11: ERROR:  role "postgres" already exists"

7) Finally, upgrade the dCache software on all nodes 

For this, basically, on all nodes, you can just copy old 
site-info.def in to the INSTALL_DIR/install directory, 
make changes if you want (one change that needs to be 
made is mentioned below) and run the install.sh script 
present in the INSTALL_DIR/install directory.

For the order in which to run the install.sh script and
other installation/configuration details, refer to the 
README file under the INSTALL_DIR/install/ directory.

One change in site-info.def:
The name of java rpm has changed, so you will have to 
change the value of JDK_FILENAME in your site-info.def file
to point to new rpm

References
++++++++++
For Postgres upgrade instructions
https://plone4.fnal.gov/P0/DCache/dcachedoc/administrative-procedures/postgresql-upgrade-procedure 
www.postgresql.org

Questions
+++++++++
osg-storage@opensciencgrid.org