Add postmaster/postgres undocumented -b option for binary upgrades.
This option turns off autovacuum, prevents non-super-user connections, and enables oid setting hooks in the backend. The code continues to use the old autoavacuum disable settings for servers with earlier catalog versions. This includes a catalog version bump to identify servers that support the -b option.
This commit is contained in:
parent
02e6a115cc
commit
76dd09bbec
@ -264,7 +264,7 @@ check_cluster_compatibility(bool live_check)
|
|||||||
|
|
||||||
/* Is it 9.0 but without tablespace directories? */
|
/* Is it 9.0 but without tablespace directories? */
|
||||||
if (GET_MAJOR_VERSION(new_cluster.major_version) == 900 &&
|
if (GET_MAJOR_VERSION(new_cluster.major_version) == 900 &&
|
||||||
new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS)
|
new_cluster.controldata.cat_ver < TABLE_SPACE_SUBDIRS_CAT_VER)
|
||||||
pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
|
pg_log(PG_FATAL, "This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
|
||||||
"because of backend API changes made during development.\n");
|
"because of backend API changes made during development.\n");
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,9 @@
|
|||||||
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
|
||||||
|
|
||||||
/* OID system catalog preservation added during PG 9.0 development */
|
/* OID system catalog preservation added during PG 9.0 development */
|
||||||
#define TABLE_SPACE_SUBDIRS 201001111
|
#define TABLE_SPACE_SUBDIRS_CAT_VER 201001111
|
||||||
|
/* postmaster/postgres -b (binary_upgrade) flag added during PG 9.1 development */
|
||||||
|
#define BINARY_UPGRADE_SERVER_FLAG_CAT_VER 201104251
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Each relation is represented by a relinfo structure.
|
* Each relation is represented by a relinfo structure.
|
||||||
|
@ -173,6 +173,11 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
|
|||||||
const char *datadir;
|
const char *datadir;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
bool exit_hook_registered = false;
|
bool exit_hook_registered = false;
|
||||||
|
#ifndef WIN32
|
||||||
|
char *output_filename = log_opts.filename;
|
||||||
|
#else
|
||||||
|
char *output_filename = DEVNULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
bindir = cluster->bindir;
|
bindir = cluster->bindir;
|
||||||
datadir = cluster->pgdata;
|
datadir = cluster->pgdata;
|
||||||
@ -193,7 +198,6 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
|
|||||||
* same file because we get the error: "The process cannot access the file
|
* same file because we get the error: "The process cannot access the file
|
||||||
* because it is being used by another process." so we have to send all
|
* because it is being used by another process." so we have to send all
|
||||||
* other output to 'nul'.
|
* other output to 'nul'.
|
||||||
*
|
|
||||||
* Using autovacuum=off disables cleanup vacuum and analyze, but freeze
|
* Using autovacuum=off disables cleanup vacuum and analyze, but freeze
|
||||||
* vacuums can still happen, so we set autovacuum_freeze_max_age to its
|
* vacuums can still happen, so we set autovacuum_freeze_max_age to its
|
||||||
* maximum. We assume all datfrozenxid and relfrozen values are less than
|
* maximum. We assume all datfrozenxid and relfrozen values are less than
|
||||||
@ -202,15 +206,13 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
|
|||||||
*/
|
*/
|
||||||
snprintf(cmd, sizeof(cmd),
|
snprintf(cmd, sizeof(cmd),
|
||||||
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
|
SYSTEMQUOTE "\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
|
||||||
"-o \"-p %d -c autovacuum=off "
|
"-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
|
||||||
"-c autovacuum_freeze_max_age=2000000000\" "
|
bindir, output_filename, datadir, port,
|
||||||
"start >> \"%s\" 2>&1" SYSTEMQUOTE,
|
(cluster->controldata.cat_ver >=
|
||||||
bindir,
|
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" :
|
||||||
#ifndef WIN32
|
"-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
|
||||||
log_opts.filename, datadir, port, log_opts.filename);
|
log_opts.filename);
|
||||||
#else
|
|
||||||
DEVNULL, datadir, port, DEVNULL);
|
|
||||||
#endif
|
|
||||||
exec_prog(true, "%s", cmd);
|
exec_prog(true, "%s", cmd);
|
||||||
|
|
||||||
/* wait for the server to start properly */
|
/* wait for the server to start properly */
|
||||||
|
@ -1053,7 +1053,8 @@ heap_create_with_catalog(const char *relname,
|
|||||||
* Use binary-upgrade override for pg_class.oid/relfilenode, if
|
* Use binary-upgrade override for pg_class.oid/relfilenode, if
|
||||||
* supplied.
|
* supplied.
|
||||||
*/
|
*/
|
||||||
if (OidIsValid(binary_upgrade_next_heap_pg_class_oid) &&
|
if (IsBinaryUpgrade &&
|
||||||
|
OidIsValid(binary_upgrade_next_heap_pg_class_oid) &&
|
||||||
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
|
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
|
||||||
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
|
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
|
||||||
relkind == RELKIND_FOREIGN_TABLE))
|
relkind == RELKIND_FOREIGN_TABLE))
|
||||||
@ -1061,7 +1062,8 @@ heap_create_with_catalog(const char *relname,
|
|||||||
relid = binary_upgrade_next_heap_pg_class_oid;
|
relid = binary_upgrade_next_heap_pg_class_oid;
|
||||||
binary_upgrade_next_heap_pg_class_oid = InvalidOid;
|
binary_upgrade_next_heap_pg_class_oid = InvalidOid;
|
||||||
}
|
}
|
||||||
else if (OidIsValid(binary_upgrade_next_toast_pg_class_oid) &&
|
else if (IsBinaryUpgrade &&
|
||||||
|
OidIsValid(binary_upgrade_next_toast_pg_class_oid) &&
|
||||||
relkind == RELKIND_TOASTVALUE)
|
relkind == RELKIND_TOASTVALUE)
|
||||||
{
|
{
|
||||||
relid = binary_upgrade_next_toast_pg_class_oid;
|
relid = binary_upgrade_next_toast_pg_class_oid;
|
||||||
|
@ -789,7 +789,8 @@ index_create(Relation heapRelation,
|
|||||||
* Use binary-upgrade override for pg_class.oid/relfilenode, if
|
* Use binary-upgrade override for pg_class.oid/relfilenode, if
|
||||||
* supplied.
|
* supplied.
|
||||||
*/
|
*/
|
||||||
if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
|
if (IsBinaryUpgrade &&
|
||||||
|
OidIsValid(binary_upgrade_next_index_pg_class_oid))
|
||||||
{
|
{
|
||||||
indexRelationId = binary_upgrade_next_index_pg_class_oid;
|
indexRelationId = binary_upgrade_next_index_pg_class_oid;
|
||||||
binary_upgrade_next_index_pg_class_oid = InvalidOid;
|
binary_upgrade_next_index_pg_class_oid = InvalidOid;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "catalog/pg_enum.h"
|
#include "catalog/pg_enum.h"
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
#include "storage/lmgr.h"
|
#include "storage/lmgr.h"
|
||||||
|
#include "miscadmin.h"
|
||||||
#include "utils/builtins.h"
|
#include "utils/builtins.h"
|
||||||
#include "utils/fmgroids.h"
|
#include "utils/fmgroids.h"
|
||||||
#include "utils/rel.h"
|
#include "utils/rel.h"
|
||||||
@ -311,7 +312,7 @@ restart:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get a new OID for the new label */
|
/* Get a new OID for the new label */
|
||||||
if (OidIsValid(binary_upgrade_next_pg_enum_oid))
|
if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_pg_enum_oid))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Use binary-upgrade override for pg_enum.oid, if supplied. During
|
* Use binary-upgrade override for pg_enum.oid, if supplied. During
|
||||||
|
@ -125,7 +125,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
|
|||||||
tup = heap_form_tuple(tupDesc, values, nulls);
|
tup = heap_form_tuple(tupDesc, values, nulls);
|
||||||
|
|
||||||
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
||||||
if (OidIsValid(binary_upgrade_next_pg_type_oid))
|
if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_pg_type_oid))
|
||||||
{
|
{
|
||||||
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
|
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
|
||||||
binary_upgrade_next_pg_type_oid = InvalidOid;
|
binary_upgrade_next_pg_type_oid = InvalidOid;
|
||||||
@ -430,7 +430,7 @@ TypeCreate(Oid newTypeOid,
|
|||||||
if (OidIsValid(newTypeOid))
|
if (OidIsValid(newTypeOid))
|
||||||
HeapTupleSetOid(tup, newTypeOid);
|
HeapTupleSetOid(tup, newTypeOid);
|
||||||
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
||||||
else if (OidIsValid(binary_upgrade_next_pg_type_oid))
|
else if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_pg_type_oid))
|
||||||
{
|
{
|
||||||
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
|
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
|
||||||
binary_upgrade_next_pg_type_oid = InvalidOid;
|
binary_upgrade_next_pg_type_oid = InvalidOid;
|
||||||
|
@ -157,7 +157,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
|
|||||||
* creation even if it seems not to need one.
|
* creation even if it seems not to need one.
|
||||||
*/
|
*/
|
||||||
if (!needs_toast_table(rel) &&
|
if (!needs_toast_table(rel) &&
|
||||||
!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
|
(!IsBinaryUpgrade ||
|
||||||
|
!OidIsValid(binary_upgrade_next_toast_pg_class_oid)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -202,7 +203,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
|
|||||||
namespaceid = PG_TOAST_NAMESPACE;
|
namespaceid = PG_TOAST_NAMESPACE;
|
||||||
|
|
||||||
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
/* Use binary-upgrade override for pg_type.oid, if supplied. */
|
||||||
if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
|
if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_toast_pg_type_oid))
|
||||||
{
|
{
|
||||||
toast_typid = binary_upgrade_next_toast_pg_type_oid;
|
toast_typid = binary_upgrade_next_toast_pg_type_oid;
|
||||||
binary_upgrade_next_toast_pg_type_oid = InvalidOid;
|
binary_upgrade_next_toast_pg_type_oid = InvalidOid;
|
||||||
|
@ -1550,7 +1550,7 @@ AssignTypeArrayOid(void)
|
|||||||
Oid type_array_oid;
|
Oid type_array_oid;
|
||||||
|
|
||||||
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
|
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
|
||||||
if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
|
if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_array_pg_type_oid))
|
||||||
{
|
{
|
||||||
type_array_oid = binary_upgrade_next_array_pg_type_oid;
|
type_array_oid = binary_upgrade_next_array_pg_type_oid;
|
||||||
binary_upgrade_next_array_pg_type_oid = InvalidOid;
|
binary_upgrade_next_array_pg_type_oid = InvalidOid;
|
||||||
|
@ -388,7 +388,7 @@ CreateRole(CreateRoleStmt *stmt)
|
|||||||
* pg_largeobject_metadata contains pg_authid.oid's, so we use the
|
* pg_largeobject_metadata contains pg_authid.oid's, so we use the
|
||||||
* binary-upgrade override, if specified.
|
* binary-upgrade override, if specified.
|
||||||
*/
|
*/
|
||||||
if (OidIsValid(binary_upgrade_next_pg_authid_oid))
|
if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_pg_authid_oid))
|
||||||
{
|
{
|
||||||
HeapTupleSetOid(tuple, binary_upgrade_next_pg_authid_oid);
|
HeapTupleSetOid(tuple, binary_upgrade_next_pg_authid_oid);
|
||||||
binary_upgrade_next_pg_authid_oid = InvalidOid;
|
binary_upgrade_next_pg_authid_oid = InvalidOid;
|
||||||
|
@ -529,7 +529,7 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
* tcop/postgres.c (the option sets should not conflict) and with the
|
* tcop/postgres.c (the option sets should not conflict) and with the
|
||||||
* common help() function in main/main.c.
|
* common help() function in main/main.c.
|
||||||
*/
|
*/
|
||||||
while ((opt = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1)
|
while ((opt = getopt(argc, argv, "A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:")) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
{
|
{
|
||||||
@ -541,6 +541,11 @@ PostmasterMain(int argc, char *argv[])
|
|||||||
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
|
SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
/* Undocumented flag used for binary upgrades */
|
||||||
|
IsBinaryUpgrade = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
userDoption = optarg;
|
userDoption = optarg;
|
||||||
break;
|
break;
|
||||||
@ -1480,8 +1485,13 @@ ServerLoop(void)
|
|||||||
if (WalWriterPID == 0 && pmState == PM_RUN)
|
if (WalWriterPID == 0 && pmState == PM_RUN)
|
||||||
WalWriterPID = StartWalWriter();
|
WalWriterPID = StartWalWriter();
|
||||||
|
|
||||||
/* If we have lost the autovacuum launcher, try to start a new one */
|
/*
|
||||||
if (AutoVacPID == 0 &&
|
* If we have lost the autovacuum launcher, try to start a new one.
|
||||||
|
* We don't want autovacuum to run in binary upgrade mode because
|
||||||
|
* autovacuum might update relfrozenxid for empty tables before
|
||||||
|
* the physical files are put in place.
|
||||||
|
*/
|
||||||
|
if (!IsBinaryUpgrade && AutoVacPID == 0 &&
|
||||||
(AutoVacuumingActive() || start_autovac_launcher) &&
|
(AutoVacuumingActive() || start_autovac_launcher) &&
|
||||||
pmState == PM_RUN)
|
pmState == PM_RUN)
|
||||||
{
|
{
|
||||||
@ -2413,7 +2423,7 @@ reaper(SIGNAL_ARGS)
|
|||||||
*/
|
*/
|
||||||
if (WalWriterPID == 0)
|
if (WalWriterPID == 0)
|
||||||
WalWriterPID = StartWalWriter();
|
WalWriterPID = StartWalWriter();
|
||||||
if (AutoVacuumingActive() && AutoVacPID == 0)
|
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
|
||||||
AutoVacPID = StartAutoVacLauncher();
|
AutoVacPID = StartAutoVacLauncher();
|
||||||
if (XLogArchivingActive() && PgArchPID == 0)
|
if (XLogArchivingActive() && PgArchPID == 0)
|
||||||
PgArchPID = pgarch_start();
|
PgArchPID = pgarch_start();
|
||||||
|
@ -3238,7 +3238,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
|
|||||||
* postmaster/postmaster.c (the option sets should not conflict) and with
|
* postmaster/postmaster.c (the option sets should not conflict) and with
|
||||||
* the common help() function in main/main.c.
|
* the common help() function in main/main.c.
|
||||||
*/
|
*/
|
||||||
while ((flag = getopt(argc, argv, "A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:")) != -1)
|
while ((flag = getopt(argc, argv, "A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:")) != -1)
|
||||||
{
|
{
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
@ -3250,6 +3250,11 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
|
|||||||
SetConfigOption("shared_buffers", optarg, ctx, gucsource);
|
SetConfigOption("shared_buffers", optarg, ctx, gucsource);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'b':
|
||||||
|
/* Undocumented flag used for binary upgrades */
|
||||||
|
IsBinaryUpgrade = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
if (secure)
|
if (secure)
|
||||||
userDoption = strdup(optarg);
|
userDoption = strdup(optarg);
|
||||||
|
@ -85,6 +85,7 @@ pid_t PostmasterPid = 0;
|
|||||||
*/
|
*/
|
||||||
bool IsPostmasterEnvironment = false;
|
bool IsPostmasterEnvironment = false;
|
||||||
bool IsUnderPostmaster = false;
|
bool IsUnderPostmaster = false;
|
||||||
|
bool IsBinaryUpgrade = false;
|
||||||
|
|
||||||
bool ExitOnAnyError = false;
|
bool ExitOnAnyError = false;
|
||||||
|
|
||||||
|
@ -625,6 +625,16 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
|
|||||||
errmsg("must be superuser to connect during database shutdown")));
|
errmsg("must be superuser to connect during database shutdown")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Binary upgrades only allowed super-user connections
|
||||||
|
*/
|
||||||
|
if (IsBinaryUpgrade && !am_superuser)
|
||||||
|
{
|
||||||
|
ereport(FATAL,
|
||||||
|
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||||
|
errmsg("must be superuser to connect in binary upgrade mode")));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The last few connections slots are reserved for superusers. Although
|
* The last few connections slots are reserved for superusers. Although
|
||||||
* replication connections currently require superuser privileges, we
|
* replication connections currently require superuser privileges, we
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201104181
|
#define CATALOG_VERSION_NO 201104251
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -124,6 +124,7 @@ do { \
|
|||||||
extern pid_t PostmasterPid;
|
extern pid_t PostmasterPid;
|
||||||
extern bool IsPostmasterEnvironment;
|
extern bool IsPostmasterEnvironment;
|
||||||
extern PGDLLIMPORT bool IsUnderPostmaster;
|
extern PGDLLIMPORT bool IsUnderPostmaster;
|
||||||
|
extern bool IsBinaryUpgrade;
|
||||||
|
|
||||||
extern bool ExitOnAnyError;
|
extern bool ExitOnAnyError;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user