pg_ctl当您不记得数据库目录是什么,也没有定义 PGDATA 环境变量时,您如何用(或以其他方式)很好地停止所有 postgres 进程?
Cra*_*ger 68
可以安全地:
sudo pkill -u postgres
Run Code Online (Sandbox Code Playgroud)
这会杀死以 user 身份运行的所有进程postgres。或者:
pkill postgres
Run Code Online (Sandbox Code Playgroud)
这会杀死所有名为“postgres”的进程。
千万不能使用kill -9(kill -KILL)。只是kill(没有选项)做了一个SIGTERM,这就是你想要的。
或者,如果您可以连接到 PostgreSQL,您可以检查 pgdata 位置。例如:
sudo -u postgres psql -c "SHOW data_directory";
Run Code Online (Sandbox Code Playgroud)
...或通过在 中检查其环境变量,您可以在其中使用. 寻找其他进程的父进程。例如:/proc/[postmaster pid]/environps -fHC postgrespostgres
postgres 794 1 0 Nov06 ? 00:00:03 /usr/pgsql-9.3/bin/postgres -D /var/lib/pgsql/9.3/data -p 5432
postgres 857 794 0 Nov06 ? 00:00:00 postgres: logger process
postgres 871 794 0 Nov06 ? 00:00:00 postgres: checkpointer process
postgres 872 794 0 Nov06 ? 00:00:00 postgres: writer process
postgres 873 794 0 Nov06 ? 00:00:00 postgres: wal writer process
postgres 874 794 0 Nov06 ? 00:00:03 postgres: autovacuum launcher process
postgres 875 794 0 Nov06 ? 00:00:07 postgres: stats collector process
Run Code Online (Sandbox Code Playgroud)
它的 datadir 通常会显示在它的命令行上。
在同一个命令中看到kill 和postgres 让我感到紧张。要仅使用 回答问题pg_ctl,那就是:
pg_ctl -D $(psql -Xtc 'show data_directory') stop
Run Code Online (Sandbox Code Playgroud)
-X 参数表示忽略.psqlrc文件。如果您将 psql 配置为发出查询所花费的时间(通过 \timing 命令),这非常有用。
-t 参数表示删除输出顶部的列名和生成的总行数。
-c 参数包含要执行的 SQL 代码。
运行 barepsql -c 'show data_directory'可能会产生以下输出:
data_directory
--------------------------
/path/to/postgresql/data
(1 row)
Run Code Online (Sandbox Code Playgroud)
因此,反引号$( ... )将传递/path/to/postgresql/data给 pg_ctl 的 -D 参数,然后该参数将以有序的方式停止数据库。
| 归档时间: |
|
| 查看次数: |
130016 次 |
| 最近记录: |