2010-05-12 04:19:11 +02:00
|
|
|
/*
|
|
|
|
* relfilenode.c
|
|
|
|
*
|
|
|
|
* relfilenode functions
|
2010-07-03 16:23:14 +02:00
|
|
|
*
|
2016-01-02 19:33:40 +01:00
|
|
|
* Copyright (c) 2010-2016, PostgreSQL Global Development Group
|
2015-03-11 03:33:25 +01:00
|
|
|
* src/bin/pg_upgrade/relfilenode.c
|
2010-05-12 04:19:11 +02: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 14:33:40 +01:00
|
|
|
#include "postgres_fe.h"
|
2011-08-27 03:16:24 +02:00
|
|
|
|
2010-05-12 04:19:11 +02:00
|
|
|
#include "pg_upgrade.h"
|
|
|
|
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
#include <sys/stat.h>
|
2010-05-12 04:19:11 +02:00
|
|
|
#include "catalog/pg_class.h"
|
|
|
|
#include "access/transam.h"
|
|
|
|
|
|
|
|
|
2016-03-08 14:13:02 +01:00
|
|
|
static void transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace);
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
static void transfer_relfile(FileNameMap *map, const char *suffix, bool vm_must_add_frozenbit);
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2010-07-06 21:19:02 +02:00
|
|
|
|
2013-01-09 14:57:47 +01:00
|
|
|
/*
|
|
|
|
* transfer_all_new_tablespaces()
|
|
|
|
*
|
|
|
|
* Responsible for upgrading all database. invokes routines to generate mappings and then
|
|
|
|
* physically link the databases.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
|
2013-05-29 22:58:43 +02:00
|
|
|
char *old_pgdata, char *new_pgdata)
|
2013-01-09 14:57:47 +01:00
|
|
|
{
|
|
|
|
pg_log(PG_REPORT, "%s user relation files\n",
|
|
|
|
user_opts.transfer_mode == TRANSFER_MODE_LINK ? "Linking" : "Copying");
|
|
|
|
|
|
|
|
/*
|
2015-05-24 03:35:49 +02:00
|
|
|
* Transferring files by tablespace is tricky because a single database
|
|
|
|
* can use multiple tablespaces. For non-parallel mode, we just pass a
|
|
|
|
* NULL tablespace path, which matches all tablespaces. In parallel mode,
|
|
|
|
* we pass the default tablespace and all user-created tablespaces and let
|
2013-05-29 22:58:43 +02:00
|
|
|
* those operations happen in parallel.
|
2013-01-09 14:57:47 +01:00
|
|
|
*/
|
|
|
|
if (user_opts.jobs <= 1)
|
|
|
|
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
|
|
|
|
new_pgdata, NULL);
|
|
|
|
else
|
|
|
|
{
|
2013-05-29 22:58:43 +02:00
|
|
|
int tblnum;
|
2013-01-09 14:57:47 +01:00
|
|
|
|
|
|
|
/* transfer default tablespace */
|
|
|
|
parallel_transfer_all_new_dbs(old_db_arr, new_db_arr, old_pgdata,
|
2013-05-29 22:58:43 +02:00
|
|
|
new_pgdata, old_pgdata);
|
2013-01-09 14:57:47 +01:00
|
|
|
|
|
|
|
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
|
2013-06-01 15:38:15 +02:00
|
|
|
parallel_transfer_all_new_dbs(old_db_arr,
|
|
|
|
new_db_arr,
|
|
|
|
old_pgdata,
|
|
|
|
new_pgdata,
|
|
|
|
os_info.old_tablespaces[tblnum]);
|
2013-01-09 14:57:47 +01:00
|
|
|
/* reap all children */
|
|
|
|
while (reap_child(true) == true)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
end_progress_output();
|
|
|
|
check_ok();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 04:19:11 +02:00
|
|
|
/*
|
|
|
|
* transfer_all_new_dbs()
|
|
|
|
*
|
|
|
|
* Responsible for upgrading all database. invokes routines to generate mappings and then
|
|
|
|
* physically link the databases.
|
|
|
|
*/
|
2013-01-03 03:20:13 +01:00
|
|
|
void
|
2013-01-09 14:57:47 +01:00
|
|
|
transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
|
2013-05-29 22:58:43 +02:00
|
|
|
char *old_pgdata, char *new_pgdata, char *old_tablespace)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
int old_dbnum,
|
|
|
|
new_dbnum;
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2011-11-01 18:49:03 +01:00
|
|
|
/* Scan the old cluster databases and transfer their files */
|
|
|
|
for (old_dbnum = new_dbnum = 0;
|
2011-11-03 18:56:56 +01:00
|
|
|
old_dbnum < old_db_arr->ndbs;
|
2011-11-01 18:49:03 +01:00
|
|
|
old_dbnum++, new_dbnum++)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2012-06-10 21:20:04 +02:00
|
|
|
DbInfo *old_db = &old_db_arr->dbs[old_dbnum],
|
|
|
|
*new_db = NULL;
|
2010-05-12 04:19:11 +02:00
|
|
|
FileNameMap *mappings;
|
|
|
|
int n_maps;
|
|
|
|
|
2011-11-01 18:49:03 +01:00
|
|
|
/*
|
2012-06-10 21:20:04 +02:00
|
|
|
* Advance past any databases that exist in the new cluster but not in
|
|
|
|
* the old, e.g. "postgres". (The user might have removed the
|
|
|
|
* 'postgres' database from the old cluster.)
|
2011-11-01 18:49:03 +01:00
|
|
|
*/
|
2011-11-03 18:56:56 +01:00
|
|
|
for (; new_dbnum < new_db_arr->ndbs; new_dbnum++)
|
|
|
|
{
|
|
|
|
new_db = &new_db_arr->dbs[new_dbnum];
|
|
|
|
if (strcmp(old_db->db_name, new_db->db_name) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2011-11-01 18:49:03 +01:00
|
|
|
|
2011-11-03 18:56:56 +01:00
|
|
|
if (new_dbnum >= new_db_arr->ndbs)
|
2013-10-02 03:24:56 +02:00
|
|
|
pg_fatal("old database \"%s\" not found in the new cluster\n",
|
2014-05-06 18:12:18 +02:00
|
|
|
old_db->db_name);
|
2011-04-10 17:42:00 +02:00
|
|
|
|
2010-10-19 23:38:16 +02:00
|
|
|
mappings = gen_db_file_maps(old_db, new_db, &n_maps, old_pgdata,
|
2010-05-12 04:19:11 +02:00
|
|
|
new_pgdata);
|
|
|
|
if (n_maps)
|
|
|
|
{
|
2010-10-19 23:38:16 +02:00
|
|
|
print_maps(mappings, n_maps, new_db->db_name);
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2016-03-08 14:13:02 +01:00
|
|
|
transfer_single_new_db(mappings, n_maps, old_tablespace);
|
2010-05-12 04:19:11 +02:00
|
|
|
}
|
2015-01-09 18:12:30 +01:00
|
|
|
/* We allocate something even for n_maps == 0 */
|
|
|
|
pg_free(mappings);
|
2010-05-12 04:19:11 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 03:20:13 +01:00
|
|
|
return;
|
2010-05-12 04:19:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transfer_single_new_db()
|
|
|
|
*
|
|
|
|
* create links for mappings stored in "maps" array.
|
|
|
|
*/
|
|
|
|
static void
|
2016-03-08 14:13:02 +01:00
|
|
|
transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
int mapnum;
|
2012-11-14 23:32:04 +01:00
|
|
|
bool vm_crashsafe_match = true;
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
bool vm_must_add_frozenbit = false;
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
/*
|
|
|
|
* Do the old and new cluster disagree on the crash-safetiness of the vm
|
2013-05-29 22:58:43 +02:00
|
|
|
* files? If so, do not copy them.
|
|
|
|
*/
|
2011-08-19 17:20:30 +02:00
|
|
|
if (old_cluster.controldata.cat_ver < VISIBILITY_MAP_CRASHSAFE_CAT_VER &&
|
|
|
|
new_cluster.controldata.cat_ver >= VISIBILITY_MAP_CRASHSAFE_CAT_VER)
|
2012-11-14 23:32:04 +01:00
|
|
|
vm_crashsafe_match = false;
|
2012-06-10 21:20:04 +02:00
|
|
|
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
/*
|
|
|
|
* Do we need to rewrite visibilitymap?
|
|
|
|
*/
|
|
|
|
if (old_cluster.controldata.cat_ver < VISIBILITY_MAP_FROZEN_BIT_CAT_VER &&
|
|
|
|
new_cluster.controldata.cat_ver >= VISIBILITY_MAP_FROZEN_BIT_CAT_VER)
|
|
|
|
vm_must_add_frozenbit = true;
|
|
|
|
|
2010-05-12 04:19:11 +02:00
|
|
|
for (mapnum = 0; mapnum < size; mapnum++)
|
|
|
|
{
|
2013-01-09 14:57:47 +01:00
|
|
|
if (old_tablespace == NULL ||
|
|
|
|
strcmp(maps[mapnum].old_tablespace, old_tablespace) == 0)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2013-01-09 14:57:47 +01:00
|
|
|
/* transfer primary file */
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
transfer_relfile(&maps[mapnum], "", vm_must_add_frozenbit);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2013-01-09 14:57:47 +01:00
|
|
|
/* fsm/vm files added in PG 8.4 */
|
|
|
|
if (GET_MAJOR_VERSION(old_cluster.major_version) >= 804)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Copy/link any fsm and vm files, if they exist
|
|
|
|
*/
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
transfer_relfile(&maps[mapnum], "_fsm", vm_must_add_frozenbit);
|
2013-01-09 14:57:47 +01:00
|
|
|
if (vm_crashsafe_match)
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
transfer_relfile(&maps[mapnum], "_vm", vm_must_add_frozenbit);
|
2013-01-09 14:57:47 +01:00
|
|
|
}
|
2010-05-12 04:19:11 +02:00
|
|
|
}
|
2010-10-20 02:33:19 +02:00
|
|
|
}
|
2010-05-12 04:19:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* transfer_relfile()
|
|
|
|
*
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
* Copy or link file from old cluster to new one. If vm_must_add_frozenbit
|
|
|
|
* is true, visibility map forks are converted and rewritten, even in link
|
|
|
|
* mode.
|
2010-05-12 04:19:11 +02:00
|
|
|
*/
|
|
|
|
static void
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
transfer_relfile(FileNameMap *map, const char *type_suffix, bool vm_must_add_frozenbit)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
|
|
|
const char *msg;
|
2012-11-14 23:32:04 +01:00
|
|
|
char old_file[MAXPGPATH];
|
|
|
|
char new_file[MAXPGPATH];
|
|
|
|
int segno;
|
|
|
|
char extent_suffix[65];
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
struct stat statbuf;
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
/*
|
2013-05-29 22:58:43 +02:00
|
|
|
* Now copy/link any related segments as well. Remember, PG breaks large
|
|
|
|
* files into 1GB segments, the first segment has no extension, subsequent
|
|
|
|
* segments are named relfilenode.1, relfilenode.2, relfilenode.3. copied.
|
2012-11-14 23:32:04 +01:00
|
|
|
*/
|
|
|
|
for (segno = 0;; segno++)
|
2010-05-12 04:19:11 +02:00
|
|
|
{
|
2012-11-14 23:32:04 +01:00
|
|
|
if (segno == 0)
|
|
|
|
extent_suffix[0] = '\0';
|
|
|
|
else
|
|
|
|
snprintf(extent_suffix, sizeof(extent_suffix), ".%d", segno);
|
|
|
|
|
2013-06-01 15:38:15 +02:00
|
|
|
snprintf(old_file, sizeof(old_file), "%s%s/%u/%u%s%s",
|
|
|
|
map->old_tablespace,
|
|
|
|
map->old_tablespace_suffix,
|
|
|
|
map->old_db_oid,
|
|
|
|
map->old_relfilenode,
|
|
|
|
type_suffix,
|
|
|
|
extent_suffix);
|
|
|
|
snprintf(new_file, sizeof(new_file), "%s%s/%u/%u%s%s",
|
|
|
|
map->new_tablespace,
|
|
|
|
map->new_tablespace_suffix,
|
|
|
|
map->new_db_oid,
|
|
|
|
map->new_relfilenode,
|
|
|
|
type_suffix,
|
|
|
|
extent_suffix);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
/* Is it an extent, fsm, or vm file? */
|
|
|
|
if (type_suffix[0] != '\0' || segno != 0)
|
|
|
|
{
|
|
|
|
/* Did file open fail? */
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
if (stat(old_file, &statbuf) != 0)
|
2012-11-14 23:32:04 +01:00
|
|
|
{
|
|
|
|
/* File does not exist? That's OK, just return */
|
|
|
|
if (errno == ENOENT)
|
|
|
|
return;
|
|
|
|
else
|
2013-10-02 03:24:56 +02:00
|
|
|
pg_fatal("error while checking for file existence \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
|
2014-05-06 18:12:18 +02:00
|
|
|
map->nspname, map->relname, old_file, new_file,
|
2015-11-24 23:18:28 +01:00
|
|
|
getErrorText());
|
2012-11-14 23:32:04 +01:00
|
|
|
}
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
|
|
|
|
/* If file is empty, just return */
|
|
|
|
if (statbuf.st_size == 0)
|
|
|
|
return;
|
2012-11-14 23:32:04 +01:00
|
|
|
}
|
2010-05-12 04:19:11 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
unlink(new_file);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
/* Copying files might take some time, so give feedback. */
|
2012-12-07 18:26:13 +01:00
|
|
|
pg_log(PG_STATUS, "%s", old_file);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
2012-11-14 23:32:04 +01:00
|
|
|
if (user_opts.transfer_mode == TRANSFER_MODE_COPY)
|
|
|
|
{
|
|
|
|
pg_log(PG_VERBOSE, "copying \"%s\" to \"%s\"\n", old_file, new_file);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
/* Rewrite visibility map if needed */
|
|
|
|
if (vm_must_add_frozenbit && (strcmp(type_suffix, "_vm") == 0))
|
2016-06-06 15:51:56 +02:00
|
|
|
msg = rewriteVisibilityMap(old_file, new_file);
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
else
|
2016-06-06 15:51:56 +02:00
|
|
|
msg = copyFile(old_file, new_file);
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
|
|
|
|
if (msg)
|
2013-10-02 03:24:56 +02:00
|
|
|
pg_fatal("error while copying relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
|
2014-05-06 18:12:18 +02:00
|
|
|
map->nspname, map->relname, old_file, new_file, msg);
|
2012-11-14 23:32:04 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pg_log(PG_VERBOSE, "linking \"%s\" to \"%s\"\n", old_file, new_file);
|
2013-05-29 22:58:43 +02:00
|
|
|
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
/* Rewrite visibility map if needed */
|
|
|
|
if (vm_must_add_frozenbit && (strcmp(type_suffix, "_vm") == 0))
|
2016-06-06 15:51:56 +02:00
|
|
|
msg = rewriteVisibilityMap(old_file, new_file);
|
pg_upgrade: Convert old visibility map format to new format.
Commit a892234f830e832110f63fc0a2afce2fb21d1584 added a second bit per
page to the visibility map, but pg_upgrade has been unaware of it up
until now. Therefore, a pg_upgrade from an earlier major release of
PostgreSQL to any commit preceding this one and following the one
mentioned above would result in invalid visibility map contents on the
new cluster, very possibly leading to data corruption. This plugs
that hole.
Masahiko Sawada, reviewed by Jeff Janes, Bruce Momjian, Simon Riggs,
Michael Paquier, Andres Freund, me, and others.
2016-03-11 18:28:22 +01:00
|
|
|
else
|
|
|
|
msg = linkFile(old_file, new_file);
|
|
|
|
|
|
|
|
if (msg)
|
2013-10-02 03:24:56 +02:00
|
|
|
pg_fatal("error while creating link for relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
|
2014-05-06 18:12:18 +02:00
|
|
|
map->nspname, map->relname, old_file, new_file, msg);
|
2012-11-14 23:32:04 +01:00
|
|
|
}
|
2013-05-29 22:58:43 +02:00
|
|
|
}
|
2010-05-12 04:19:11 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|