]> granicus.if.org Git - postgresql/blob - contrib/pg_upgrade/version.c
In pg_upgrade, add various logging improvements:
[postgresql] / contrib / pg_upgrade / version.c
1 /*
2  *      version.c
3  *
4  *      Postgres-version-specific routines
5  *
6  *      Copyright (c) 2010-2012, PostgreSQL Global Development Group
7  *      contrib/pg_upgrade/version.c
8  */
9
10 #include "postgres.h"
11
12 #include "pg_upgrade.h"
13
14
15
16 /*
17  * new_9_0_populate_pg_largeobject_metadata()
18  *      new >= 9.0, old <= 8.4
19  *      9.0 has a new pg_largeobject permission table
20  */
21 void
22 new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
23 {
24         int                     dbnum;
25         FILE       *script = NULL;
26         bool            found = false;
27         char            output_path[MAXPGPATH];
28
29         prep_status("Checking for large objects");
30
31         snprintf(output_path, sizeof(output_path), "pg_largeobject.sql");
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_priv(output_path, "w")) == NULL)
52                                         pg_log(PG_FATAL, "could not open file \"%s\": %s\n", output_path, getErrorText(errno));
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 (script)
66                 fclose(script);
67
68         if (found)
69         {
70                 report_status(PG_WARNING, "warning");
71                 if (check_mode)
72                         pg_log(PG_WARNING, "\n"
73                                    "Your installation contains large objects.  The new database has an\n"
74                                    "additional large object permission table.  After upgrading, you will be\n"
75                                    "given a command to populate the pg_largeobject permission table with\n"
76                                    "default permissions.\n\n");
77                 else
78                         pg_log(PG_WARNING, "\n"
79                                    "Your installation contains large objects.  The new database has an\n"
80                                    "additional large object permission table, so default permissions must be\n"
81                                    "defined for all large objects.  The file\n"
82                                    "    %s\n"
83                                    "when executed by psql by the database superuser will set the default\n"
84                                    "permissions.\n\n",
85                                    output_path);
86         }
87         else
88                 check_ok();
89 }