Docker 卷 - PG::DiskFull - 设备上没有剩余空间

Dav*_*wys 1 postgresql ruby-on-rails docker docker-compose docker-volume

如何使用 Postgresql 数据库解决 Docker Volume 中的磁盘已满错误。

我不确定问题是否出在 docker、docker 卷或 Postgres 配置上。

环境

MAC 上的 Docker - Postgresql

运行 Rails 应用程序时出现以下错误。

PG::DiskFull: 错误: 无法写入文件“base/pgsql_tmp/pgsql_tmp125.6.sharedfileset/i35of64.p0.0”: 设备上没有剩余空间

导入数据库转储时我也遇到这些类型的问题

错误:无法扩展文件“base/1051062/1259”:设备上没有剩余空间

提示:检查可用磁盘空间。

语句:使用 btree (xyz_id, abc_key) WHERE ((NOT前景) AND (abc_key IS NOT NULL)); 在 public.some_table 上创建索引index_some_table_key

容器壳盘尺寸

docker exec -it pg13 bash

root@51fe1c96f701:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
overlay          59G   56G   26M 100% /
tmpfs            64M     0   64M   0% /dev
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
shm              64M  1.3M   63M   2% /dev/shm
/dev/vda1        59G   56G   26M 100% /etc/hosts
tmpfs           2.0G     0  2.0G   0% /proc/acpi
tmpfs           2.0G     0  2.0G   0% /sys/firmware
Run Code Online (Sandbox Code Playgroud)

我一直在逐渐尝试不同的使用方式pg_restore

# many indexes in the database fail to create
pg_restore -h 127.0.0.1 -U postgres -d "mydb" "mydump.dump"

# when running data only, the restore works
pg_restore --section=pre-data --section=data -h 127.0.0.1 -U postgres -d "mydb" "mydump.dump"

# when running for specific TOCs, I sometimes have success and sometimes have out of disk space errors
pg_restore -v -L x.txt -h 127.0.0.1 -U postgres -d "printspeak_development" "salescrm.dump"

# contents of x.txt
;5971; 1259 31041251 INDEX public index_account_history_data_tenant_source_account_platform_id salescrm
;6138; 1259 2574937 INDEX public index_action_logs_on_action salescrm
Run Code Online (Sandbox Code Playgroud)

已恢复的数据库

我创建了一个数据库并从生产中恢复了转储。

.dump 文件大小为 8GB,导入的数据库大小为 29GB

SELECT pg_size_pretty( pg_database_size('mydb_development') );

 pg_size_pretty
----------------
 29 GB

Run Code Online (Sandbox Code Playgroud)

Docker 组合

volumes:        
   pgdata:

services:
  pg13:
    container_name: "pg13"
    image: "postgres:latest"
    environment:
      POSTGRES_USER: "postgres"
      POSTGRES_PASSWORD: "xyz"

    # Increase the Write Ahead Log size because of warnings.
    command: "postgres -c max_wal_size=2GB"

    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
Run Code Online (Sandbox Code Playgroud)

是什么让这个问题很难弄清楚(误导了我)。

我在 Docker 中有足够的磁盘空间用于数据库+数据+许多索引。

但并不是所有的索引,创建索引也有一定的随机性,有时有效,有时无效。

Dav*_*wys 16

问题在于 Docker 分配的磁盘空间量,最终在 Docker GUI 中进行了简单的修复。

在此输入图像描述