Skip to main content

Upgrade PostgreSQL 9.1 to 9.3 - Step by Step

PostgreSQL can be upgrade can be done in following two methods.
A. using pg_upgrade 
B. using pg_dump and pg_restore 
Detail steps are as explained bellow
A)  pg_upgrade 9.3 from 9.1
1. Take full system downtime and stop streaming replication
2. Take full dump of database from Old 9.1 version.
3. Install New version PostgreSQL9.3 under new location say /usr/lib/postgresql/9.3/
4. Stop both(V9.1 and 9.3) the databases.
$/usr/lib/postgresql/9.1/bin/pg_ctl -D /usr/lib/postgresql/9.1/main stop
$/usr/lib/postgresql/9.3/bin/pg_ctl -D /usr/lib/postgresql/9.3/main stop
5. Run pg_upgrade
  • Please make sure that the port no. 50432 is free and no other process is using it. 50432 is used for pg_upgread.
  • Command format
pg_upgrade -b oldbindir -B newbindir -d olddatadir -D newdatadir [option...]
  • Consider old as 9.1 database and new as 9.3 database directory 
    /usr/lib/postgresql/9.3/bin/pg_upgrade -b /usr/lib/postgresql/9.1/bin -B /usr/lib/postgresql/9.3/bin -d /var/lib/postgresql/9.1/main/ -D /var/lib/postgresql/9.3/main/ -O "-c config_file=/etc/postgresql/9.3/main/postgresql.conf" -o "-c config_file=/etc/postgresql/9.1/main/postgresql.conf"
6. Restore pg_hba.conf from old installation to new.
7. Start new v9.3 database.
8. Post-Upgrade processing: If any post-upgrade processing is required, pg_upgrade will issue warnings as it completes. It will also generate script files that must be run by the administrator. The script files will connect to each database that needs post-upgrade processing. Each script should be run using:
psql --username postgres --file script.sql postgres
9.  Statistics : Because optimizer statistics are not transferred by pg_upgrade, you will be instructed to run a command to regenerate that information at the end of the upgrade. You might need to set connection parameters to match your new cluster.
10. Configure: streaming replication
Reference:
B)  pg_dump 9.1 and pg_restore in 9.3
1. Take full system down time and stop Streaming replication
2. Take full database dump from old 9.1 server
3. Stop 9.1 server
4. Install New version 9.3.
5. Create all required role and databases.
6. Restore the 9.1 database dump on 9.3
7. Restore pg_hba.conf from old installation to new.
 Reference:
pg_upgrade will able to handle the creation of all required roles, permission same as old database server. No manual intervention required in this case. where as in dump-restore case all database and user role, permission creation needs to handled manually. Hence we recommend using pg_upgrade...
Before doing upgrade in production we recommend to try this on test setup. All will get the idea on time required to perform the upgrade. 

Comments

Post a Comment

Popular posts from this blog

Drop all Objects from Schema In Postgres

To Drop all objects from Postgres Schema there could be following two approaches: Drop Schema with cascade all and re-create it again.  In some cases where you dont want to/not allowed to drop and recreate schema, its easy to look for objects on current schema and drop them. following script would help to do so, Create function which would do the task and then drop that function too. --- CREATE OR REPLACE FUNCTION drop_DB_objects() RETURNS VOID AS $$ DECLARE  rd_object RECORD; v_idx_statement VARCHAR(500);   BEGIN ---1. Dropping all stored functions RAISE NOTICE '%', 'Dropping all stored functions...'; FOR rd_object IN ( SELECT format('%I.%I(%s)', ns.nspname, p.proname, oidvectortypes(p.proargtypes)) as functionDef     FROM pg_proc p     INNER JOIN pg_namespace ns ON (p.pronamespace = ns.oid)    WHERE ns.nspname = current_schema      AND p.proname <...

Distributed transaction in Oracle ( Over Oracle DBLink)

To fetch the data from one server to and other Oracle server over DBLink, I experienced the following facts of Oracle Distributed transactions: Security issue: -           We cannot create Public synonym for the remote object accessed over Private DBLink of other Database.   -           It’s allowed to create private synonym for remote object, but you cannot grant the access over this synonym to any other schema. If you try to provide the grants to other schema Oracle raises an error:              [ORA-02021: DDL operations are not allowed on a remote database] “In an all you can access remote objects over private DBLink in the same schema where DBLink is created”. Fetching the Ref Cursor at Remote site:                   Let’s say we have two site...

How to Troubleshoot Connectivity Issue with 11gR2 SCAN

I installed the Oracle 11g RAC successfully, But when tried connecting from remote client via SCAN, it used to raise ORA-12537. This is the most common issues that the happens with SCAN listener. And there are few common mistakes that generally  cause this issue. . So, here is how we can troubleshoot the connectivity issues with SCAN, and cases out the possibilities. 1)  Check if Local_listener and remote_listener parameter are set properly on all nodes. 2)  The very common issue is with permissions. SCAN will always be created under grid user (Grid cluserware installation user). Oracle will also create one local listener “LISTENER” during grid infrastructure installation. But if that is not present then always make sure that you create a local listener with grid user. This is required to handover the connection between remote and local listener. 3)  Also “oracle” executable should have given to oracle and grid user i.e. 6751.  Under $ORACLE_HOME/bi...