⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postinit.c

📁 关系型数据库 Postgresql 6.5.2
💻 C
📖 第 1 页 / 共 2 页
字号:
		key = atoi(ipc_key);		Assert(MyBackendTag >= 0);	}	postport = getenv("POSTPORT");	if (PointerIsValid(postport))	{		if (MyBackendTag == -1)			elog(FATAL, "InitCommunication: missing POSTID");		/*		 * Enable this if you are trying to force the backend to run as if		 * it is running under the postmaster.		 *		 * This goto forces Postgres to attach to shared memory instead of		 * using malloc'ed memory (which is the normal behavior if run		 * directly).		 *		 * To enable emulation, run the following shell commands (in addition		 * to enabling this goto)		 *		 * % setenv POSTID 1 % setenv POSTPORT 4321 % setenv IPC_KEY 4321000		 * % postmaster & % kill -9 %1		 *		 * Upon doing this, Postmaster will have allocated the shared memory		 * resources that Postgres will attach to if you enable		 * EMULATE_UNDER_POSTMASTER.		 *		 * This comment may well age with time - it is current as of 8		 * January 1990		 *		 * Greg		 */#ifdef EMULATE_UNDER_POSTMASTER		goto forcesharedmemory;#endif	}	else if (IsUnderPostmaster)	{		elog(FATAL,			 "InitCommunication: under postmaster and POSTPORT not set");	}	else	{		/* ----------------		 *	assume we're running a postgres backend by itself with		 *	no front end or postmaster.		 * ----------------		 */		if (MyBackendTag == -1)			MyBackendTag = 1;		key = PrivateIPCKey;	}	/* ----------------	 *	initialize shared memory and semaphores appropriately.	 * ----------------	 */#ifdef EMULATE_UNDER_POSTMASTERforcesharedmemory:#endif	if (!IsUnderPostmaster)		/* postmaster already did this */	{		PostgresIpcKey = key;		AttachSharedMemoryAndSemaphores(key);	}}/* -------------------------------- *		InitStdio * *		this routine consists of a bunch of code fragments *		that used to be randomly scattered through cinit(). *		they all seem to do stuff associated with io. * -------------------------------- */static voidInitStdio(){	DebugFileOpen();}/* -------------------------------- * InitPostgres *		Initialize POSTGRES. * * Note: *		Be very careful with the order of calls in the InitPostgres function. * -------------------------------- */bool		PostgresIsInitialized = false;extern int	NBuffers;/* *	this global is used by wei for testing his code, but must be declared *	here rather than in postgres.c so that it's defined for cinterface.a *	applications. *//*int	testFlag = 0;*/int			lockingOff = 0;/* */voidInitPostgres(char *name)		/* database name */{	bool		bootstrap;		/* true if BootstrapProcessing */	/* ----------------	 *	see if we're running in BootstrapProcessing mode	 * ----------------	 */	bootstrap = IsBootstrapProcessingMode();	/* ----------------	 *	turn on the exception handler.	Note: we cannot use elog, Assert,	 *	AssertState, etc. until after exception handling is on.	 * ----------------	 */	EnableExceptionHandling(true);	/* ----------------	 *	A stupid check to make sure we don't call this more than once.	 *	But things like ReinitPostgres() get around this by just diddling	 *	the PostgresIsInitialized flag.	 * ----------------	 */	AssertState(!PostgresIsInitialized);	/* ----------------	 *	Memory system initialization.	 *	(we may call palloc after EnableMemoryContext())	 *	 *	Note EnableMemoryContext() must happen before EnablePortalManager().	 * ----------------	 */	EnableMemoryContext(true);	/* initializes the "top context" */	EnablePortalManager(true);	/* memory for portal/transaction stuff */	/* ----------------	 *	initialize the backend local portal stack used by	 *	internal PQ function calls.  see src/lib/libpq/be-dumpdata.c	 *	This is different from the "portal manager" so this goes here.	 *	-cim 2/12/91	 * ----------------	 */	be_portalinit();	/* ----------------	 *	 attach to shared memory and semaphores, and initialize our	 *	 input/output/debugging file descriptors.	 * ----------------	 */	InitCommunication();	InitStdio();	/*	 * initialize the local buffer manager	 */	InitLocalBuffer();	if (!TransactionFlushEnabled())		on_shmem_exit(FlushBufferPool, (caddr_t) NULL);	/* ----------------	 *	initialize the database id used for system caches and lock tables	 * ----------------	 */	if (bootstrap)	{		SetDatabasePath(ExpandDatabasePath(name));		SetDatabaseName(name);		LockDisable(true);	}	else	{		VerifySystemDatabase();		InitMyDatabaseInfo(name);		VerifyMyDatabase();	}	/*	 * Code after this point assumes we are in the proper directory!	 *	 * So, how do we implement alternate locations for databases? There are	 * two possible locations for tables and we need to look in	 * DataDir/pg_database to find the true location of an individual	 * database. We can brute-force it as done in InitMyDatabaseInfo(), or	 * we can be patient and wait until we open pg_database gracefully.	 * Will try that, but may not work... - thomas 1997-11-01	 */	/* Does not touch files (?) - thomas 1997-11-01 */	smgrinit();	/* ----------------	 *	initialize the transaction system and the relation descriptor cache.	 *	Note we have to make certain the lock manager is off while we do this.	 * ----------------	 */	AmiTransactionOverride(IsBootstrapProcessingMode());	LockDisable(true);	/*	 * Part of the initialization processing done here sets a read lock on	 * pg_log.	Since locking is disabled the set doesn't have intended	 * effect of locking out writers, but this is ok, since we only lock	 * it to examine AMI transaction status, and this is never written	 * after initdb is done. -mer 15 June 1992	 */	RelationInitialize();		/* pre-allocated reldescs created here */	InitializeTransactionSystem();		/* pg_log,etc init/crash recovery										 * here */	LockDisable(false);	/* ----------------	 *	anyone knows what this does?  something having to do with	 *	system catalog cache invalidation in the case of multiple	 *	backends, I think -cim 10/3/90	 *	Sets up MyBackendId a unique backend identifier.	 * ----------------	 */	InitSharedInvalidationState();	/* ----------------	 * Set up a per backend process in shared memory.  Must be done after	 * InitSharedInvalidationState() as it relies on MyBackendId being	 * initialized already.  XXX -mer 11 Aug 1991	 * ----------------	 */	InitProcess(PostgresIpcKey);	if (MyBackendId > MAXBACKENDS || MyBackendId <= 0)	{		elog(FATAL, "cinit2: bad backend id %d (%d)",			 MyBackendTag,			 MyBackendId);	}	/* ----------------	 *	initialize the access methods.	 *	Does not touch files (?) - thomas 1997-11-01	 * ----------------	 */	initam();	/* ----------------	 *	initialize all the system catalog caches.	 * ----------------	 */	zerocaches();	/*	 * Does not touch files since all routines are builtins (?) - thomas	 * 1997-11-01	 */	InitCatalogCache();	/* ----------------	 *	 set ourselves to the proper user id and figure out our postgres	 *	 user id.  If we ever add security so that we check for valid	 *	 postgres users, we might do it here.	 * ----------------	 */	InitUserid();	/* ----------------	 *	 initialize local data in cache invalidation stuff	 * ----------------	 */	if (!bootstrap)		InitLocalInvalidateData();	/* ----------------	 *	ok, all done, now let's make sure we don't do it again.	 * ----------------	 */	PostgresIsInitialized = true;/*	  on_shmem_exit(DestroyLocalRelList, (caddr_t) NULL); */	/* ----------------	 *	Done with "InitPostgres", now change to NormalProcessing unless	 *	we're in BootstrapProcessing mode.	 * ----------------	 */	if (!bootstrap)		SetProcessingMode(NormalProcessing);/*	  if (testFlag || lockingOff) */	if (lockingOff)		LockDisable(true);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -