2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* version.c
|
|
|
|
*
|
|
|
|
* Postgres-version-specific routines
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2011-01-02 02:18:15 +08:00
|
|
|
* Copyright (c) 2010-2011, PostgreSQL Global Development Group
|
2010-09-21 04:08:53 +08:00
|
|
|
* contrib/pg_upgrade/version.c
|
2010-05-12 10:19:11 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pg_upgrade.h"
|
|
|
|
|
|
|
|
#include "access/transam.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* new_9_0_populate_pg_largeobject_metadata()
|
|
|
|
* new >= 9.0, old <= 8.4
|
|
|
|
* 9.0 has a new pg_largeobject permission table
|
|
|
|
*/
|
|
|
|
void
|
2011-01-02 01:06:36 +08:00
|
|
|
new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
FILE *script = NULL;
|
|
|
|
bool found = false;
|
|
|
|
char output_path[MAXPGPATH];
|
|
|
|
|
2010-10-20 05:38:16 +08:00
|
|
|
prep_status("Checking for large objects");
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
snprintf(output_path, sizeof(output_path), "%s/pg_largeobject.sql",
|
2010-10-20 05:38:16 +08:00
|
|
|
os_info.cwd);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
2011-01-02 01:06:36 +08:00
|
|
|
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
|
2010-05-12 10:19:11 +08:00
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
int i_count;
|
2011-01-02 01:06:36 +08:00
|
|
|
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
|
|
|
|
PGconn *conn = connectToServer(cluster, active_db->db_name);
|
2010-05-12 10:19:11 +08:00
|
|
|
|
|
|
|
/* find if there are any large objects */
|
2010-10-20 05:38:16 +08:00
|
|
|
res = executeQueryOrDie(conn,
|
2010-05-12 10:19:11 +08:00
|
|
|
"SELECT count(*) "
|
|
|
|
"FROM pg_catalog.pg_largeobject ");
|
|
|
|
|
|
|
|
i_count = PQfnumber(res, "count");
|
|
|
|
if (atoi(PQgetvalue(res, 0, i_count)) != 0)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
if (!check_mode)
|
|
|
|
{
|
|
|
|
if (script == NULL && (script = fopen(output_path, "w")) == NULL)
|
2011-07-12 12:13:51 +08:00
|
|
|
pg_log(PG_FATAL, "could not open file \"%s\": %s\n", output_path, getErrorText(errno));
|
2010-05-12 10:19:11 +08:00
|
|
|
fprintf(script, "\\connect %s\n",
|
2010-10-20 05:38:16 +08:00
|
|
|
quote_identifier(active_db->db_name));
|
2010-05-12 10:19:11 +08:00
|
|
|
fprintf(script,
|
|
|
|
"SELECT pg_catalog.lo_create(t.loid)\n"
|
|
|
|
"FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) AS t;\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
PQfinish(conn);
|
|
|
|
}
|
|
|
|
|
2011-03-09 10:35:42 +08:00
|
|
|
if (script)
|
|
|
|
fclose(script);
|
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
if (found)
|
|
|
|
{
|
2010-10-20 05:38:16 +08:00
|
|
|
report_status(PG_WARNING, "warning");
|
2010-05-12 10:19:11 +08:00
|
|
|
if (check_mode)
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_WARNING, "\n"
|
2011-07-12 12:13:51 +08:00
|
|
|
"Your installation contains large objects. The new database has an\n"
|
|
|
|
"additional large object permission table. After upgrading, you will be\n"
|
|
|
|
"given a command to populate the pg_largeobject permission table with\n"
|
|
|
|
"default permissions.\n\n");
|
2010-05-12 10:19:11 +08:00
|
|
|
else
|
2010-10-20 05:38:16 +08:00
|
|
|
pg_log(PG_WARNING, "\n"
|
2011-07-12 12:13:51 +08:00
|
|
|
"Your installation contains large objects. The new database has an\n"
|
|
|
|
"additional large object permission table, so default permissions must be\n"
|
|
|
|
"defined for all large objects. The file\n"
|
|
|
|
" %s\n"
|
|
|
|
"when executed by psql by the database superuser will set the default\n"
|
|
|
|
"permissions.\n\n",
|
2010-05-12 10:19:11 +08:00
|
|
|
output_path);
|
|
|
|
}
|
|
|
|
else
|
2010-10-20 05:38:16 +08:00
|
|
|
check_ok();
|
2010-05-12 10:19:11 +08:00
|
|
|
}
|