您当前的位置: 首页 >  sql

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

PostgreSQL基础:容器启动错误No space left on device对应方法

发布时间:2020-08-30 19:50:24 ,浏览量:0

在这里插入图片描述

这篇文章记录一下PostgreSQL 12.4的alpine版本启动时的错误信息和对应方法。

环境说明
  • 操作系统版本信息
liumiaocn:~ liumiao$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.15.6
BuildVersion:	19G73
liumiaocn:~ liumiao$
  • Docker版本信息
liumiaocn:~ liumiao$ docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:22:34 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:29:19 2019
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
liumiaocn:~ liumiao$
现象描述

使用docker run无法启动服务,现象如下所示

liumiaocn:~ liumiao$ docker run --name postgres -e POSTGRES_PASSWORD=liuiaocn -d postgres:12.4-alpine
d05e59f051d313ef0f4ebe25929b8555a63827af15b901f96981b12c150d5442
liumiaocn:~ liumiao$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
liumiaocn:~ liumiao$
原因分析

使用docker logs确认日志信息如下所示

liumiaocn:postgres liumiao$ docker logs postgres
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... UTC
creating configuration files ... ok
running bootstrap script ... ok
sh: locale: not found
2020-08-30 06:09:16.165 UTC [30] WARNING:  no usable system locales were found
2020-08-30 06:09:16.428 UTC [30] FATAL:  could not write to file "base/13455/2606_fsm": No space left on device
2020-08-30 06:09:16.428 UTC [30] STATEMENT:  CREATE DATABASE postgres;
	
child process exited with exit code 1
initdb: removing contents of data directory "/var/lib/postgresql/data"
performing post-bootstrap initialization ... liumiaocn:postgres liumiao$ 
liumiaocn:postgres liumiao$

可以看到提示的关键错误信息为:No space left on device。实际上指定volume即可解决。

对应方法

删除原有的postgres容器,使用如下命令启动即可

liumiaocn:postgres liumiao$ docker rm postgres
postgres
liumiaocn:postgres liumiao$ docker run --name postgres -v ${HOME}/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=liuiaocn -d postgres:12.4-alpine
a8ca9cad9abb3f3221b4b078a81a0d247ea8af3fa0edbd25e10179b0b34db55d
liumiaocn:postgres liumiao$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS               NAMES
a8ca9cad9abb        postgres:12.4-alpine   "docker-entrypoint.s…"   3 seconds ago       Up 1 second         5432/tcp            postgres
liumiaocn:postgres liumiao$

确认日志信息也发现已经正常启动了

liumiaocn:postgres liumiao$ docker logs postgres

PostgreSQL Database directory appears to contain a database; Skipping initialization

2020-08-30 06:09:52.094 UTC [1] LOG:  starting PostgreSQL 12.4 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
2020-08-30 06:09:52.094 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-08-30 06:09:52.094 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2020-08-30 06:09:52.097 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-08-30 06:09:52.150 UTC [21] LOG:  database system was shut down at 2020-08-30 06:08:15 UTC
2020-08-30 06:09:52.172 UTC [1] LOG:  database system is ready to accept connections
liumiaocn:postgres liumiao$
补充信息

但也有可能确实是空间不足,此时删除一下空间也有可能会有效,比如:

liumiaocn:postgres liumiao$ docker run --name postgres -v ${HOME}/data:/var/lib/postgresql/data -e POSTGRES_PASSWORD=liuiaocn -d postgres:12.4-alpine
fec5fe8a93d03ca3060cb37badaf4d41aa51e39d6f1df8b0fda25e996dd586c5
liumiaocn:postgres liumiao$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
liumiaocn:postgres liumiao$ docker logs postgres

PostgreSQL Database directory appears to contain a database; Skipping initialization

2020-08-30 22:36:27.574 UTC [1] LOG:  starting PostgreSQL 12.4 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bit
2020-08-30 22:36:27.574 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2020-08-30 22:36:27.574 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2020-08-30 22:36:27.576 UTC [1] FATAL:  could not write lock file "/var/run/postgresql/.s.PGSQL.5432.lock": No space left on device
2020-08-30 22:36:27.577 UTC [1] LOG:  database system is shut down
liumiaocn:postgres liumiao$
  • 删除无用空间
liumiaocn:postgres liumiao$ docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
4f0f1d7cde51c3beac3d595a8f4fbae126cf18a9e489805411313331b22c56e9
...
32400b716b9904a2b9ef6081f44999ea030c7b7501d73c8e1ff2118e26213ee1

Total reclaimed space: 11.26GB
liumiaocn:postgres liumiao$

可以看到清空了11.25G

  • 重新启动
liumiaocn:postgres liumiao$ docker start postgres
postgres
liumiaocn:postgres liumiao$ docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED              STATUS              PORTS               NAMES
fec5fe8a93d0        postgres:12.4-alpine   "docker-entrypoint.s…"   About a minute ago   Up 1 second         5432/tcp            postgres
liumiaocn:postgres liumiao$
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.9155s