here it is as requested by Bruce.

I tested it restoring my database with > 100000 BLOBS, and dumping it out.
But unfortunatly I can not restore it back due to problems in pg_dump.

--
Sincerely Yours,
Denis Perchine
This commit is contained in:
Bruce Momjian 2000-10-21 15:55:29 +00:00
parent 33581195d5
commit 293d1e5f2c
10 changed files with 561 additions and 1111 deletions

View File

@ -2,7 +2,7 @@
#
# Makefile for catalog
#
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.28 2000/10/20 21:03:42 petere Exp $
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.29 2000/10/21 15:55:21 momjian Exp $
#
#-------------------------------------------------------------------------
@ -11,7 +11,8 @@ top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
OBJS = catalog.o heap.o index.o indexing.o aclchk.o \
pg_aggregate.o pg_operator.o pg_proc.o pg_type.o
pg_aggregate.o pg_largeobject.o pg_operator.o pg_proc.o \
pg_type.o
BKIFILES = global.bki template1.bki global.description template1.description
@ -29,7 +30,7 @@ TEMPLATE1_BKI_SRCS := $(addprefix $(top_srcdir)/src/include/catalog/,\
pg_proc.h pg_type.h pg_attribute.h pg_class.h \
pg_inherits.h pg_index.h pg_statistic.h \
pg_operator.h pg_opclass.h pg_am.h pg_amop.h pg_amproc.h \
pg_language.h \
pg_language.h pg_largeobject.h \
pg_aggregate.h pg_ipl.h pg_inheritproc.h \
pg_rewrite.h pg_listener.h pg_description.h indexing.h \
)

View File

@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.69 2000/10/08 03:53:13 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.70 2000/10/21 15:55:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -51,6 +51,8 @@ char *Name_pg_inherits_indices[Num_pg_inherits_indices] =
{InheritsRelidSeqnoIndex};
char *Name_pg_language_indices[Num_pg_language_indices] =
{LanguageOidIndex, LanguageNameIndex};
char *Name_pg_largeobject_indices[Num_pg_largeobject_indices] =
{LargeobjectLOIdIndex, LargeobjectLOIdPNIndex};
char *Name_pg_listener_indices[Num_pg_listener_indices] =
{ListenerPidRelnameIndex};
char *Name_pg_opclass_indices[Num_pg_opclass_indices] =

View File

@ -0,0 +1,135 @@
/*-------------------------------------------------------------------------
*
* pg_largeobject.c
* routines to support manipulation of the pg_largeobject relation
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_largeobject.c,v 1.3 2000/10/21 15:55:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "catalog/catname.h"
#include "catalog/indexing.h"
#include "catalog/pg_largeobject.h"
#include "miscadmin.h"
#include "utils/fmgroids.h"
bytea *_byteain(const char *data, int32 size);
bytea *_byteain(const char *data, int32 size) {
bytea *result;
result = (bytea *)palloc(size + VARHDRSZ);
result->vl_len = size + VARHDRSZ;
if (size > 0)
memcpy(result->vl_dat, data, size);
return result;
}
Oid LargeobjectCreate(Oid loid) {
Oid retval;
Relation pg_largeobject;
HeapTuple ntup = (HeapTuple) palloc(sizeof(HeapTupleData));
Relation idescs[Num_pg_largeobject_indices];
Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject];
int i;
for (i=0; i<Natts_pg_largeobject; i++) {
nulls[i] = ' ';
values[i] = (Datum)NULL;
}
i = 0;
values[i++] = ObjectIdGetDatum(loid);
values[i++] = Int32GetDatum(0);
values[i++] = (Datum) _byteain(NULL, 0);
pg_largeobject = heap_openr(LargeobjectRelationName, RowExclusiveLock);
ntup = heap_formtuple(pg_largeobject->rd_att, values, nulls);
retval = heap_insert(pg_largeobject, ntup);
if (!IsIgnoringSystemIndexes()) {
CatalogOpenIndices(Num_pg_largeobject_indices, Name_pg_largeobject_indices, idescs);
CatalogIndexInsert(idescs, Num_pg_largeobject_indices, pg_largeobject, ntup);
CatalogCloseIndices(Num_pg_largeobject_indices, idescs);
}
heap_close(pg_largeobject, RowExclusiveLock);
heap_freetuple(ntup);
CommandCounterIncrement();
return retval;
}
void LargeobjectDrop(Oid loid) {
Relation pg_largeobject;
Relation pg_lo_id;
ScanKeyData skey;
IndexScanDesc sd = (IndexScanDesc) NULL;
RetrieveIndexResult indexRes;
int found = 0;
ScanKeyEntryInitialize(&skey,
(bits16) 0x0,
(AttrNumber) 1,
(RegProcedure) F_OIDEQ,
ObjectIdGetDatum(loid));
pg_largeobject = heap_openr(LargeobjectRelationName, RowShareLock);
pg_lo_id = index_openr(LargeobjectLOIdIndex);
sd = index_beginscan(pg_lo_id, false, 1, &skey);
while((indexRes = index_getnext(sd, ForwardScanDirection))) {
found++;
heap_delete(pg_largeobject, &indexRes->heap_iptr, NULL);
pfree(indexRes);
}
index_endscan(sd);
index_close(pg_lo_id);
heap_close(pg_largeobject, RowShareLock);
if (found == 0)
elog(ERROR, "LargeobjectDrop: large object %d not found", loid);
}
int LargeobjectFind(Oid loid) {
int retval = 0;
Relation pg_lo_id;
ScanKeyData skey;
IndexScanDesc sd = (IndexScanDesc) NULL;
RetrieveIndexResult indexRes;
ScanKeyEntryInitialize(&skey,
(bits16) 0x0,
(AttrNumber) 1,
(RegProcedure) F_OIDEQ,
ObjectIdGetDatum(loid));
pg_lo_id = index_openr(LargeobjectLOIdIndex);
sd = index_beginscan(pg_lo_id, false, 1, &skey);
if ((indexRes = index_getnext(sd, ForwardScanDirection))) {
retval = 1;
pfree(indexRes);
}
index_endscan(sd);
index_close(pg_lo_id);
return retval;
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.52 2000/10/08 03:53:13 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.53 2000/10/21 15:55:22 momjian Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
@ -267,7 +267,7 @@ lo_creat(PG_FUNCTION_ARGS)
PG_RETURN_OID(InvalidOid);
}
lobjId = RelationGetRelid(lobjDesc->heap_r);
lobjId = lobjDesc->id;
inv_close(lobjDesc);
@ -512,8 +512,10 @@ lo_commit(bool isCommit)
{
if (cookies[i] != NULL)
{
/*
if (isCommit)
inv_cleanindex(cookies[i]);
*/
cookies[i] = NULL;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.170 2000/10/13 00:43:31 pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.171 2000/10/21 15:55:26 momjian Exp $
*
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
*
@ -1104,7 +1104,7 @@ dumpBlobs(Archive *AH, char* junkOid, void *junkVal)
fprintf(stderr, "%s saving BLOBs\n", g_comment_start);
/* Cursor to get all BLOB tables */
appendPQExpBuffer(oidQry, "Declare blobOid Cursor for SELECT oid from pg_class where relkind = '%c'", RELKIND_LOBJECT);
appendPQExpBuffer(oidQry, "Declare blobOid Cursor for SELECT loid from pg_largeobject");
res = PQexec(g_conn, oidQry->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: catname.h,v 1.14 2000/10/08 03:53:15 momjian Exp $
* $Id: catname.h,v 1.15 2000/10/21 15:55:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -29,6 +29,7 @@
#define InheritsRelationName "pg_inherits"
#define InheritancePrecidenceListRelationName "pg_ipl"
#define LanguageRelationName "pg_language"
#define LargeobjectRelationName "pg_largeobject"
#define ListenerRelationName "pg_listener"
#define LogRelationName "pg_log"
#define OperatorClassRelationName "pg_opclass"

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: indexing.h,v 1.42 2000/10/08 03:53:15 momjian Exp $
* $Id: indexing.h,v 1.43 2000/10/21 15:55:28 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -31,6 +31,7 @@
#define Num_pg_index_indices 2
#define Num_pg_inherits_indices 1
#define Num_pg_language_indices 2
#define Num_pg_largeobject_indices 2
#define Num_pg_listener_indices 1
#define Num_pg_opclass_indices 2
#define Num_pg_operator_indices 2
@ -62,6 +63,8 @@
#define InheritsRelidSeqnoIndex "pg_inherits_relid_seqno_index"
#define LanguageNameIndex "pg_language_name_index"
#define LanguageOidIndex "pg_language_oid_index"
#define LargeobjectLOIdIndex "pg_largeobject_loid_index"
#define LargeobjectLOIdPNIndex "pg_largeobject_loid_pn_index"
#define ListenerPidRelnameIndex "pg_listener_pid_relname_index"
#define OpclassDeftypeIndex "pg_opclass_deftype_index"
#define OpclassNameIndex "pg_opclass_name_index"
@ -92,6 +95,7 @@ extern char *Name_pg_group_indices[];
extern char *Name_pg_index_indices[];
extern char *Name_pg_inherits_indices[];
extern char *Name_pg_language_indices[];
extern char *Name_pg_largeobject_indices[];
extern char *Name_pg_listener_indices[];
extern char *Name_pg_opclass_indices[];
extern char *Name_pg_operator_indices[];
@ -191,6 +195,8 @@ DECLARE_UNIQUE_INDEX(pg_index_indexrelid_index on pg_index using btree(indexreli
DECLARE_UNIQUE_INDEX(pg_inherits_relid_seqno_index on pg_inherits using btree(inhrelid oid_ops, inhseqno int4_ops));
DECLARE_UNIQUE_INDEX(pg_language_name_index on pg_language using btree(lanname name_ops));
DECLARE_UNIQUE_INDEX(pg_language_oid_index on pg_language using btree(oid oid_ops));
DECLARE_INDEX(pg_largeobject_loid_index on pg_largeobject using btree(loid oid_ops));
DECLARE_UNIQUE_INDEX(pg_largeobject_loid_pn_index on pg_largeobject using btree(loid oid_ops, pageno int4_ops));
DECLARE_UNIQUE_INDEX(pg_listener_pid_relname_index on pg_listener using btree(listenerpid int4_ops, relname name_ops));
/* This column needs to allow multiple zero entries, but is in the cache */
DECLARE_INDEX(pg_opclass_deftype_index on pg_opclass using btree(opcdeftype oid_ops));

View File

@ -0,0 +1,63 @@
/*-------------------------------------------------------------------------
*
* pg_largeobject.h
* definition of the system "largeobject" relation (pg_largeobject)
* along with the relation's initial contents.
*
*
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_largeobject.h,v 1.3 2000/10/21 15:55:28 momjian Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
* information from the DATA() statements.
*
*-------------------------------------------------------------------------
*/
#ifndef PG_LARGEOBJECT_H
#define PG_LARGEOBJECT_H
/* ----------------
* postgres.h contains the system type definintions and the
* CATALOG(), BOOTSTRAP and DATA() sugar words so this file
* can be read by both genbki.sh and the C compiler.
* ----------------
*/
/* ----------------
* pg_largeobject definition. cpp turns this into
* typedef struct FormData_pg_largeobject. Large object id
* is stored in loid;
* ----------------
*/
CATALOG(pg_largeobject)
{
Oid loid;
int4 pageno;
bytea data;
} FormData_pg_largeobject;
/* ----------------
* Form_pg_largeobject corresponds to a pointer to a tuple with
* the format of pg_largeobject relation.
* ----------------
*/
typedef FormData_pg_largeobject *Form_pg_largeobject;
/* ----------------
* compiler constants for pg_largeobject
* ----------------
*/
#define Natts_pg_largeobject 3
#define Anum_pg_largeobject_loid 1
#define Anum_pg_largeobject_pageno 2
#define Anum_pg_largeobject_data 3
Oid LargeobjectCreate(Oid loid);
void LargeobjectDrop(Oid loid);
int LargeobjectFind(Oid loid);
#endif /* PG_LARGEOBJECT_H */

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: large_object.h,v 1.15 2000/10/08 03:53:15 momjian Exp $
* $Id: large_object.h,v 1.16 2000/10/21 15:55:29 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -22,17 +22,11 @@
/*
* This structure will eventually have lots more stuff associated with it.
*/
typedef struct LargeObjectDesc
{
Relation heap_r; /* heap relation */
Relation index_r; /* index relation on seqno attribute */
IndexScanDesc iscan; /* index scan we're using */
TupleDesc hdesc; /* heap relation tuple desc */
TupleDesc idesc; /* index relation tuple desc */
uint32 lowbyte; /* low byte on the current page */
uint32 highbyte; /* high byte on the current page */
typedef struct LargeObjectDesc {
Relation heap_r;
Relation index_r;
uint32 offset; /* current seek pointer */
ItemPointerData htid; /* tid of current heap tuple */
Oid id;
#define IFS_RDLOCK (1 << 0)
#define IFS_WRLOCK (1 << 1)
@ -55,7 +49,4 @@ extern int inv_tell(LargeObjectDesc *obj_desc);
extern int inv_read(LargeObjectDesc *obj_desc, char *buf, int nbytes);
extern int inv_write(LargeObjectDesc *obj_desc, char *buf, int nbytes);
/* added for buffer leak prevention [ PA ] */
extern void inv_cleanindex(LargeObjectDesc *obj_desc);
#endif /* LARGE_OBJECT_H */