2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* version.c
|
|
|
|
*
|
|
|
|
* Postgres-version-specific routines
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2015-01-07 00:43:47 +08:00
|
|
|
* Copyright (c) 2010-2015, 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
|
|
|
*/
|
|
|
|
|
Create libpgcommon, and move pg_malloc et al to it
libpgcommon is a new static library to allow sharing code among the
various frontend programs and backend; this lets us eliminate duplicate
implementations of common routines. We avoid libpgport, because that's
intended as a place for porting issues; per discussion, it seems better
to keep them separate.
The first use case, and the only implemented by this patch, is pg_malloc
and friends, which many frontend programs were already using.
At the same time, we can use this to provide palloc emulation functions
for the frontend; this way, some palloc-using files in the backend can
also be used by the frontend cleanly. To do this, we change palloc() in
the backend to be a function instead of a macro on top of
MemoryContextAlloc(). This was previously believed to cause loss of
performance, but this implementation has been tweaked by Tom and Andres
so that on modern compilers it provides a slight improvement over the
previous one.
This lets us clean up some places that were already with
localized hacks.
Most of the pg_malloc/palloc changes in this patch were authored by
Andres Freund. Zoltán Böszörményi also independently provided a form of
that. libpgcommon infrastructure was authored by Álvaro.
2013-02-12 21:33:40 +08:00
|
|
|
#include "postgres_fe.h"
|
2011-08-27 09:16:24 +08:00
|
|
|
|
2010-05-12 10:19:11 +08:00
|
|
|
#include "pg_upgrade.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
|
|
|
|
2012-03-13 07:47:54 +08:00
|
|
|
snprintf(output_path, sizeof(output_path), "pg_largeobject.sql");
|
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)
|
|
|
|
{
|
2012-03-13 07:47:54 +08:00
|
|
|
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
2013-10-02 09:24:56 +08:00
|
|
|
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
|
|
|
}
|
2014-05-15 04:26:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* old_9_3_check_for_line_data_type_usage()
|
|
|
|
* 9.3 -> 9.4
|
|
|
|
* Fully implement the 'line' data type in 9.4, which previously returned
|
2014-05-16 01:23:31 +08:00
|
|
|
* "not enabled" by default and was only functionally enabled with a
|
2014-05-15 04:26:06 +08:00
|
|
|
* compile-time switch; 9.4 "line" has different binary and text
|
|
|
|
* representation formats; checks tables and indexes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster)
|
|
|
|
{
|
|
|
|
int dbnum;
|
|
|
|
FILE *script = NULL;
|
|
|
|
bool found = false;
|
|
|
|
char output_path[MAXPGPATH];
|
|
|
|
|
|
|
|
prep_status("Checking for invalid \"line\" user columns");
|
|
|
|
|
|
|
|
snprintf(output_path, sizeof(output_path), "tables_using_line.txt");
|
|
|
|
|
|
|
|
for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
|
|
|
|
{
|
|
|
|
PGresult *res;
|
|
|
|
bool db_used = false;
|
|
|
|
int ntups;
|
|
|
|
int rowno;
|
|
|
|
int i_nspname,
|
|
|
|
i_relname,
|
|
|
|
i_attname;
|
|
|
|
DbInfo *active_db = &cluster->dbarr.dbs[dbnum];
|
|
|
|
PGconn *conn = connectToServer(cluster, active_db->db_name);
|
|
|
|
|
|
|
|
res = executeQueryOrDie(conn,
|
|
|
|
"SELECT n.nspname, c.relname, a.attname "
|
|
|
|
"FROM pg_catalog.pg_class c, "
|
|
|
|
" pg_catalog.pg_namespace n, "
|
|
|
|
" pg_catalog.pg_attribute a "
|
|
|
|
"WHERE c.oid = a.attrelid AND "
|
|
|
|
" NOT a.attisdropped AND "
|
|
|
|
" a.atttypid = 'pg_catalog.line'::pg_catalog.regtype AND "
|
|
|
|
" c.relnamespace = n.oid AND "
|
|
|
|
/* exclude possible orphaned temp tables */
|
|
|
|
" n.nspname !~ '^pg_temp_' AND "
|
|
|
|
" n.nspname !~ '^pg_toast_temp_' AND "
|
|
|
|
" n.nspname NOT IN ('pg_catalog', 'information_schema')");
|
|
|
|
|
|
|
|
ntups = PQntuples(res);
|
|
|
|
i_nspname = PQfnumber(res, "nspname");
|
|
|
|
i_relname = PQfnumber(res, "relname");
|
|
|
|
i_attname = PQfnumber(res, "attname");
|
|
|
|
for (rowno = 0; rowno < ntups; rowno++)
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
if (script == NULL && (script = fopen_priv(output_path, "w")) == NULL)
|
|
|
|
pg_fatal("could not open file \"%s\": %s\n", output_path, getErrorText(errno));
|
|
|
|
if (!db_used)
|
|
|
|
{
|
|
|
|
fprintf(script, "Database: %s\n", active_db->db_name);
|
|
|
|
db_used = true;
|
|
|
|
}
|
|
|
|
fprintf(script, " %s.%s.%s\n",
|
|
|
|
PQgetvalue(res, rowno, i_nspname),
|
|
|
|
PQgetvalue(res, rowno, i_relname),
|
|
|
|
PQgetvalue(res, rowno, i_attname));
|
|
|
|
}
|
|
|
|
|
|
|
|
PQclear(res);
|
|
|
|
|
|
|
|
PQfinish(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (script)
|
|
|
|
fclose(script);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
pg_log(PG_REPORT, "fatal\n");
|
|
|
|
pg_fatal("Your installation contains the \"line\" data type in user tables. This\n"
|
|
|
|
"data type changed its internal and input/output format between your old\n"
|
|
|
|
"and new clusters so this cluster cannot currently be upgraded. You can\n"
|
|
|
|
"remove the problem tables and restart the upgrade. A list of the problem\n"
|
|
|
|
"columns is in the file:\n"
|
|
|
|
" %s\n\n", output_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
check_ok();
|
|
|
|
}
|