如果数据库服务器上的磁盘 space 已满,Postgres 不会启动吗?

Will Postgres not start if disc space on database server is full?

我的 Postgresql 数据库停止工作,这已经关闭了我所有使用它的 Django 应用程序。我尝试用 'service postgresql restart' 重新启动,但它给了我这个响应

* Starting PostgreSQL 9.3 database server                                                                                                                                                                                                     
* The PostgreSQL server failed to start. Please check the log output.

我检查了 /var/log/postgresql 的日志,但最近的日志文件中没有任何内容。之前查过那个,除了一大堆说没有光盘的错误,没觉得有什么特别的space.

/var/log/postgresql/postgresql-9.3-main.log.1

2018-03-15 08:46:09 CDT LOG:  could not write temporary statistics file "pg_stat_tmp/db_12061.tmp": No space left on device
2018-03-15 08:46:09 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-15 08:46:09 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-15 08:46:10 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-15 08:46:10 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-15 08:46:15 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-15 08:46:15 CDT HINT:  Check free disk space.
2018-03-15 08:46:15 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1606764, 'https://content.homenetiol.com/2001722/2120878/640x480/43d0a25930554cdbbbd0834c9803e5ad.jpg', 1) RET$
2018-03-15 08:46:19 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-15 08:46:20 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-16 08:45:49 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-16 08:45:49 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-16 08:45:53 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-16 08:45:53 CDT HINT:  Check free disk space.
2018-03-16 08:45:53 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1587463, 'https://content.homenetiol.com/2001722/2120878/640x480/c80fb80f8dc04c2581872ad2cf221cbc.jpg', 1) RET$
2018-03-16 08:45:59 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-17 08:45:48 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-17 08:45:48 CDT HINT:  Check free disk space.
2018-03-17 08:45:48 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1144699, 'https://content.homenetiol.com/2001722/2120878/640x480/4e7711dd0d5148eeaadd1e8a7f00b0eb.jpg', 1) RET$
2018-03-18 08:45:44 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-18 08:45:44 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-18 08:45:47 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-18 08:45:47 CDT HINT:  Check free disk space.
2018-03-18 08:45:47 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1144694, 'https://content.homenetiol.com/2001722/2120878/640x480/3dee837dd31942c5a26bc73775f07dba.jpg', 0) RET$
2018-03-18 08:45:54 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-18 10:21:40 CDT FATAL:  password authentication failed for user "socialauto"
2018-03-18 10:21:40 CDT DETAIL:  Connection matched pg_hba.conf line 17: "local   all             all                                     md5"
2018-03-15 08:46:15 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-15 08:46:15 CDT HINT:  Check free disk space.
2018-03-15 08:46:15 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1606764, 'https://content.homenetiol.com/2001722/2120878/640x480/43d0a25930554cdbbbd0834c9803e5ad.jpg', 1) RET$
2018-03-15 08:46:19 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-15 08:46:20 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-16 08:45:49 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-16 08:45:49 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-16 08:45:53 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-16 08:45:53 CDT HINT:  Check free disk space.
2018-03-16 08:45:53 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1587463, 'https://content.homenetiol.com/2001722/2120878/640x480/c80fb80f8dc04c2581872ad2cf221cbc.jpg', 1) RET$
2018-03-16 08:45:59 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-17 08:45:48 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-17 08:45:48 CDT HINT:  Check free disk space.
2018-03-17 08:45:48 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1144699, 'https://content.homenetiol.com/2001722/2120878/640x480/4e7711dd0d5148eeaadd1e8a7f00b0eb.jpg', 1) RET$
2018-03-18 08:45:44 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/db_0.tmp": No space left on device
2018-03-18 08:45:44 CDT LOG:  could not close temporary statistics file "pg_stat_tmp/global.tmp": No space left on device
2018-03-18 08:45:47 CDT ERROR:  could not extend file "base/16385/616778.1": No space left on device
2018-03-18 08:45:47 CDT HINT:  Check free disk space.
2018-03-18 08:45:47 CDT STATEMENT:  INSERT INTO "vehicle_vehicleimage" ("vehicle_id", "image_url", "display_sequence") VALUES (1144694, 'https://content.homenetiol.com/2001722/2120878/640x480/3dee837dd31942c5a26bc73775f07dba.jpg', 0) RET$
2018-03-18 08:45:54 CDT LOG:  using stale statistics instead of current ones because stats collector is not responding
2018-03-18 10:21:40 CDT FATAL:  password authentication failed for user "socialauto"

我用'df'命令在托管数据库的虚拟机上检查了磁盘space,确实看起来所有space都用完了

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/root       49300032 49283648         0 100% /
devtmpfs         2014088        4   2014084   1% /dev
none                   4        0         4   0% /sys/fs/cgroup
none              403388      340    403048   1% /run
none                5120        0      5120   0% /run/lock
none             2016924        0   2016924   0% /run/shm
none              102400        0    102400   0% /run/user

每当我尝试使用选项卡自动完成路径时,我也会收到这条奇怪的消息

-bash: cannot create temp file for here-document: No space left on device

是启动 Postgres 和 运行 在我的机器上增加光盘 space 的唯一方法。有什么方法可以使用 'service postgresql restart' 和一些调试标志来查看它面临的错误而不必进入日志文件?

您可以strace服务器进程...

但说真的——如果你不在 space 之列,那就是原因。如果PostgreSQL不能分配新的事务日志,它将拒绝启动。

最简单的方法是启动 postgres 并跟踪日志,就像

tail -f ${PGDATA}/postgresql-$(date --iso-8601)* | grep "ERROR\|FATAL" 

或任何你的日志。

当然,如果没有免费 space,您就无法 运行 数据库。正如您自己提到的,您甚至不能使用 bash 自动完成功能。

如果磁盘已满,您希望数据库如何运行?新数据或日志或事务日志存储在哪里?

为什么不从清理磁盘开始space。找出正在使用磁盘 space 的内容,并删除不需要的内容。卸载不需要的包,清理 /var/log 中的旧日志文件或 /tmp 或 /var/tmp.

中的临时文件

请不要删除 PostgreSQL WAL 文件!