
One reason to migrate from the xCAT default SQLite database to PostgreSQL is for xCAT hierarchy using Service Nodes. PostgreSQL provides the ability for remote access to the database on the xCAT Management Node; a requirement for Service Nodes. PostgreSQL also support IPV6.
Note: If using postgresql-9.0, the paths have changed from /var/lib/pgsql/... to /var/lib/pgsql/9.0/...
The postgresql service name has changed to postgresql-9.0 (service postgresql-9.0 stop/start)
This following documentation assumes:
Substitute your IP addresses, userid, password, and database name as appropriate.
The PostgreSQL rpms are part of the base Linux OS. Please verify the following rpms are installed:
    postgresql-libs-*
    postgresql-server-*
    postgresql-*
    perl-DBD-Pg*    
Note: in SLES the Perl-DBD is located in the SDK
You may also want to install the following:
    postgresql-odbc*
    postgresql-plpython
    postgresql-plperl
On Debian/Ubuntu. Should install following packages:
    postgresql
    libdbd-pg-perl
Space Required for database install:
As root:
http://sourceforge.net/projects/xcat/files/xcat-dep/2.x_AIX
    gunzip xcat-postgresql*.gz
    tar -xvf xcat-postgresql*.tar
Read the README file for installation instructions, and install the two rpms on the AIX Management Node that are appropriate for your OS level.
*Note: as of Oct 2010, the AIX deps package will automatically install the perl-DBD-Pg , and unixODBC- when installed on the Management or Service Nodes. You may find these already installed. **
You should use the pgsqlsetup script to setup xCAT on PostgreSQL instead of following steps under "Manually setup PostgreSQL" section
See the pgsqlsetup man page for more information on the script. The script will complete all actions described in the "Manually setup PostgreSQL" section, including the addition of the Management Nodes IP address in the pg_hba.conf file.
The script will prompt you for an xCAT admin password for the database. As of xCAT2.8, you can bypass this prompt by setting XCATPGPW=<password> in the environment.</password>
To setup the PostgreSQL database, run
     pgsqlsetup -i -V
After the automatic setup is complete, to support Service Nodes you need to
    host    all          all        11.16.1.230/32      md5
    host    all          all        11.16.2.230/32      md5
Look in the "Setup the PostgreSQL configuration files" section for more information in changing the pg_hba.conf and postgresql.conf files.
    * /var - 131072 bytes 
    * / - 2818048 bytes 
    * /opt - 52428 bytes 
STOP: If using xCAT 2.5 or later, you can use pgsqlsetup to do this work. See above for instructions.
As root: Stop the xcatd daemon during the database migration:
AIX:
stopsrc -s xcatd 
Linux:
service xcatd stop 
On AIX create the needed postgreSQL ids:
    mkgroup postgres
    mkuser pgrp=postgres home=/var/lib/pgsql postgres
    passwd postgres ( assign a password this is optional)
    mkuser xcatadm
    passwd xcatadm ( assign temp password with root)
    su - xcatadm
    passwd ( assign permanent password that will be used in the /etc/xcat/cfgloc file)
as root:
    mkdir /var/lib/pgsql/data
    chown postgres /var/lib/pgsql/data
    chgrp postgres /var/lib/pgsql/data
    su - postgres
    pwd ( are you in /var/lib/pgsql)
Add paths needing to run DB commands to the .profile
    MANPATH=/usr/local/pgsql/man:$MANPATH
    export MANPATH
    PATH=/usr/local/pgsql/bin:$PATH
    export PATH
On AIX as postgres Create a database installation by running the following:
    /var/lib/pgsql/bin/initdb -D /var/lib/pgsql/data
You should get the following message "Success. You can now start the database..."
On Linux as root run the following to create the Database installation:
    service postgresql initdb
On AIX or Linux as root:
    vi /var/lib/pgsql/data/pg_hba.conf
Lines should look like this (with your IP addresses substituted). Add all nodes that need to access the database.
    local all all ident sameuser
    # IPv4 local connections:
    host all all 127.0.0.1/32 md5
    host all all 11.16.0.1/32 md5
    host all all 11.16.1.230/32 md5
    host all all 11.16.2.230/32 md5
For example, where 11.16.0.1 is the MN and 11.16.1.230 and 11.16.2.230 are service nodes.
    vi /var/lib/pgsql/data/postgresql.conf
    set listen_addresses = '*' # This allows remote access from all ips
Note: be sure and un-comment the line.
The following logging setup is the default on Linux, but should be set on AIX also.
    logging_collector = on
    log_directory = 'pg_log'
    log_filename = 'postgresql-%a.log'
    log_truncate_on_rotation = on
    log_rotation_age = 1d
    log_rotation_size = 0
    log_min_messages = notice
If you are working on large systems, you may need to set the max_connections attribute in the file. This is the number of connections that can be make to the database at one time. If you are using service nodes, it is recommended that you
    set max_connections = 1000
Start/Stop the PostgreSQL server
start the server:
AIX:
     su - postgres
     /var/lib/pgsql/bin/pg_ctl -D /var/lib/pgsql/data start
Linux:
    service postgresql start
If you need to stop the server:
AIX:
    su - postgres
    /var/lib/pgsql/bin/pg_ctl -D /var/lib/pgsql/data stop
Linux:
    service postgresql stop
Note: you can get the message $ LOG: could not bind IPv6 socket: Address already in use HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry after setting listen_addresses = '*' , it can be ignored.
On AIX and Linux:
    su - postgres:
Create the xcatadm userid in the database and set to own xcatdb
AIX:
    /var/lib/pgsql/bin/createuser -SDRP xcatadm
Linux:
    /usr/bin/createuser -SDRP xcatadm
( Will prompt for a password, use the same one that you input for the AIX xcatadm id. Note: this xcatadm unix id does not have to exist on Linux, only in the database.).
Create the xcatdb database owned by xcatadm
AIX:
    /var/lib/pgsql/bin/createdb -O xcatadm xcatdb
Linux:
    /usr/bin/createdb -O xcatadm xcatdb
exit ( back to root)
Note: the pgsqlsetup script will do this for you also, if you choose to use it.
Backup your database to migrate to the new database. (This is required even if you have not added anything to your xCAT database yet. Required default entries were created when the xCAT RPMs were installed on the management node which, and they must be migrated to the new postgresql database.)
    mkdir -p ~/xcat-dbback
    XCATBYPASS=1 dumpxCATdb -p ~/xcat-dbback
    Pg:dbname=xcatdb;host=11.16.0.1|xcatadm|cluster
change to allow only root access:
    chmod 0600 /etc/xcat/cfgloc
    XCATBYPASS=1 restorexCATdb -p ~/xcat-dbback
AIX:
    startsrc -s xcatd
Linux:
    service xcatd start
If you want to access the database through the Postgresql (psql) command, to check the database, enter the following:
    su - postgres
    psql -h <hostname> -U xcatadm -d xcatdb
( note hostname must match ip in the pg_hba.conf file) and you will be prompted for the password ( cluster).
You can then run sql commands on the database.
    Run \h for a list of commands
    Run \g so SQL commands can end in ;
Then
    select * from nodelist; to see table entries
    \dt    will list all tables;
    \q to quit
AIX 7.1 uses a new level of Perl ( 5.10.1). A new level for AIX 7.1 of the perl-DBD rpm and the postgresql rpm must be installed to replaced the AIX 6.x rpms that was installed previously.
During the migration:
Backup your xcat database ( dumpxCATdb)
The xcatd daemon should be stopped.
After the OS migration:
The new rpms can be obtained from the xcat postgresql package on the web:
    /usr/bin/pg_dump xcatdb -U xcatadm -t prescripts
    su - postgres
    dropdb xcatdb - drops the database
    dropuser xcatadm -  removes the xcatadm database owner
    cd /var/lib/pgsql/data
    rm -rf *    (need to remove the data if you want to recreate)
    su - postgres
    psql -l
    su - postgres
    psql xcatdb
    SELECT * FROM "pg_user";    Select all users
    SELECT * FROM "site";   Select the site table
    SELECT MAX(recid) from "auditlog";
    SELECT MIN(recid) from "auditlog";
    drop table zvm;   Removes a table
    \dt    Select all tables
    \?  help
    \q   exit
You can get a nice list of useful commands from here:
  http://www.linuxweblog.com/postgresql-reference 
Install:
    postgresql-odbc-*
    unixODBC-*
On Debian/Ubuntu install:
    unixodbc
    odbc-postgresql
As of xCAT 2.8, the pgsqlsetup script will automatically setup the ODBC interface for Linux after xCAT has been setup to use postgreSQL. AIX is not supported. To setup the ODBC on the Management Node, run the following command and then you can skip the "Manually setup ODBC" section.
    pgsqlsetup -o -V
    cat /root/.odbc.ini
    [xCATDB]
    SERVER = x.xx.xx.xx
    DATABASE = xcatdb
    USER     = xcatadm
    PASSWORD = xcat20
    chmod 0600 /root/.odbc.ini
    cat /etc/odbc.ini
    [xCATDB]
    Driver   = PostgreSQL
    SERVER   = xx.xx.xx.xx
    PORT     = 3306
    DATABASE = xcatdb
    cat /etc/odbcinst.ini
    # Driver from the postgresql-odbc package
    # Setup from the unixODBC package
    [PostgreSQL]
    Description     = ODBC for PostgreSQL
    Driver          = /usr/lib/psqlodbc.so
    Setup           = /usr/lib/libodbcpsqlS.so
    Driver64        = /usr/lib64/psqlodbc.so
    Setup64         = /usr/lib64/libodbcpsqlS.so
    FileUsage       = 1
su - postgres
createuser -SDRP root
Enter password for new role:
Enter it again:
isql -v xcatdb
To remove the database, first run a backup:
    mkdir -p ~/xcat-dbback
    dumpxCATdb -p ~/xcat-dbback
Stop the xcatd daemon on the Management Node. Note if you are using Service Nodes, they will no longer work. SQLite does not support Service Node. You should stop xcatd on the service node. After you run this process which takes you to SQLite, you will need to pick another database such as MySQL and follow the procedure for setting up MySQL for xCAT.
On AIX:
    stopsrc -s xcatd
On Linux:
service xcatd stop
Now remove the xcatdb database from Postgresql.
    su - postgres
    dropdb xcatdb - drops the database
    dropuser xcatadm -  removes the xcatadm database owner
    cd /var/lib/pgsql/data
    rm -rf *    (need to remove the data if you want to recreate)
Move /etc/xcat/cfgloc file (it points xCAT to Postgresql). Move it on the Management Node and Service Nodes. Service Nodes will no longer work at this point. With no /etc/xcat/cfgloc, xcat runs on the default SQLite datbase.
mv /etc/xcat/cfgloc /etc/xcat/cfgloc.pg
Restore the Postgresql database into SQLite. xCAT will run from SQlite database now as the default.
XCATBYPASS=1 restorexCATdb -p ~/xcat-dbback
Start xcatd
On AIX:
restartxcatd
On Linux:
service xcatd start
Tested by Ting Ting Li on Aug. 6 2014 against xCAT 2.8.5
    
      
        
        
          
        
      
      Wiki: AIX_System_Migration
    
      
        
        
          
        
      
      Wiki: Choosing_the_Database
    
      
        
        
          
        
      
      Wiki: Setting_Up_a_Linux_Hierarchical_Cluster
    
      
        
        
          
        
      
      Wiki: Setting_Up_an_AIX_Hierarchical_Cluster
    
      
        
        
          
        
      
      Wiki: Setup_HA_Mgmt_Node_With_NAS_and_Database_Replication
    
      
        
        
          
        
      
      Wiki: XCAT_Documentation