
Traditionally, "pg_ctl start -w" has waited for the server to become ready to accept connections by attempting a connection once per second. That has the major problem that connection issues (for instance, a kernel packet filter blocking traffic) can't be reliably told apart from server startup issues, and the minor problem that if server startup isn't quick, we accumulate "the database system is starting up" spam in the server log. We've hacked around many of the possible connection issues, but it resulted in ugly and complicated code in pg_ctl.c. In commit c61559ec3, I changed the probe rate to every tenth of a second. That prompted Jeff Janes to complain that the log-spam problem had become much worse. In the ensuing discussion, Andres Freund pointed out that we could dispense with connection attempts altogether if the postmaster were changed to report its status in postmaster.pid, which "pg_ctl start" already relies on being able to read. This patch implements that, teaching postmaster.c to report a status string into the pidfile at the same state-change points already identified as being of interest for systemd status reporting (cf commit 7d17e683f). pg_ctl no longer needs to link with libpq at all; all its functions now depend on reading server files. In support of this, teach AddToDataDirLockFile() to allow addition of postmaster.pid lines in not-necessarily-sequential order. This is needed on Windows where the SHMEM_KEY line will never be written at all. We still have the restriction that we don't want to truncate the pidfile; document the reasons for that a bit better. Also, fix the pg_ctl TAP tests so they'll notice if "start -w" mode is broken --- before, they'd just wait out the sixty seconds until the loop gives up, and then report success anyway. (Yes, I found that out the hard way.) While at it, arrange for pg_ctl to not need to #include miscadmin.h; as a rather low-level backend header, requiring that to be compilable client-side is pretty dubious. This requires moving the #define's associated with the pidfile into a new header file, and moving PG_BACKEND_VERSIONSTR someplace else. For lack of a clearly better "someplace else", I put it into port.h, beside the declaration of find_other_exec(), since most users of that macro are passing the value to find_other_exec(). (initdb still depends on miscadmin.h, but at least pg_ctl and pg_upgrade no longer do.) In passing, fix main.c so that PG_BACKEND_VERSIONSTR actually defines the output of "postgres -V", which remarkably it had never done before. Discussion: https://postgr.es/m/CAMkU=1xJW8e+CTotojOMBd-yzUvD0e_JZu2xHo=MnuZ4__m7Pg@mail.gmail.com
206 lines
4.8 KiB
C
206 lines
4.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* config_info.c
|
|
* Common code for pg_config output
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
*
|
|
* IDENTIFICATION
|
|
* src/common/config_info.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef FRONTEND
|
|
#include "postgres.h"
|
|
#else
|
|
#include "postgres_fe.h"
|
|
#endif
|
|
|
|
#include "common/config_info.h"
|
|
|
|
|
|
/*
|
|
* get_configdata(const char *my_exec_path, size_t *configdata_len)
|
|
*
|
|
* Get configure-time constants. The caller is responsible
|
|
* for pfreeing the result.
|
|
*/
|
|
ConfigData *
|
|
get_configdata(const char *my_exec_path, size_t *configdata_len)
|
|
{
|
|
ConfigData *configdata;
|
|
char path[MAXPGPATH];
|
|
char *lastsep;
|
|
int i = 0;
|
|
|
|
/* Adjust this to match the number of items filled below */
|
|
*configdata_len = 23;
|
|
configdata = (ConfigData *) palloc(*configdata_len * sizeof(ConfigData));
|
|
|
|
configdata[i].name = pstrdup("BINDIR");
|
|
strlcpy(path, my_exec_path, sizeof(path));
|
|
lastsep = strrchr(path, '/');
|
|
if (lastsep)
|
|
*lastsep = '\0';
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("DOCDIR");
|
|
get_doc_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("HTMLDIR");
|
|
get_html_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("INCLUDEDIR");
|
|
get_include_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("PKGINCLUDEDIR");
|
|
get_pkginclude_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("INCLUDEDIR-SERVER");
|
|
get_includeserver_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LIBDIR");
|
|
get_lib_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("PKGLIBDIR");
|
|
get_pkglib_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LOCALEDIR");
|
|
get_locale_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("MANDIR");
|
|
get_man_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("SHAREDIR");
|
|
get_share_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("SYSCONFDIR");
|
|
get_etc_path(my_exec_path, path);
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("PGXS");
|
|
get_pkglib_path(my_exec_path, path);
|
|
strlcat(path, "/pgxs/src/makefiles/pgxs.mk", sizeof(path));
|
|
cleanup_path(path);
|
|
configdata[i].setting = pstrdup(path);
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("CONFIGURE");
|
|
#ifdef VAL_CONFIGURE
|
|
configdata[i].setting = pstrdup(VAL_CONFIGURE);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("CC");
|
|
#ifdef VAL_CC
|
|
configdata[i].setting = pstrdup(VAL_CC);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("CPPFLAGS");
|
|
#ifdef VAL_CPPFLAGS
|
|
configdata[i].setting = pstrdup(VAL_CPPFLAGS);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("CFLAGS");
|
|
#ifdef VAL_CFLAGS
|
|
configdata[i].setting = pstrdup(VAL_CFLAGS);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("CFLAGS_SL");
|
|
#ifdef VAL_CFLAGS_SL
|
|
configdata[i].setting = pstrdup(VAL_CFLAGS_SL);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LDFLAGS");
|
|
#ifdef VAL_LDFLAGS
|
|
configdata[i].setting = pstrdup(VAL_LDFLAGS);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LDFLAGS_EX");
|
|
#ifdef VAL_LDFLAGS_EX
|
|
configdata[i].setting = pstrdup(VAL_LDFLAGS_EX);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LDFLAGS_SL");
|
|
#ifdef VAL_LDFLAGS_SL
|
|
configdata[i].setting = pstrdup(VAL_LDFLAGS_SL);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("LIBS");
|
|
#ifdef VAL_LIBS
|
|
configdata[i].setting = pstrdup(VAL_LIBS);
|
|
#else
|
|
configdata[i].setting = pstrdup(_("not recorded"));
|
|
#endif
|
|
i++;
|
|
|
|
configdata[i].name = pstrdup("VERSION");
|
|
configdata[i].setting = pstrdup("PostgreSQL " PG_VERSION);
|
|
i++;
|
|
|
|
Assert(i == *configdata_len);
|
|
|
|
return configdata;
|
|
}
|