]> granicus.if.org Git - postgresql/blob - contrib/pg_upgrade/version.c
Add CVS tags to pg_upgrade and pg_upgrade_support files, per request
[postgresql] / contrib / pg_upgrade / version.c
1 /*
2  *      version.c
3  *
4  *      Postgres-version-specific routines
5  *
6  *      $PostgreSQL: pgsql/contrib/pg_upgrade/version.c,v 1.3 2010/07/03 14:23:14 momjian Exp $
7  */
8
9 #include "pg_upgrade.h"
10
11 #include "access/transam.h"
12
13
14 /*
15  * new_9_0_populate_pg_largeobject_metadata()
16  *      new >= 9.0, old <= 8.4
17  *      9.0 has a new pg_largeobject permission table
18  */
19 void
20 new_9_0_populate_pg_largeobject_metadata(migratorContext *ctx, bool check_mode,
21                                                                                  Cluster whichCluster)
22 {
23         ClusterInfo *active_cluster = (whichCluster == CLUSTER_OLD) ?
24         &ctx->old : &ctx->new;
25         int                     dbnum;
26         FILE       *script = NULL;
27         bool            found = false;
28         char            output_path[MAXPGPATH];
29
30         prep_status(ctx, "Checking for large objects");
31
32         snprintf(output_path, sizeof(output_path), "%s/pg_largeobject.sql",
33                          ctx->cwd);
34
35         for (dbnum = 0; dbnum < active_cluster->dbarr.ndbs; dbnum++)
36         {
37                 PGresult   *res;
38                 int                     i_count;
39                 DbInfo     *active_db = &active_cluster->dbarr.dbs[dbnum];
40                 PGconn     *conn = connectToServer(ctx, active_db->db_name, whichCluster);
41
42                 /* find if there are any large objects */
43                 res = executeQueryOrDie(ctx, conn,
44                                                                 "SELECT count(*) "
45                                                                 "FROM   pg_catalog.pg_largeobject ");
46
47                 i_count = PQfnumber(res, "count");
48                 if (atoi(PQgetvalue(res, 0, i_count)) != 0)
49                 {
50                         found = true;
51                         if (!check_mode)
52                         {
53                                 if (script == NULL && (script = fopen(output_path, "w")) == NULL)
54                                         pg_log(ctx, PG_FATAL, "Could not create necessary file:  %s\n", output_path);
55                                 fprintf(script, "\\connect %s\n",
56                                                 quote_identifier(ctx, active_db->db_name));
57                                 fprintf(script,
58                                                 "SELECT pg_catalog.lo_create(t.loid)\n"
59                                                 "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) AS t;\n");
60                         }
61                 }
62
63                 PQclear(res);
64                 PQfinish(conn);
65         }
66
67         if (found)
68         {
69                 if (!check_mode)
70                         fclose(script);
71                 report_status(ctx, PG_WARNING, "warning");
72                 if (check_mode)
73                         pg_log(ctx, PG_WARNING, "\n"
74                                    "| Your installation contains large objects.\n"
75                                    "| The new database has an additional large object\n"
76                                    "| permission table.  After migration, you will be\n"
77                                    "| given a command to populate the pg_largeobject\n"
78                                    "| permission table with default permissions.\n\n");
79                 else
80                         pg_log(ctx, PG_WARNING, "\n"
81                                    "| Your installation contains large objects.\n"
82                                    "| The new database has an additional large object\n"
83                                    "| permission table so default permissions must be\n"
84                                    "| defined for all large objects.  The file:\n"
85                                    "| \t%s\n"
86                                    "| when executed by psql by the database super-user\n"
87                                    "| will define the default permissions.\n\n",
88                                    output_path);
89         }
90         else
91                 check_ok(ctx);
92 }