postgresql FRONTEND、EXEC_BACKEND宏定义的作用

FONTEND宏主要用于标记某些可能会在libpq客户端使用的场景,虽然他们主要用于服务端。如下:

/*
 * Although this header file is nominally backend-only, certain frontend
 * programs like pg_controldata include it via postgres.h.  For some compilers
 * it's necessary to hide the inline definition of MemoryContextSwitchTo in
 * this scenario; hence the #ifndef FRONTEND.
 */

#ifndef FRONTEND
static inline MemoryContext
MemoryContextSwitchTo(MemoryContext context)
{
    MemoryContext old = CurrentMemoryContext;

    CurrentMemoryContext = context;
    return old;
}
#endif                            /* FRONTEND */

 典型的一处用途是pg_waldump获取下一个可读取的wal record位置,如下:

#ifdef FRONTEND
extern XLogRecPtr XLogFindNextRecord(XLogReaderState *state, XLogRecPtr RecPtr);
#endif                            /* FRONTEND */

 

 

 

 并且看起来,主要用于windows下为主。

============================

除了FRONTEND宏定义外,还有一个EXEC_BACKEND宏定义。主要使用在PostgreSQL源代码 postmaster.c 的BackendStartup 函数中,如下:

#ifdef EXEC_BACKEND                                
    pid = backend_forkexec(port);                            
#else                            /* !EXEC_BACKEND */    
    pid = fork_process();    
        ....                        
#endif   /* EXEC_BACKEND */

经相关上下文搜索以及网上资料参考,看起来也是windows使用为主。因为我们不支持windows版,所以编译日志选项中确实是没有出现过EXEC_BACKEND这个宏标志。

https://my.oschina.net/ashnah/blog/3132343

https://www.cnblogs.com/gaojian/archive/2012/07/19/2598959.html

通过grep可以搜索到pg中的所有宏开关,如下:

[zjh@hs-10-20-30-193 postgresql-13.3]$ grep -r "#ifdef HAVE_" | awk '{print $NF}' | grep HAVE | sort | uniq
HAVE_ASN1_STRING_GET0_DATA
HAVE_ATOMIC_H
HAVE_ATOMICS
HAVE_BACKTRACE_SYMBOLS
HAVE_BE_TLS_GET_CERTIFICATE_HASH
HAVE_BIO_METH_NEW
HAVE_BUGGY_SOLARIS_STRTOD
HAVE_BUGGY_STRTOF
HAVE__BUILTIN_CLZ
HAVE__BUILTIN_CONSTANT_P
HAVE__BUILTIN_CTZ
HAVE__BUILTIN_FRAME_ADDRESS
HAVE__BUILTIN_POPCOUNT
HAVE__BUILTIN_TYPES_COMPATIBLE_P
HAVE_CLOCK_GETTIME
HAVE_COMPUTED_GOTO
HAVE__CONFIGTHREADLOCALE
HAVE_COPYFILE_H
HAVE__CPUID
HAVE_CRYPTO_LOCK
HAVE_DLOPEN
HAVE_EXECINFO_H
HAVE_FDATASYNC
HAVE_FLOCK
HAVE_FSYNC_WRITETHROUGH
HAVE_FUNCNAME__FUNC
HAVE_FUNCNAME__FUNCTION
HAVE_GCC__SYNC_INT32_TAS
HAVE_GETADDRINFO
HAVE__GET_CPUID
HAVE_GETOPT_H
HAVE_GETRLIMIT
HAVE_GETRUSAGE
HAVE_HSTRERROR
HAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P
HAVE_IFADDRS_H
HAVE_INT128
HAVE_INT64_TIMESTAMP
HAVE_INT_OPTERR
HAVE_INT_OPTRESET
HAVE_INTTYPES_H
HAVE_IPSET_ATTR_IFACE
HAVE_IPV6
HAVE_KERNEL_OS_H
HAVE_LANGINFO_H
HAVE_LDAP_INITIALIZE
HAVE_LIBCURL
HAVE_LIBREADLINE
HAVE_LIBZ
HAVE_LIMITS_H
HAVE_LINUX_EIDRM_BUG
HAVE_LINUX_IP_VS_H
HAVE_LINUX_NETFILTER_X_TABLES_H
HAVE_LOCALE_T
HAVE_LONG_INT_64
HAVE_LONG_LONG_INT_64
HAVE_MBARRIER_H
HAVE_MBSTOWCS_L
HAVE_NET_IF_H
HAVE_NETINET_TCP_H
HAVE_OPENSSL_INIT_SSL
HAVE_PAM_PAM_APPL_H
HAVE_PG_ATTRIBUTE_NORETURN
HAVE_PGTLS_GET_PEER_CERTIFICATE_HASH
HAVE_PIPE2
HAVE_POLL
HAVE_POLL_H
HAVE_PREAD
HAVE_PS_STRINGS
HAVE_PTHREAD_IS_THREADED_NP
HAVE_PWRITE
HAVE_READLINK
HAVE_REPLICATION_ORIGINS
HAVE_RL_COMPLETION_APPEND_CHARACTER
HAVE_RL_COMPLETION_SUPPRESS_QUOTE
HAVE_RL_FILENAME_QUOTE_CHARACTERS
HAVE_RL_FILENAME_QUOTING_FUNCTION
HAVE_RL_RESET_SCREEN_SIZE
HAVE_SECURITY_PAM_APPL_H
HAVE_SETSID
HAVE_SHM_OPEN
HAVE__STATIC_ASSERT
HAVE_STDBOOL_H
HAVE_STDINT_H
HAVE_STRERROR_R
HAVE_STRING_H
HAVE_STRINGS_H
HAVE_STRSIGNAL
HAVE_STRTOLL
HAVE_STRTOULL
HAVE_STRUCT_CMSGCRED
HAVE_STRUCT_SOCKADDR_SA_LEN
HAVE_STRUCT_SOCKADDR_STORAGE
HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN
HAVE_STRUCT_SOCKADDR_UN
HAVE_SYMLINK
HAVE_SYNC_FILE_RANGE
HAVE_SYS_EPOLL_H
HAVE_SYS_EVENT_H
HAVE_SYS_IPC_H
HAVE_SYSLOG
HAVE_SYS_PRCTL_H
HAVE_SYS_PROCCTL_H
HAVE_SYS_PSTAT_H
HAVE_SYS_RESOURCE_H
HAVE_SYS_SELECT_H
HAVE_SYS_SEM_H
HAVE_SYS_SHM_H
HAVE_SYS_SOCKIO_H
HAVE_SYS_STAT_H
HAVE_SYS_TYPES_H
HAVE_SYS_UCRED_H
HAVE_SYS_UN_H
HAVE_TERMIOS_H
HAVE_TYPEOF
HAVE_UCOL_STRCOLLUTF8
HAVE_UCRED_H
HAVE_UNISTD_H
HAVE_UNIX_SOCKETS
HAVE_USELOCALE
HAVE_UUID_BSD
HAVE_UUID_E2FS
HAVE_UUID_OSSP
HAVE_VFORK_H
HAVE_WCSTOMBS_L
HAVE_WCTYPE_H
HAVE_WORKING_LINK
HAVE_X509_GET_SIGNATURE_NID
HAVE_X86_64_POPCNTQ
HAVE_XMLSTRUCTUREDERRORCONTEXT
HAVE_XT_SET_INFO_MATCH_V4

 

posted @ 2021-10-25 20:12  zhjh256  阅读(278)  评论(0编辑  收藏  举报