今天在使用 ALTER SYSTEM 来修改 PostgreSQL 参数时遇到无法启动数据库的问题。如下所示:
1 2 3 4 5 6 7 8 9 10 11
postgres=# ALTER SYSTEM SET shared_preload_libraries TO 'pg_buffercache,passwordcheck'; ALTER SYSTEM postgres=# \q $ pg_ctl restart waiting for server to shut down.... done server stopped waiting for server to start....postgres: could not access directory "/Users/japinli/Codes/postgresql/pg/data": No such file or directory Run initdb or pg_basebackup to initialize a PostgreSQL data directory. stopped waiting pg_ctl: could not start server Examine the log output.
你是否也遇到了这样的问题呢?其实这都是由于我们先入为主的思想导致的,ALTER SYSTEM 支持以逗号分割的列表,而这类参数的修改不需要使用引号。因此,正确的使用方式如下:
1
ALTER SYSTEM SET shared_preload_libraries TO pg_buffercache, passwordcheck;
while (scanner_isspace(*nextp)) nextp++; /* skip leading whitespace */
if (*nextp == '\0') returntrue; /* allow empty string */
/* At the top of the loop, we are at start of a new directory. */ do { char *curname; char *endp;
if (*nextp == '"') { /* Quoted name --- collapse quote-quote pairs */ curname = nextp + 1; for (;;) { endp = strchr(nextp + 1, '"'); if (endp == NULL) returnfalse; /* mismatched quotes */ if (endp[1] != '"') break; /* found end of quoted name */ /* Collapse adjacent quotes into one quote, and look again */ memmove(endp, endp + 1, strlen(endp)); nextp = endp; } /* endp now points at the terminating quote */ nextp = endp + 1; } else { /* Unquoted name --- extends to separator or end of string */ curname = endp = nextp; while (*nextp && *nextp != separator) { /* trailing whitespace should not be included in name */ if (!scanner_isspace(*nextp)) endp = nextp + 1; nextp++; } if (curname == endp) returnfalse; /* empty unquoted name not allowed */ }
while (scanner_isspace(*nextp)) nextp++; /* skip trailing whitespace */
if (*nextp == separator) { nextp++; while (scanner_isspace(*nextp)) nextp++; /* skip leading whitespace for next */ /* we expect another name, so done remains false */ } elseif (*nextp == '\0') done = true; else returnfalse; /* invalid syntax */
/* Now safe to overwrite separator with a null */ *endp = '\0';
/* Truncate path if it's overlength */ if (strlen(curname) >= MAXPGPATH) curname[MAXPGPATH - 1] = '\0';
/* * Finished isolating current name --- add it to list */ curname = pstrdup(curname); canonicalize_path(curname); *namelist = lappend(*namelist, curname);
/* Loop back if we didn't reach end of string */ } while (!done);