2010-05-12 10:19:11 +08:00
|
|
|
/*
|
|
|
|
* version.c
|
|
|
|
*
|
|
|
|
* Postgres-version-specific routines
|
2010-07-03 22:23:14 +08:00
|
|
|
*
|
2013-01-02 06:15:01 +08:00
|
|
|
* Copyright (c) 2010-2013, 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
|
|
|
}
|