Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76dd09b

Browse files
committed
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 usethe old autoavacuum disable settings for servers with earlier catalogversions.This includes a catalog version bump to identify servers that supportthe -b option.
1 parent02e6a11 commit76dd09b

File tree

16 files changed

+64
-28
lines changed

16 files changed

+64
-28
lines changed

‎contrib/pg_upgrade/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ check_cluster_compatibility(bool live_check)
264264

265265
/* Is it 9.0 but without tablespace directories? */
266266
if (GET_MAJOR_VERSION(new_cluster.major_version)==900&&
267-
new_cluster.controldata.cat_ver<TABLE_SPACE_SUBDIRS)
267+
new_cluster.controldata.cat_ver<TABLE_SPACE_SUBDIRS_CAT_VER)
268268
pg_log(PG_FATAL,"This utility can only upgrade to PostgreSQL version 9.0 after 2010-01-11\n"
269269
"because of backend API changes made during development.\n");
270270
}

‎contrib/pg_upgrade/pg_upgrade.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
#defineatooid(x) ((Oid) strtoul((x), NULL, 10))
5959

6060
/* OID system catalog preservation added during PG 9.0 development */
61-
#defineTABLE_SPACE_SUBDIRS 201001111
61+
#defineTABLE_SPACE_SUBDIRS_CAT_VER 201001111
62+
/* postmaster/postgres -b (binary_upgrade) flag added during PG 9.1 development */
63+
#defineBINARY_UPGRADE_SERVER_FLAG_CAT_VER 201104251
6264

6365
/*
6466
* Each relation is represented by a relinfo structure.

‎contrib/pg_upgrade/server.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
173173
constchar*datadir;
174174
unsigned shortport;
175175
boolexit_hook_registered= false;
176+
#ifndefWIN32
177+
char*output_filename=log_opts.filename;
178+
#else
179+
char*output_filename=DEVNULL;
180+
#endif
176181

177182
bindir=cluster->bindir;
178183
datadir=cluster->pgdata;
@@ -193,7 +198,6 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
193198
* same file because we get the error: "The process cannot access the file
194199
* because it is being used by another process." so we have to send all
195200
* other output to 'nul'.
196-
*
197201
* Using autovacuum=off disables cleanup vacuum and analyze, but freeze
198202
* vacuums can still happen, so we set autovacuum_freeze_max_age to its
199203
* maximum. We assume all datfrozenxid and relfrozen values are less than
@@ -202,15 +206,13 @@ start_postmaster(ClusterInfo *cluster, bool quiet)
202206
*/
203207
snprintf(cmd,sizeof(cmd),
204208
SYSTEMQUOTE"\"%s/pg_ctl\" -l \"%s\" -D \"%s\" "
205-
"-o \"-p %d -c autovacuum=off "
206-
"-c autovacuum_freeze_max_age=2000000000\" "
207-
"start >> \"%s\" 2>&1"SYSTEMQUOTE,
208-
bindir,
209-
#ifndefWIN32
210-
log_opts.filename,datadir,port,log_opts.filename);
211-
#else
212-
DEVNULL,datadir,port,DEVNULL);
213-
#endif
209+
"-o \"-p %d %s\" start >> \"%s\" 2>&1"SYSTEMQUOTE,
210+
bindir,output_filename,datadir,port,
211+
(cluster->controldata.cat_ver >=
212+
BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ?"-b" :
213+
"-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
214+
log_opts.filename);
215+
214216
exec_prog(true,"%s",cmd);
215217

216218
/* wait for the server to start properly */

‎src/backend/catalog/heap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,15 +1053,17 @@ heap_create_with_catalog(const char *relname,
10531053
* Use binary-upgrade override for pg_class.oid/relfilenode, if
10541054
* supplied.
10551055
*/
1056-
if (OidIsValid(binary_upgrade_next_heap_pg_class_oid)&&
1056+
if (IsBinaryUpgrade&&
1057+
OidIsValid(binary_upgrade_next_heap_pg_class_oid)&&
10571058
(relkind==RELKIND_RELATION||relkind==RELKIND_SEQUENCE||
10581059
relkind==RELKIND_VIEW||relkind==RELKIND_COMPOSITE_TYPE||
10591060
relkind==RELKIND_FOREIGN_TABLE))
10601061
{
10611062
relid=binary_upgrade_next_heap_pg_class_oid;
10621063
binary_upgrade_next_heap_pg_class_oid=InvalidOid;
10631064
}
1064-
elseif (OidIsValid(binary_upgrade_next_toast_pg_class_oid)&&
1065+
elseif (IsBinaryUpgrade&&
1066+
OidIsValid(binary_upgrade_next_toast_pg_class_oid)&&
10651067
relkind==RELKIND_TOASTVALUE)
10661068
{
10671069
relid=binary_upgrade_next_toast_pg_class_oid;

‎src/backend/catalog/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ index_create(Relation heapRelation,
789789
* Use binary-upgrade override for pg_class.oid/relfilenode, if
790790
* supplied.
791791
*/
792-
if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
792+
if (IsBinaryUpgrade&&
793+
OidIsValid(binary_upgrade_next_index_pg_class_oid))
793794
{
794795
indexRelationId=binary_upgrade_next_index_pg_class_oid;
795796
binary_upgrade_next_index_pg_class_oid=InvalidOid;

‎src/backend/catalog/pg_enum.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include"catalog/pg_enum.h"
2222
#include"catalog/pg_type.h"
2323
#include"storage/lmgr.h"
24+
#include"miscadmin.h"
2425
#include"utils/builtins.h"
2526
#include"utils/fmgroids.h"
2627
#include"utils/rel.h"
@@ -311,7 +312,7 @@ AddEnumLabel(Oid enumTypeOid,
311312
}
312313

313314
/* Get a new OID for the new label */
314-
if (OidIsValid(binary_upgrade_next_pg_enum_oid))
315+
if (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_pg_enum_oid))
315316
{
316317
/*
317318
* Use binary-upgrade override for pg_enum.oid, if supplied. During

‎src/backend/catalog/pg_type.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
125125
tup=heap_form_tuple(tupDesc,values,nulls);
126126

127127
/* Use binary-upgrade override for pg_type.oid, if supplied. */
128-
if (OidIsValid(binary_upgrade_next_pg_type_oid))
128+
if (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_pg_type_oid))
129129
{
130130
HeapTupleSetOid(tup,binary_upgrade_next_pg_type_oid);
131131
binary_upgrade_next_pg_type_oid=InvalidOid;
@@ -430,7 +430,7 @@ TypeCreate(Oid newTypeOid,
430430
if (OidIsValid(newTypeOid))
431431
HeapTupleSetOid(tup,newTypeOid);
432432
/* Use binary-upgrade override for pg_type.oid, if supplied. */
433-
elseif (OidIsValid(binary_upgrade_next_pg_type_oid))
433+
elseif (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_pg_type_oid))
434434
{
435435
HeapTupleSetOid(tup,binary_upgrade_next_pg_type_oid);
436436
binary_upgrade_next_pg_type_oid=InvalidOid;

‎src/backend/catalog/toasting.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
157157
* creation even if it seems not to need one.
158158
*/
159159
if (!needs_toast_table(rel)&&
160-
!OidIsValid(binary_upgrade_next_toast_pg_class_oid))
160+
(!IsBinaryUpgrade||
161+
!OidIsValid(binary_upgrade_next_toast_pg_class_oid)))
161162
return false;
162163

163164
/*
@@ -202,7 +203,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
202203
namespaceid=PG_TOAST_NAMESPACE;
203204

204205
/* Use binary-upgrade override for pg_type.oid, if supplied. */
205-
if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
206+
if (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_toast_pg_type_oid))
206207
{
207208
toast_typid=binary_upgrade_next_toast_pg_type_oid;
208209
binary_upgrade_next_toast_pg_type_oid=InvalidOid;

‎src/backend/commands/typecmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ AssignTypeArrayOid(void)
15501550
Oidtype_array_oid;
15511551

15521552
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
1553-
if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
1553+
if (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_array_pg_type_oid))
15541554
{
15551555
type_array_oid=binary_upgrade_next_array_pg_type_oid;
15561556
binary_upgrade_next_array_pg_type_oid=InvalidOid;

‎src/backend/commands/user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ CreateRole(CreateRoleStmt *stmt)
388388
* pg_largeobject_metadata contains pg_authid.oid's, so we use the
389389
* binary-upgrade override, if specified.
390390
*/
391-
if (OidIsValid(binary_upgrade_next_pg_authid_oid))
391+
if (IsBinaryUpgrade&&OidIsValid(binary_upgrade_next_pg_authid_oid))
392392
{
393393
HeapTupleSetOid(tuple,binary_upgrade_next_pg_authid_oid);
394394
binary_upgrade_next_pg_authid_oid=InvalidOid;

‎src/backend/postmaster/postmaster.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ PostmasterMain(int argc, char *argv[])
529529
* tcop/postgres.c (the option sets should not conflict) and with the
530530
* common help() function in main/main.c.
531531
*/
532-
while ((opt=getopt(argc,argv,"A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
532+
while ((opt=getopt(argc,argv,"A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:W:-:"))!=-1)
533533
{
534534
switch (opt)
535535
{
@@ -541,6 +541,11 @@ PostmasterMain(int argc, char *argv[])
541541
SetConfigOption("shared_buffers",optarg,PGC_POSTMASTER,PGC_S_ARGV);
542542
break;
543543

544+
case'b':
545+
/* Undocumented flag used for binary upgrades */
546+
IsBinaryUpgrade= true;
547+
break;
548+
544549
case'D':
545550
userDoption=optarg;
546551
break;
@@ -1480,8 +1485,13 @@ ServerLoop(void)
14801485
if (WalWriterPID==0&&pmState==PM_RUN)
14811486
WalWriterPID=StartWalWriter();
14821487

1483-
/* If we have lost the autovacuum launcher, try to start a new one */
1484-
if (AutoVacPID==0&&
1488+
/*
1489+
*If we have lost the autovacuum launcher, try to start a new one.
1490+
*We don't want autovacuum to run in binary upgrade mode because
1491+
*autovacuum might update relfrozenxid for empty tables before
1492+
*the physical files are put in place.
1493+
*/
1494+
if (!IsBinaryUpgrade&&AutoVacPID==0&&
14851495
(AutoVacuumingActive()||start_autovac_launcher)&&
14861496
pmState==PM_RUN)
14871497
{
@@ -2413,7 +2423,7 @@ reaper(SIGNAL_ARGS)
24132423
*/
24142424
if (WalWriterPID==0)
24152425
WalWriterPID=StartWalWriter();
2416-
if (AutoVacuumingActive()&&AutoVacPID==0)
2426+
if (!IsBinaryUpgrade&&AutoVacuumingActive()&&AutoVacPID==0)
24172427
AutoVacPID=StartAutoVacLauncher();
24182428
if (XLogArchivingActive()&&PgArchPID==0)
24192429
PgArchPID=pgarch_start();

‎src/backend/tcop/postgres.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3238,7 +3238,7 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
32383238
* postmaster/postmaster.c (the option sets should not conflict) and with
32393239
* the common help() function in main/main.c.
32403240
*/
3241-
while ((flag=getopt(argc,argv,"A:B:c:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
3241+
while ((flag=getopt(argc,argv,"A:B:bc:D:d:EeFf:h:ijk:lN:nOo:Pp:r:S:sTt:v:W:-:"))!=-1)
32423242
{
32433243
switch (flag)
32443244
{
@@ -3250,6 +3250,11 @@ process_postgres_switches(int argc, char *argv[], GucContext ctx)
32503250
SetConfigOption("shared_buffers",optarg,ctx,gucsource);
32513251
break;
32523252

3253+
case'b':
3254+
/* Undocumented flag used for binary upgrades */
3255+
IsBinaryUpgrade= true;
3256+
break;
3257+
32533258
case'D':
32543259
if (secure)
32553260
userDoption=strdup(optarg);

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pid_tPostmasterPid = 0;
8585
*/
8686
boolIsPostmasterEnvironment= false;
8787
boolIsUnderPostmaster= false;
88+
boolIsBinaryUpgrade= false;
8889

8990
boolExitOnAnyError= false;
9091

‎src/backend/utils/init/postinit.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,16 @@ InitPostgres(const char *in_dbname, Oid dboid, const char *username,
625625
errmsg("must be superuser to connect during database shutdown")));
626626
}
627627

628+
/*
629+
* Binary upgrades only allowed super-user connections
630+
*/
631+
if (IsBinaryUpgrade&& !am_superuser)
632+
{
633+
ereport(FATAL,
634+
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
635+
errmsg("must be superuser to connect in binary upgrade mode")));
636+
}
637+
628638
/*
629639
* The last few connections slots are reserved for superusers. Although
630640
* replication connections currently require superuser privileges, we

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201104181
56+
#defineCATALOG_VERSION_NO201104251
5757

5858
#endif

‎src/include/miscadmin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ do { \
124124
externpid_tPostmasterPid;
125125
externboolIsPostmasterEnvironment;
126126
externPGDLLIMPORTboolIsUnderPostmaster;
127+
externboolIsBinaryUpgrade;
127128

128129
externboolExitOnAnyError;
129130

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp