【发布时间】:2021-09-18 12:15:37
【问题描述】:
如何使用 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”:设备上没有剩余空间
提示:检查可用磁盘空间。
STATEMENT: CREATE INDEX index_some_table_key ON public.some_table USING btree (xyz_id, abc_key) WHERE ((NOT deleted) AND (abc_key IS NOT NULL));
容器外壳磁盘大小
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
我一直在逐步尝试使用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
已恢复的数据库
我创建了一个数据库并从生产中恢复了一个转储。
.dump 文件大小为 8GB,导入的数据库大小为 29GB
SELECT pg_size_pretty( pg_database_size('mydb_development') );
pg_size_pretty
----------------
29 GB
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
是什么让这个问题难以弄清楚(误导了我)。
我在 Docker 中有足够的磁盘空间用于数据库 + 数据 + 许多索引。
但不是所有的索引,创建索引也有一些随机性,有时它们有效,有时它们没有。
【问题讨论】:
标签: ruby-on-rails postgresql docker docker-compose docker-volume