1 Star 0 Fork 0

中启开源 / check_tablespace

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
check_tablespace.c 2.49 KB
一键复制 编辑 原始数据 按行查看 历史
osdba 提交于 2024-01-23 11:10 . first commit
/*********************************************************************************
*Copyright(C),2022-2023, csudata.com
*Author: osdba
*Date: 2023.05.15
*Description:
**********************************************************************************/
//#include <inttypes.h>
//#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include "postgres.h"
#include "fmgr.h"
#include "funcapi.h"
#include "storage/latch.h"
#include "pgstat.h"
#include "utils/guc.h"
#include "access/xact.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(csufb_start);
void _PG_init(void);
void _PG_fini(void);
void
_PG_init(void)
{
char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)];
DIR *spc_dir;
struct dirent *spc_de;
MemoryContext tmpctx,
oldctx;
DIR *dir;
if (IsBinaryUpgrade)
{
return;
}
if (!process_shared_preload_libraries_in_progress)
{
return;
}
/*
* Just to be sure we don't leak any memory, let's create a temporary
* memory context for this operation.
*/
tmpctx = AllocSetContextCreate(CurrentMemoryContext,
"ResetUnloggedRelations",
ALLOCSET_DEFAULT_SIZES);
oldctx = MemoryContextSwitchTo(tmpctx);
/*
* First process unlogged files in pg_default ($PGDATA/base)
*/
spc_dir = AllocateDir("base");
if (spc_dir == NULL && errno == ENOENT)
{
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not open directory \"base\": %m")));
return;
}
FreeDir(spc_dir);
spc_dir = AllocateDir("pg_tblspc");
if (spc_dir == NULL && errno == ENOENT)
{
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not open directory \"pg_tblspc\": %m")));
return;
}
while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL)
{
if (strcmp(spc_de->d_name, ".") == 0 ||
strcmp(spc_de->d_name, "..") == 0)
continue;
if (strspn(spc_de->d_name, "0123456789") != strlen(spc_de->d_name))
continue;
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s",
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
if ((dir = opendir(temp_path)) != NULL)
{
closedir(dir);
}
else
{
FreeDir(spc_dir);
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not open directory(check_tablespace) \"%s\": %m", temp_path)));
return;
}
}
FreeDir(spc_dir);
/*
* Restore memory context.
*/
MemoryContextSwitchTo(oldctx);
MemoryContextDelete(tmpctx);
}
void _PG_fini(void)
{
;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/csudata/check_tablespace.git
git@gitee.com:csudata/check_tablespace.git
csudata
check_tablespace
check_tablespace
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891