使用运行在localhost上的psql 9.6.1服务器的PostgreSQL CLI工具,我创建了一个新的表空间
create tablespace my_tablespace location /tmp/data;并发现这创建了一个名为PG_9.6_201608131的目录。
我可以看到9.6是版本,但是最后一个数字字符串是什么?我想用它来创建Makefile中的数据库,所以知道这个数字是如何导出的(而不仅仅是硬编码),这将是很有帮助的。
发布于 2017-01-20 16:48:43
我看了postgres9.6的源代码。
/* tablespace.c */
create_tablespace_directories(const char *location, const Oid tablespaceoid)
{
....
location_with_version_dir = psprintf("%s/%s", location,TABLESPACE_VERSION_DIRECTORY);
....
if (mkdir(location_with_version_dir, S_IRWXU) < 0)
{
....
}
}
/* catalog.h */
#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION"_" \
CppAsString2(CATALOG_VERSION_NO)
/* catversion.h */
#define CATALOG_VERSION_NO 201608131我发现PG_9.6_201608131是由三个部分组成的。
'PG_‘+ PG_MAJORVERSION + '_’+ CATALOG_VERSION_NO
在PostgreSQL9.6中
PG_MAJORVERSION为9.6
CATALOG_VERSION_NO是201608131
PG_MAJORVERSION和CATALOG_VERSION_NO都是c中的宏定义,不会改变。

https://dba.stackexchange.com/questions/161780
复制相似问题