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