我有一张表存放一些图像。最近我不得不运行一些测试,我必须删除所有表的所有行,然后再次插入新行,所以我不得不多次导入相同的图像。完成后我注意到它在我的驱动器中占用了大量空间,所以我尝试运行vacuumlo
来回收这个空间,但什么也没发生。程序运行完毕,没有错误,并显示消息
"找到0个对象"
或类似的东西。我做错了什么?
答案 0 :(得分:1)
vacuumlo是一个简单的实用程序,可以删除任何“孤儿” PostgreSQL数据库中的大对象。孤立的大型物体 (LO)被认为是任何其OID不出现在任何oid中的LO 或者数据库的数据列。
您可以手动检查孤儿,将pg_largeobject
加入所有lo表。例如:让我们创建几个lo表并用数据填充它们:
b=# create table l_o (n text, o oid);
CREATE TABLE
b=# create table lo (n text, p oid);
CREATE TABLE
b=# insert into l_o values('one',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
b=# insert into l_o values('two',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
b=# insert into l_o values('three',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
b=# insert into lo values('one',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
b=# insert into l_o values('two',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
现在检查孤儿:
b=# with l_o as (select o,'l_o' tname from l_o union all select p,'lo' from lo)
b-# select distinct loid, o, tname
b-# from pg_largeobject left outer join l_o on l_o.o = loid;
loid | o | tname
-------+-------+-------
34530 | 34530 | lo
34528 | 34528 | l_o
34527 | 34527 | l_o
34529 | 34529 | l_o
34531 | 34531 | l_o
(5 rows)
无。现在使用vacuumlo
:
b=# \! vacuumlo -v -n b
Connected to database "b"
Test run: no large objects will be removed!
Checking o in public.l_o
Checking p in public.lo
Would remove 0 large objects from database "b".
相同。现在重现你的情况 - 删除,重新创建并重新填充表格:
b=# drop table lo;
DROP TABLE
b=# create table lo (n text, p oid);
CREATE TABLE
b=# insert into lo values('one',lo_import ('/tmp/wheel.PNG'));
INSERT 0 1
干运行:
b=# \! vacuumlo -v -n b
Connected to database "b"
Test run: no large objects will be removed!
Checking o in public.l_o
Checking p in public.lo
Would remove 1 large objects from database "b".
检查pg_largeobject
:
b=# with l_o as (select o,'l_o' tname from l_o union all select p,'lo' from lo)
select distinct loid, o, tname
from pg_largeobject left outer join l_o on l_o.o = loid;
loid | o | tname
-------+-------+-------
34528 | 34528 | l_o
34531 | 34531 | l_o
34550 | 34550 | lo
34527 | 34527 | l_o
34529 | 34529 | l_o
34530 | |
(6 rows)
是 - 一个孤儿(“lo”表有一行,掉线并重新填充一行orphain)
运行vacuumlo
来修复它:
b=# \! vacuumlo -v b
Connected to database "b"
Checking o in public.l_o
Checking p in public.lo
Successfully removed 1 large objects from database "b".
检查结果:
b=# with l_o as (select o,'l_o' tname from l_o union all select p,'lo' from lo)
select distinct loid, o, tname
from pg_largeobject left outer join l_o on l_o.o = loid;
loid | o | tname
-------+-------+-------
34528 | 34528 | l_o
34531 | 34531 | l_o
34550 | 34550 | lo
34527 | 34527 | l_o
34529 | 34529 | l_o
(5 rows)
是的 - 一切都清楚。现在查看vacuumlo
:
b=# \! vacuumlo -v -n b
Connected to database "b"
Test run: no large objects will be removed!
Checking o in public.l_o
Checking p in public.lo
Would remove 0 large objects from database "b".