服务器管理技巧
- 使用
pg_ctl确保服务器正确启动/重启 -
场景: 当使用
pg_ctl启动/重启 PostgreSQL 时,输出显示“”,但并未指示服务器是否实际启动,这会导致类似以下的情况。elephant$ pg_ctl -D /path/to/data/ -l /tmp/pg.log start server starting $ psql -d postgres psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?解决方案: 使用
pg_ctl的-w命令行标志,该标志会使pg_ctl等待启动和关闭操作完成(在 PostgreSQL 10 之前,默认仅等待关闭完成)。$ pg_ctl -w -D /path/to/data/ -l /tmp/pg.log start waiting for server to start........ stopped waiting pg_ctl: could not start server Examine the log output.
- 使用位于数据目录之外的
postgresql.conf文件 -
场景: 你需要将
postgresql.conf放在其他位置,例如使服务器管理更轻松。解决方案: 在服务器启动时,向 PostgreSQL 服务器传递“
-c config_file=/path/to/postgresql.conf”。$ pg_ctl -D /path/to/data-directory -o "-c config_file=/path/to/postgresql.conf" -w start waiting for server to start.... done server started
