src/bin/pg_dump/pg_dump.c
static int
dumpBlobs(Archive *fout, const void *arg)
{
	const char *blobQry;
	const char *blobFetchQry;
	PGconn	   *conn = GetConnection(fout);
	PGresult   *res;
	char		buf[LOBBUFSIZE];
	int			ntups;
	int			i;
	int			cnt;

	pg_log_info("saving large objects");

	/*
	 * Currently, we re-fetch all BLOB OIDs using a cursor.  Consider scanning
	 * the already-in-memory dumpable objects instead...
	 */
	blobQry =
		"DECLARE bloboid CURSOR FOR "
		"SELECT oid FROM pg_largeobject_metadata ORDER BY 1";

	ExecuteSqlStatement(fout, blobQry);

	/* Command to fetch from cursor */
	blobFetchQry = "FETCH 1000 IN bloboid";

	do
	{
		/* Do a fetch */
		res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);

		/* Process the tuples, if any */
		ntups = PQntuples(res);
		for (i = 0; i < ntups; i++)
		{
			Oid			blobOid;
			int			loFd;

			blobOid = atooid(PQgetvalue(res, i, 0));
			/* Open the BLOB */
			loFd = lo_open(conn, blobOid, INV_READ);
			if (loFd == -1)
				fatal("could not open large object %u: %s",
					  blobOid, PQerrorMessage(conn));

			StartBlob(fout, blobOid);

			/* Now read it in chunks, sending data to archive */
			do
			{
				cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
				if (cnt < 0)
					fatal("error reading large object %u: %s",
						  blobOid, PQerrorMessage(conn));

				WriteData(fout, buf, cnt);
			} while (cnt > 0);

			lo_close(conn, loFd);

			EndBlob(fout, blobOid);
		}

		PQclear(res);
	} while (ntups > 0);

	return 1;
}
/*
 * dumpBlobs:
 *	dump the data contents of all large objects
 */
dump the data contents of all large objects
dump the data contents of all large objects
static int
dumpBlobs(Archive *fout, const void *arg)
{
	const char *blobQry;
	const char *blobFetchQry;
	PGconn	   *conn = GetConnection(fout);
	PGresult   *res;
	char		buf[LOBBUFSIZE];
	int			ntups;
	int			i;
	int			cnt;
	pg_log_info("saving large objects");
	blobQry =
		"DECLARE bloboid CURSOR FOR "
		"SELECT oid FROM pg_largeobject_metadata ORDER BY 1";
	ExecuteSqlStatement(fout, blobQry);
	blobFetchQry = "FETCH 1000 IN bloboid";
	do
	{
		res = ExecuteSqlQuery(fout, blobFetchQry, PGRES_TUPLES_OK);
		ntups = PQntuples(res);
		for (i = 0; i < ntups; i++)
		{
			Oid			blobOid;
			int			loFd;
			blobOid = atooid(PQgetvalue(res, i, 0));
			loFd = lo_open(conn, blobOid, INV_READ);
			if (loFd == -1)
				fatal("could not open large object %u: %s",
					  blobOid, PQerrorMessage(conn));
			StartBlob(fout, blobOid);
			do
			{
				cnt = lo_read(conn, loFd, buf, LOBBUFSIZE);
				if (cnt < 0)
					fatal("error reading large object %u: %s",
						  blobOid, PQerrorMessage(conn));
				WriteData(fout, buf, cnt);
			} while (cnt > 0);
			lo_close(conn, loFd);
			EndBlob(fout, blobOid);
		}
		PQclear(res);
	} while (ntups > 0);
	return 1;
}
static int dumpBlobs ( Archive * fout , const void * arg ) { const char * blobQry ; const char * blobFetchQry ; PGconn * conn = GetConnection ( fout ) ; PGresult * res ; char buf [ LOBBUFSIZE ] ; int ntups ; int i ; int cnt ; pg_log_info ( " " ) ; blobQry = " " " " ; ExecuteSqlStatement ( fout , blobQry ) ; blobFetchQry = " " ; do { res = ExecuteSqlQuery ( fout , blobFetchQry , PGRES_TUPLES_OK ) ; ntups = PQntuples ( res ) ; for ( i = 0 ; i < ntups ; i ++ ) { Oid blobOid ; int loFd ; blobOid = atooid ( PQgetvalue ( res , i , 0 ) ) ; loFd = lo_open ( conn , blobOid , INV_READ ) ; if ( loFd == -1 ) fatal ( " " , blobOid , PQerrorMessage ( conn ) ) ; StartBlob ( fout , blobOid ) ; do { cnt = lo_read ( conn , loFd , buf , LOBBUFSIZE ) ; if ( cnt < 0 ) fatal ( " " , blobOid , PQerrorMessage ( conn ) ) ; WriteData ( fout , buf , cnt ) ; } while ( cnt > 0 ) ; lo_close ( conn , loFd ) ; EndBlob ( fout , blobOid ) ; } PQclear ( res ) ; } while ( ntups > 0 ) ; return 1 ; }
dumpBlobs:
      dump the data contents of all large objects
dumpBlobs : dump the data contents of all large objects
/*
	 * Currently, we re-fetch all BLOB OIDs using a cursor.  Consider scanning
	 * the already-in-memory dumpable objects instead...
	 */ /* Command to fetch from cursor */ /* Do a fetch */ /* Process the tuples, if any */ /* Open the BLOB */ /* Now read it in chunks, sending data to archive */