Postgresql 错误:无法写入临时文件的块37583345:设备上没有剩余空间
我想要这样的输出:Postgresql 错误:无法写入临时文件的块37583345:设备上没有剩余空间,postgresql,postgresql-12,Postgresql,Postgresql 12,我想要这样的输出: obid | sid_count 1 | 3 2 | 2 3 | 4 obid位于custdata表上,sid_计数从标识符表中获取 样本数据为: custdata obid 1 2 3 identifier obid | type 1 | SID 1 | SID 1 | XID 1 | SID 2 | SID 2 | SID 3 | SID 3 | SID 3
obid | sid_count
1 | 3
2 | 2
3 | 4
obid位于custdata表上,sid_计数从标识符表中获取
样本数据为:
custdata
obid
1
2
3
identifier
obid | type
1 | SID
1 | SID
1 | XID
1 | SID
2 | SID
2 | SID
3 | SID
3 | SID
3 | XID
3 | SID
3 | SID
我尝试运行此查询:
select custdata.obid,
count (identifier.obid) filter (where identifier.type = 'SID') as sid_count
from myschema.custdata, myschema.identifier group by custdata.obid
大约花了一个小时,但出现了一个错误:
[53100] ERROR: could not write block 37583345 of temporary file: No space left on device
数据约为6500万条记录。
标识符约为2.5亿条记录
如何克服这个问题?为什么数据库需要写入磁盘?还是我需要重写我的查询?因为我无法向磁盘添加更多空间
谢谢。问题是您无意中编写了交叉联接:
from myschema.custdata, myschema.identifier
也就是说,一个表的2.5亿行中的每一行都与另一个表的6500万行中的每一行相连接,从而产生1625万亿个结果行。您的数据目录似乎没有空间缓存完成查询所需的临时数据,因此您的磁盘空间不足
作为解决方案,添加联接条件
抓住机会,学会不再像这样写连接。始终使用标准语法:
FROM a JOIN b ON <condition>
这将更加明显
FROM a CROSS JOIN b