译者简介
晏杰宏,任职于上海新炬网络信息技术股份有限公司,Oracle DBA。负责数据库、中间件、大数据等基础软件建设、优化和业务保障工作。具有10年以上电信与银行企业一线/二线数据库运维管理经验。目前专注研究云计算、开源软件和国产化数据库等领域技术研究。
校对者简介
崔鹏,任职于海能达通信股份有限公司,数据库开发高级工程师,致力于postgresql数据库在专网通信领域、公共安全领域的应用与推广。
使用PostgreSQL BLOB接口
test=# CREATE TABLE t_image (id int, name text, image bytea);CREATE TABLEtest=# \d t_imageTable "public.t_image"Column | Type | Collation | Nullable | Default-------+---------+-----------+----------+---------id | integer | | |name | text | | |image | bytea | | |
test=# SHOW bytea_output;bytea_output--------------hex(1 row)
test=# SELECT lo_import('/etc/hosts');lo_import-----------80343(1 row)
test=# CREATE TABLE t_file (id int,name text,object_id oid);CREATE TABLEtest=# INSERT INTO t_fileVALUES (1, 'some_name', lo_import('/etc/hosts'))RETURNING *;id | name | object_id----+---------------+-----------1 | some_name | 80350(1 row)1个 INSERT 0 1
test=# DELETE FROM t_file WHERE id = 1;DELETE 1
test=# \xExpanded display is on.test=# SELECT * FROM pg_largeobject WHERE loid = 80350;-[ RECORD 1 ]------------------------------------------loid | 80350pageno | 0data | ##\012# Host Database\012#\012# localhost ...
test=# \xExpanded display is off.test=#test=# SELECT lo_unlink(80350);lo_unlink-----------1(1 row)test=# SELECT * FROM pg_largeobject WHERE loid = 80350;loid | pageno | data------+--------+------(0 rows)
vacuumlo:清理死的大对象
test=# SELECT lo_import('/etc/hosts');lo_import-----------80351(1 row)
iMac:~ hs$ vacuumlo -h localhost -v testConnected to database "test"Checking object_id in public.t_fileSuccessfully removed 2 large objects from database "test".
附加功能
test=# \df lo_*List of functionsSchema | Name | Result data type | Argument data types | Type------------+---------------+------------------+---------------------------+------pg_catalog | lo_close | integer | integer | funcpg_catalog | lo_creat | oid | integer | funcpg_catalog | lo_create | oid | oid | funcpg_catalog | lo_export | integer | oid, text | funcpg_catalog | lo_from_bytea | oid | oid, bytea | funcpg_catalog | lo_get | bytea | oid | funcpg_catalog | lo_get | bytea | oid, bigint, integer | funcpg_catalog | lo_import | oid | text | funcpg_catalog | lo_import | oid | text, oid | funcpg_catalog | lo_lseek | integer | integer, integer, integer | funcpg_catalog | lo_lseek64 | bigint | integer, bigint, integer | funcpg_catalog | lo_open | integer | oid, integer | funcpg_catalog | lo_put | void | oid, bigint, bytea | funcpg_catalog | lo_tell | integer | integer | funcpg_catalog | lo_tell64 | bigint | integer | funcpg_catalog | lo_truncate | integer | integer, integer | funcpg_catalog | lo_truncate64 | integer | integer, bigint | funcpg_catalog | lo_unlink | integer | oid | func(18 rows)
1个2 pg_catalog | loread | bytea | integer, integer | funcpg_catalog | lowrite | integer | integer, bytea | func
最后
PostgreSQL中文社区欢迎广大技术人员投稿
投稿邮箱:press@postgres.cn
文章转载自PostgreSQL中文社区,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




