I have completed all the outstanding pg_migratory TODO items.

I still have more work to do in cleanup and testing, but if people want
to look at my progress, now is a good time.

You can download the current CVS here:

        http://pgfoundry.org/scm/?group_id=1000235

and you can subscribe to the "general" email list here:

        http://pgfoundry.org/mail/?group_id=1000235

I am attaching main() so you can get an idea of how pg_migrator works.

-- 
  Bruce Momjian  <br...@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
int
main(int argc, char **argv)
{
        migratorContext ctx = {0};
        int                     ntablespaces = 0;
        int                     i = 0;
        char      **tablespaces = NULL;         /* array to store table space 
paths of
                                                                                
 * old data */
        struct timezone tz;

        parseCommandLine(&ctx, argc, argv);
        setup(&ctx, argv[0]);
        

        /* -- OLD -- */
        start_postmaster(&ctx, "Starting postmaster to service old cluster", 
CLUSTER_OLD);

        /* Add any required support functions to the old cluster */
        create_support_functions(&ctx, "Adding support functions to old 
cluster",
                                                         ctx.m_oldlibpath, 
ctx.m_oldbindir, CLUSTER_OLD);

        /* Get the pg_database and pg_largeobject relation OID's */
        get_db_LO_relfilenodes(&ctx, CLUSTER_OLD);

        /* Extract a list of databases and tables from the old cluster */
        gen_db_info(&ctx, &ctx.m_olddbarr, CLUSTER_OLD);

        dump_old_schema(&ctx, DUMP_FILE);

        tablespaces = get_tablespace_paths(&ctx, &ntablespaces, CLUSTER_OLD);

        stop_postmaster(&ctx, CLUSTER_OLD);

        /* Rename all tablespace paths */
        rename_tablespaces(&ctx, tablespaces, ntablespaces);


        /* -- NEW -- */
        start_postmaster(&ctx, "Starting postmaster to service new cluster", 
CLUSTER_NEW);

        /* XXX check that new database is empty */
        /*
         *      It would make more sense to freeze after loading the schema, but
         *      that would cause us to lose the frozenids restored by the load.
         */
        prepStatus(&ctx, "Freezing all rows on the new server");
        exec_prog(&ctx, true, "%s/vacuumdb --port %d --all --frozen --full >> 
%s 2>&1",
                          ctx.m_newbindir, ctx.m_newport, ctx.m_logfile);
        check_ok(&ctx);

        stop_postmaster(&ctx, CLUSTER_NEW);


        ask_continue(&ctx);

        copy_clog_xlog_xid(&ctx);
        /* New now using xid of old system */


        /* -- NEW -- */
        start_postmaster(&ctx, "Starting postmaster to service new cluster", 
CLUSTER_NEW);
        create_support_functions(&ctx, "Adding support functions to new 
cluster",
                                                         ctx.m_newlibpath, 
ctx.m_newbindir, CLUSTER_NEW);
        get_db_LO_relfilenodes(&ctx, CLUSTER_NEW);

        /*
         * Although the schema load will create all the databases, we need to 
perform
         * this step first in order to create toast table placeholder relfiles.
         */
        create_databases(&ctx, &ctx.m_olddbarr, ctx.m_newbindir);

        prepStatus(&ctx, "Creating placeholder relfiles for toast relations");
        create_placeholder_relfiles(&ctx, &ctx.m_olddbarr, ctx.m_newpgdata);
        check_ok(&ctx);

        prepStatus(&ctx, "Restoring database schema");
        exec_prog(&ctx, false, "%s/%s --port %d --dbname template1 < %s/%s >> 
%s 2>&1",
                          ctx.m_newbindir, ctx.m_newpsql_command, ctx.m_newport,
                          ctx.m_homedir, DUMP_FILE, ctx.m_logfile);
        check_ok(&ctx);

        process_relfiles(&ctx);
        
        stop_postmaster(&ctx, CLUSTER_NEW);


#ifdef NOT_USED
        /* XXX do we need this at all?  */
        /*
         *      Assuming OIDs are only used in system tables, there is no need 
to
         *      restore the OID counter because we have not transfered any OIDs
         *      from the old system.
         */
        prepStatus(&ctx, "Setting next oid for new cluster");
        exec_prog(&ctx, true, "%s/pg_resetxlog -o %u %s 1>/dev/null",
                  ctx.m_newbindir, ctx.m_oldctrldata.chkpnt_nxtoid, 
ctx.m_newpgdata);
        check_ok(&ctx);
#endif

        cleanup(&ctx);
        
        if (gettimeofday(&ctx.m_endtime, &tz) == -1)
                pg_log(&ctx, PG_FATAL, "Unable to get time");

        pg_log(&ctx, PG_REPORT, "\nThe data migration completed in %d 
seconds\n",
                   ctx.m_endtime.tv_sec - ctx.m_starttime.tv_sec);
        return 0;
}
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to