Header And Logo

PostgreSQL
| The world's most advanced open source database.

version.c

Go to the documentation of this file.
00001 /*
00002  *  version.c
00003  *
00004  *  Postgres-version-specific routines
00005  *
00006  *  Copyright (c) 2010-2013, PostgreSQL Global Development Group
00007  *  contrib/pg_upgrade/version.c
00008  */
00009 
00010 #include "postgres_fe.h"
00011 
00012 #include "pg_upgrade.h"
00013 
00014 
00015 
00016 /*
00017  * new_9_0_populate_pg_largeobject_metadata()
00018  *  new >= 9.0, old <= 8.4
00019  *  9.0 has a new pg_largeobject permission table
00020  */
00021 void
00022 new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
00023 {
00024     int         dbnum;
00025     FILE       *script = NULL;
00026     bool        found = false;
00027     char        output_path[MAXPGPATH];
00028 
00029     prep_status("Checking for large objects");
00030 
00031     snprintf(output_path, sizeof(output_path), "pg_largeobject.sql");
00032 
00033     for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
00034     {
00035         PGresult   *res;
00036         int         i_count;
00037         DbInfo     *active_db = &cluster->dbarr.dbs[dbnum];
00038         PGconn     *conn = connectToServer(cluster, active_db->db_name);
00039 
00040         /* find if there are any large objects */
00041         res = executeQueryOrDie(conn,
00042                                 "SELECT count(*) "
00043                                 "FROM   pg_catalog.pg_largeobject ");
00044 
00045         i_count = PQfnumber(res, "count");
00046         if (atoi(PQgetvalue(res, 0, i_count)) != 0)
00047         {
00048             found = true;
00049             if (!check_mode)
00050             {
00051                 if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
00052                     pg_log(PG_FATAL, "could not open file \"%s\": %s\n", output_path, getErrorText(errno));
00053                 fprintf(script, "\\connect %s\n",
00054                         quote_identifier(active_db->db_name));
00055                 fprintf(script,
00056                         "SELECT pg_catalog.lo_create(t.loid)\n"
00057                         "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) AS t;\n");
00058             }
00059         }
00060 
00061         PQclear(res);
00062         PQfinish(conn);
00063     }
00064 
00065     if (script)
00066         fclose(script);
00067 
00068     if (found)
00069     {
00070         report_status(PG_WARNING, "warning");
00071         if (check_mode)
00072             pg_log(PG_WARNING, "\n"
00073                    "Your installation contains large objects.  The new database has an\n"
00074                    "additional large object permission table.  After upgrading, you will be\n"
00075                    "given a command to populate the pg_largeobject permission table with\n"
00076                    "default permissions.\n\n");
00077         else
00078             pg_log(PG_WARNING, "\n"
00079                    "Your installation contains large objects.  The new database has an\n"
00080                    "additional large object permission table, so default permissions must be\n"
00081                    "defined for all large objects.  The file\n"
00082                    "    %s\n"
00083                    "when executed by psql by the database superuser will set the default\n"
00084                    "permissions.\n\n",
00085                    output_path);
00086     }
00087     else
00088         check_ok();
00089 }