### Installation and Setup Source: https://context7.com/pgedge/lolor/llms.txt Instructions for building, installing, and setting up the lolor extension in a PostgreSQL database. ```APIDOC ## Installation and Setup ### Build and Install from Source ```bash # Ensure pg_config is in PATH export PATH=/usr/pgsql-17/bin:$PATH # Compile and install make USE_PGXS=1 make USE_PGXS=1 install ``` ### Create the Extension in PostgreSQL ```sql -- Connect to your database and create the extension CREATE EXTENSION lolor; -- Set the required node parameter (1 to 2^28) SET lolor.node = 1; -- Optionally update search_path to use lolor schema SET search_path = lolor, "$user", public, pg_catalog; ``` ``` -------------------------------- ### Compile and Install lolor Extension Source: https://github.com/pgedge/lolor/blob/main/README.md Instructions for compiling and installing the lolor extension from source code using PGXS. This process involves setting the PATH to include pg_config, compiling the code, and then installing it. Sudo privileges may be required for the installation step. ```bash export PATH=/usr/pgsql-17/bin:$PATH # compile make USE_PGXS=1 # install, might be requiring sudo for the installation step make USE_PGXS=1 install ``` -------------------------------- ### Compile and Install lolor Extension from Source Source: https://github.com/pgedge/lolor/blob/main/docs/install_configure.md Compiles and installs the lolor extension from its source code using PGXS. Ensure your PATH includes the `pg_config` directory. This method requires build tools and the PostgreSQL development headers. ```bash export PATH=/opt/pg16/bin:$PATH # compile make USE_PGXS=1 make USE_PGXS=1 install ``` -------------------------------- ### Install lolor Extension using pgEdge CLI Source: https://github.com/pgedge/lolor/blob/main/docs/install_configure.md Installs the lolor extension using the pgEdge Update Manager (`um`) module. This is the recommended method for installing the extension after pgEdge Distributed Postgres is set up. ```bash ./pgedge um install lolor ``` -------------------------------- ### Build and Install lolor Extension from Source Source: https://context7.com/pgedge/lolor/llms.txt Compiles and installs the lolor PostgreSQL extension from its source code. Ensure the PostgreSQL development environment (pg_config) is accessible in your PATH before running these commands. ```bash # Ensure pg_config is in PATH export PATH=/usr/pgsql-17/bin:$PATH # Compile and install make USE_PGXS=1 make USE_PGXS=1 install ``` -------------------------------- ### Install Go Packages for pgEdge lolor Tests Source: https://github.com/pgedge/lolor/blob/main/tests/go/README.md Installs the required Go modules for the pgEdge lolor test suite. This includes the pgx module for PostgreSQL interaction and the properties module for configuration. ```bash go get github.com/jackc/pgx/v5 go get github.com/magiconair/properties ``` -------------------------------- ### Replication Setup with pgEdge spock Source: https://context7.com/pgedge/lolor/llms.txt Configure lolor tables for replication across a pgEdge cluster. ```APIDOC ## Replication Setup with pgEdge spock ### Description Configure lolor tables for replication across a pgEdge cluster. ### Method Bash (CLI) and SQL ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash # Add lolor tables to replication set on each node ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject' lolor_db ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject_metadata' lolor_db ``` ```sql -- Verify replication tables are configured SELECT * FROM spock.replication_set_table WHERE set_name = 'spock_replication_set' AND relname LIKE 'pg_largeobject%'; ``` ### Response #### Success Response (Bash/SQL Result) - **Bash**: Command executes successfully. - **SQL**: Returns rows from `spock.replication_set_table` if the tables are configured for replication. #### Response Example (Bash command output varies) ``` set_name | schema_name | relname | add_type | updated_at | created_at ----------+-------------+---------------------+----------+---------------------+--------------------- spock_replication_set | lolor | pg_largeobject | 1 | 2023-10-27 10:00:00 | 2023-10-27 10:00:00 spock_replication_set | lolor | pg_largeobject_metadata | 1 | 2023-10-27 10:00:00 | 2023-10-27 10:00:00 (2 rows) ``` ``` -------------------------------- ### Spock Replication Setup for lolor Large Objects Source: https://github.com/pgedge/lolor/blob/main/tests/junit/multinode/README.md Shell commands to configure Spock replication for the 'lolor' extension's large object tables ('pg_largeobject' and 'pg_largeobject_metadata'). This ensures that large objects are replicated across nodes. ```bash # All Nodes ./pgedge spock repset-create lolor_tables_rs test_db # Node1 ./pgedge spock sub-add-repset sub_n1n2 lolor_tables_rs test_db ./pgedge spock sub-add-repset sub_n1n3 lolor_tables_rs test_db # Node2 ./pgedge spock sub-add-repset sub_n2n1 lolor_tables_rs test_db ./pgedge spock sub-add-repset sub_n2n3 lolor_tables_rs test_db # Node3 ./pgedge spock sub-add-repset sub_n3n1 lolor_tables_rs test_db ./pgedge spock sub-add-repset sub_n3n2 lolor_tables_rs test_db # All Nodes # psql -d test_db CREATE EXTENSION lolor; ./pgedge spock repset-add-table lolor_tables_rs 'lolor.pg_largeobject' test_db ./pgedge spock repset-add-table lolor_tables_rs 'lolor.pg_largeobject_metadata' test_db ``` -------------------------------- ### Create lolor Extension in Postgres Source: https://github.com/pgedge/lolor/blob/main/README.md Command to create the lolor extension within a PostgreSQL database after it has been installed. This enables the functionality of the extension for managing large objects with logical replication. ```sql CREATE EXTENSION lolor; ``` -------------------------------- ### Open and Close Large Object Descriptor using lo_open and lo_close Source: https://context7.com/pgedge/lolor/llms.txt Demonstrates opening a Large Object for reading and/or writing within a transaction using `lo_open` and closing its descriptor with `lo_close`. This is necessary for performing read/write operations on Large Objects. The example shows creating, opening, writing, closing, then reopening for reading and closing again. ```sql -- Large Object operations require a transaction BEGIN; -- Create a new large object SELECT lo_creat(-1) AS loid; -- Assume this returns 1100433 -- Open the object for writing (0x60000 = read/write mode) SELECT lo_open(1100433, x'60000'::int) AS fd; -- Returns file descriptor, e.g., 0 -- Write data using the descriptor SELECT lowrite(0, 'Example large object'); -- Returns number of bytes written: 20 -- Close the descriptor SELECT lo_close(0); -- Returns 0 on success COMMIT; -- Read the data back BEGIN; SELECT lo_open(1100433, 262144) AS fd; -- 262144 = read mode SELECT convert_from(loread(0, 1024), 'UTF8'); -- Returns: 'Example large object' SELECT lo_close(0); COMMIT; ``` -------------------------------- ### Read and Write Large Object Data using loread and lowrite Source: https://context7.com/pgedge/lolor/llms.txt Provides examples of reading data from and writing data to an open Large Object descriptor using `loread` and `lowrite` functions. These functions are used in conjunction with `lo_open` and `lo_close` to manipulate Large Object content within transactions. ```sql BEGIN; -- Create and open a large object for writing SELECT lo_creat(-1) AS loid; -- Returns e.g., 1100500 SELECT lo_open(1100500, x'60000'::int) AS fd; -- Returns e.g., 0 -- Write binary data SELECT lowrite(0, E'\x48656c6c6f20576f726c64'); -- "Hello World" in hex -- Returns: 11 SELECT lo_close(0); COMMIT; BEGIN; -- Open for reading SELECT lo_open(1100500, 262144) AS fd; -- Read 100 bytes from the object SELECT loread(0, 100); -- Returns: \x48656c6c6f20576f726c64 SELECT lo_close(0); COMMIT; ``` -------------------------------- ### Set search_path for lolor Schema Source: https://github.com/pgedge/lolor/blob/main/docs/install_configure.md Modifies the `search_path` to prioritize tables within the `lolor` schema for large object operations. This ensures that lolor's custom tables are used over default ones. ```sql SET search_path=lolor,"$user",public,pg_catalog ``` -------------------------------- ### Create Empty Large Object with Specified OID using lo_create Source: https://context7.com/pgedge/lolor/llms.txt Creates a new, empty Large Object with a specific OID using the lolor extension. If the provided OID is already in use, the system will automatically assign a new, unique OID. The example demonstrates verifying the object's metadata. ```sql -- Create an empty large object with a specific OID SELECT lo_create(200000); -- Returns: -- lo_create -- ----------- -- 200000 -- Verify the object metadata SELECT * FROM lolor.pg_largeobject_metadata WHERE oid = 200000; -- Returns: -- oid | lomowner | lomacl -- --------+----------+-------- -- 200000 | 10 | ``` -------------------------------- ### Export Large Object to File using lo_export Source: https://context7.com/pgedge/lolor/llms.txt Exports the data of an existing Large Object from the PostgreSQL database to a specified file on the operating system's filesystem using the lolor extension. The example first creates and populates a large object before exporting it. ```sql -- First, create and populate a large object SELECT lo_from_bytea(0, 'This is the content to export'); -- Returns the OID of the created object -- Export the large object to a file SELECT lo_export(1100450, '/tmp/exported_data.txt'); -- Returns 1 on success ``` -------------------------------- ### Import File into Large Object using lo_import Source: https://context7.com/pgedge/lolor/llms.txt Imports the content of an operating system file into a new Large Object within the PostgreSQL database using the lolor extension. The function returns the OID of the newly created Large Object. The example also shows how to view the imported data. ```sql -- Import a file from the filesystem SELECT lo_import('/etc/os-release'); -- Returns: -- lo_import -- ----------- -- 1100449 -- View the imported data SELECT loid, pageno, encode(data, 'escape') AS content FROM lolor.pg_largeobject WHERE loid = 1100449; -- Returns the file contents stored as binary data in chunks ``` -------------------------------- ### lo_tell / lo_tell64 - Get current position Source: https://context7.com/pgedge/lolor/llms.txt Returns the current read/write position within an open Large Object. ```APIDOC ## lo_tell / lo_tell64 - Get current position ### Description Returns the current read/write position within an open Large Object. ### Method SQL (within a transaction) ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql BEGIN; SELECT lo_open(1100500, x'60000'::int) AS fd; -- Get current position (starts at 0) SELECT lo_tell(0); -- Returns: 0 -- Write some data SELECT lowrite(0, 'Some data here'); -- Returns: 14 -- Check position after write SELECT lo_tell(0); -- Returns: 14 -- For 64-bit position SELECT lo_tell64(0); -- Returns: 14 SELECT lo_close(0); COMMIT; ``` ### Response #### Success Response (SQL Result) - **Return Value** (integer) - The current position of the cursor within the large object. #### Response Example `0` `14` ``` -------------------------------- ### Seek within Large Object (lo_lseek, lo_lseek64) Source: https://context7.com/pgedge/lolor/llms.txt Repositions the read/write cursor within an open Large Object. `lo_lseek` uses 32-bit offsets, while `lo_lseek64` supports 64-bit offsets for larger files. Both functions take the file descriptor, the desired offset, and a whence parameter (0 for start, 1 for current, 2 for end). ```sql BEGIN; -- Open existing large object for read/write SELECT lo_open(1100500, x'60000'::int) AS fd; -- Seek to position 15 from start (whence=0) SELECT lo_lseek(0, 15, 0); -- Returns: 15 -- For large files, use 64-bit version SELECT lo_lseek64(0, 1000000000, 0); -- Returns: 1000000000 SELECT lo_close(0); COMMIT; ``` -------------------------------- ### Disable lolor Extension using psql Source: https://github.com/pgedge/lolor/blob/main/docs/pg_upgrade_with_lolor.md This snippet shows how to disable the 'lolor' PostgreSQL extension using the `psql` command-line client. This is a prerequisite step before running `pg_upgrade` to ensure a smooth upgrade process. It assumes you are connected to the database where 'lolor' is installed. ```sql db1_17=# SELECT lolor.disable(); ``` -------------------------------- ### Get current Large Object position (lo_tell, lo_tell64) Source: https://context7.com/pgedge/lolor/llms.txt Returns the current read/write position within an open Large Object. `lo_tell` returns a 32-bit position, while `lo_tell64` returns a 64-bit position. These functions are useful for tracking progress during read/write operations. ```sql BEGIN; SELECT lo_open(1100500, x'60000'::int) AS fd; -- Get current position (starts at 0) SELECT lo_tell(0); -- Returns: 0 -- Write some data SELECT lowrite(0, 'Some data here'); -- Returns: 14 -- Check position after write SELECT lo_tell(0); -- Returns: 14 -- For 64-bit position SELECT lo_tell64(0); -- Returns: 14 SELECT lo_close(0); COMMIT; ``` -------------------------------- ### Execute pg_upgrade Command for PostgreSQL Upgrade Source: https://github.com/pgedge/lolor/blob/main/docs/pg_upgrade_with_lolor.md This snippet provides a sample command for executing the `pg_upgrade` utility to migrate PostgreSQL data between two versions. It includes essential parameters such as old and new data directories, and binary directories. The `--link` option is used for performance optimization by creating hard links instead of copying data. ```bash # pg_upgrade --old-datadir=/data/db1_17 \ --new-datadir=/data/db1_18 \ --old-bindir=/usr/lib/postgresql/17/bin \ --new-bindir=/usr/lib/postgresql/18/bin \ --link ``` -------------------------------- ### Prepare and Re-enable lolor Extension for pg_upgrade Source: https://context7.com/pgedge/lolor/llms.txt Demonstrates the necessary steps to manage the 'lolor' extension during a PostgreSQL upgrade using pg_upgrade. It involves disabling the extension before running pg_upgrade and re-enabling it afterward to ensure data integrity and replication continuity. Uses standard psql commands. ```bash # Before pg_upgrade: disable lolor psql -d mydb -c "SELECT lolor.disable();" # Run pg_upgrade pg_upgrade --old-datadir=/data/pg17 \ --new-datadir=/data/pg18 \ --old-bindir=/usr/lib/postgresql/17/bin \ --new-bindir=/usr/lib/postgresql/18/bin \ --link # After pg_upgrade: re-enable lolor psql -d mydb -c "SELECT lolor.enable();" ``` -------------------------------- ### Create Large Object with lolor Source: https://github.com/pgedge/lolor/blob/main/docs/using_lolor.md Demonstrates creating a large object with no initial data and retrieving its object identifier (oid). This is useful for pre-allocating space for large objects. ```sql SELECT lo_creat (-1); -- Returns the oid of the newly created large object. ``` ```sql SELECT lo_create (200000); -- Creates a large object with a specified oid (200000). ``` -------------------------------- ### Run pgEdge lolor Unit Tests Source: https://github.com/pgedge/lolor/blob/main/tests/go/README.md Executes the unit tests for the pgEdge lolor extension using the Go testing framework. The `-v` flag provides verbose output, showing the status of each test. ```bash $ go test -v ``` -------------------------------- ### Import File as Large Object with lolor Source: https://github.com/pgedge/lolor/blob/main/docs/using_lolor.md Demonstrates importing an operating system file into the database as a large object and retrieving its oid. This is useful for storing binary data or large text files. ```sql SELECT lo_import ('/etc/os-release'); -- Imports the content of '/etc/os-release' as a large object and returns its oid. ``` -------------------------------- ### Create Large Object in Go with pgx Source: https://context7.com/pgedge/lolor/llms.txt Creates a PostgreSQL Large Object using the pgx Go library. It begins a transaction, uses the LargeObjects interface to create a new OID, opens the object for writing, writes the provided string data, and commits the transaction. Returns the OID of the created object or an error. Requires a pgx connection. ```go package main import ( "context" "fmt" "github.com/jackc/pgx/v5" ) func createLargeObject(conn *pgx.Conn, data string) (uint32, error) { ctx := context.Background() tx, err := conn.Begin(ctx) if err != nil { return 0, err } lo := tx.LargeObjects() oid, err := lo.Create(ctx, 0) if err != nil { tx.Rollback(ctx) return 0, err } obj, err := lo.Open(ctx, oid, pgx.LargeObjectModeWrite) if err != nil { tx.Rollback(ctx) return 0, err } _, err = obj.Write([]byte(data)) if err != nil { tx.Rollback(ctx) return 0, err } obj.Close() tx.Commit(ctx) return oid, nil } ``` -------------------------------- ### lo_from_bytea - Create Large Object from bytea Source: https://context7.com/pgedge/lolor/llms.txt Creates a Large Object directly from bytea data. Simpler alternative to lo_create + lo_open + lowrite. ```APIDOC ## lo_from_bytea - Create Large Object from bytea ### Description Creates a Large Object directly from bytea data. Simpler alternative to lo_create + lo_open + lowrite. ### Method SQL ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql -- Create a large object with data in one call SELECT lo_from_bytea(0, 'Example large object stored in lolor'); -- Returns the OID of the created object -- With specific OID SELECT lo_from_bytea(300000, 'Data with specific OID'); -- Returns: 300000 (or new OID if 300000 was taken) ``` ### Response #### Success Response (SQL Result) - **Return Value** (oid) - The OID of the newly created large object. #### Response Example `16480` `300000` ``` -------------------------------- ### loread / lowrite - Read and write Large Object data Source: https://context7.com/pgedge/lolor/llms.txt Reads from or writes to an open Large Object descriptor. ```APIDOC ## loread / lowrite - Read and write Large Object data Reads from or writes to an open Large Object descriptor. ### Method `SELECT` ### Endpoint `lowrite(fd, data)` `loread(fd, count)` ### Parameters #### Query Parameters for `lowrite` - **fd** (integer) - Required - The file descriptor obtained from `lo_open`. - **data** (bytea) - Required - The binary data to write to the large object. #### Query Parameters for `loread` - **fd** (integer) - Required - The file descriptor obtained from `lo_open`. - **count** (integer) - Required - The number of bytes to read from the large object. ### Response #### Success Response (200) - **lowrite** (integer) - The number of bytes written. - **loread** (bytea) - The binary data read from the large object. ### Example Usage (Write) ```sql BEGIN; -- Create and open a large object for writing SELECT lo_creat(-1) AS loid; -- Returns e.g., 1100500 SELECT lo_open(1100500, x'600000'::int) AS fd; -- Returns e.g., 0 -- Write binary data SELECT lowrite(0, E'\x48656c6c6f20576f726c64'); -- "Hello World" in hex -- Returns: 11 SELECT lo_close(0); COMMIT; ``` ### Example Usage (Read) ```sql BEGIN; -- Open for reading SELECT lo_open(1100500, 2) AS fd; -- 2 = read mode -- Read 100 bytes from the object SELECT loread(0, 100); -- Returns: \x48656c6c6f20576f726c64 SELECT lo_close(0); COMMIT; ``` ``` -------------------------------- ### Create lolor Extension and Configure Node in PostgreSQL Source: https://context7.com/pgedge/lolor/llms.txt Creates the lolor extension within a PostgreSQL database and sets a required node identifier. Optionally, it updates the search_path to prioritize lolor schema objects. ```sql -- Connect to your database and create the extension CREATE EXTENSION lolor; -- Set the required node parameter (1 to 2^28) SET lolor.node = 1; -- Optionally update search_path to use lolor schema SET search_path = lolor, "$user", public, pg_catalog; ``` -------------------------------- ### Maven Unit Test Execution for pgEdge lolor Source: https://github.com/pgedge/lolor/blob/main/tests/junit/multinode/README.md Commands to run the JUnit test suite for the pgEdge lolor extension using Maven. This includes running all tests, specific test classes, or individual test methods. ```bash $ cd junit-tests $ mvn test $ mvn -Dtest=TestLOMethods test $ mvn -Dtest=TestLOMethods#t1 test ``` -------------------------------- ### lo_import - Import file as Large Object Source: https://context7.com/pgedge/lolor/llms.txt Imports an operating system file into the database as a Large Object. Returns the OID of the newly created object. ```APIDOC ## lo_import - Import file as Large Object Imports an operating system file into the database as a Large Object. Returns the OID of the newly created object. ### Method `SELECT` ### Endpoint `lo_import(filepath)` ### Parameters #### Query Parameters - **filepath** (text) - Required - The absolute path to the file on the operating system to import. ### Response #### Success Response (200) - **lo_import** (oid) - The OID of the newly created large object. ### Response Example ```json { "lo_import": 1100449 } ``` ### Example Usage ```sql -- Import a file from the filesystem SELECT lo_import('/etc/os-release'); ``` ### Viewing Imported Data Example ```sql -- View the imported data SELECT loid, pageno, encode(data, 'escape') AS content FROM lolor.pg_largeobject WHERE loid = 1100449; ``` ``` -------------------------------- ### Configure lolor tables for replication (pgEdge spock) Source: https://context7.com/pgedge/lolor/llms.txt Sets up lolor tables for replication within a pgEdge cluster using `spock`. This involves adding `lolor.pg_largeobject` and `lolor.pg_largeobject_metadata` to a spock replication set on each node. ```bash # Add lolor tables to replication set on each node ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject' lolor_db ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject_metadata' lolor_db ``` ```sql -- Verify replication tables are configured SELECT * FROM spock.replication_set_table WHERE set_name = 'spock_replication_set' AND relname LIKE 'pg_largeobject%'; ``` -------------------------------- ### Create Large Object from bytea (lo_from_bytea) Source: https://context7.com/pgedge/lolor/llms.txt Creates a Large Object directly from bytea data in a single operation. This is a convenient alternative to using `lo_create`, `lo_open`, and `lowrite` sequentially. It can create an LO with a specified OID or allow the system to generate one. ```sql -- Create a large object with data in one call SELECT lo_from_bytea(0, 'Example large object stored in lolor'); -- Returns the OID of the created object -- With specific OID SELECT lo_from_bytea(300000, 'Data with specific OID'); -- Returns: 300000 (or new OID if 300000 was taken) ``` -------------------------------- ### Create Empty Large Object with Auto-Generated OID using lo_creat Source: https://context7.com/pgedge/lolor/llms.txt Creates a new, empty Large Object in PostgreSQL using the lolor extension. The `lo_creat(-1)` function automatically assigns a unique OID based on the configured `lolor.node` value, suitable for replication environments. It also shows how to verify the creation in the `lolor.pg_largeobject_metadata` table. ```sql -- Create a large object with no data and return the OID SELECT lo_creat(-1); -- Returns: -- lo_creat -- ---------- -- 1100433 -- Verify the object was created in lolor schema SELECT * FROM lolor.pg_largeobject_metadata WHERE oid = 1100433; -- Returns: -- oid | lomowner | lomacl -- ---------+----------+-------- -- 1100433 | 10 | ``` -------------------------------- ### Retrieve Large Object data (lo_get, lo_get_fragment) Source: https://context7.com/pgedge/lolor/llms.txt Retrieves all or part of a Large Object as bytea without needing to open a file descriptor. `lo_get` can fetch the entire object or a specific fragment defined by an offset and length. ```sql -- Get entire large object SELECT lo_get(1100500); -- Returns: \x536f6d652064617461 -- Get fragment: offset 5, length 10 SELECT lo_get(1100500, 5, 10); -- Returns: portion of data starting at byte 5 ``` -------------------------------- ### Query Large Object Metadata with lolor Source: https://github.com/pgedge/lolor/blob/main/docs/using_lolor.md Shows how to query the `pg_largeobject_metadata` table to retrieve information about large objects, such as owner and access control lists, using their oid. ```sql SELECT * FROM lolor.pg_largeobject_metadata where oid = 1100433; -- Retrieves metadata for a large object with oid 1100433. ``` ```sql SELECT * FROM lolor.pg_largeobject_metadata where oid = 200001; -- Retrieves metadata for a large object with oid 200001. ``` -------------------------------- ### Configure lolor Node Parameter Source: https://github.com/pgedge/lolor/blob/main/README.md Setting the 'lolor.node' configuration parameter is mandatory before using the lolor extension. This parameter, ranging from 1 to 2^28, assists in generating new large object OIDs. ```sql lolor.node = 1 ``` -------------------------------- ### lo_creat - Create empty Large Object with auto-generated OID Source: https://context7.com/pgedge/lolor/llms.txt Creates a new empty Large Object and returns a system-generated OID. The `-1` parameter indicates that the system should assign an OID automatically based on the configured `lolor.node` value. ```APIDOC ## lo_creat - Create empty Large Object with auto-generated OID Creates a new empty Large Object and returns a system-generated OID. The `-1` parameter indicates that the system should assign an OID automatically based on the configured `lolor.node` value. ### Method `SELECT` ### Endpoint `lo_creat(-1)` ### Parameters #### Query Parameters - **-1** (integer) - Required - Indicates system assignment of OID. ### Response #### Success Response (200) - **lo_creat** (oid) - The system-generated OID for the new large object. ### Response Example ```json { "lo_creat": 1100433 } ``` ### Example Usage ```sql -- Create a large object with no data and return the OID SELECT lo_creat(-1); ``` ### Verification Example ```sql -- Verify the object was created in lolor schema SELECT * FROM lolor.pg_largeobject_metadata WHERE oid = 1100433; ``` ``` -------------------------------- ### Enable lolor Extension using psql after Upgrade Source: https://github.com/pgedge/lolor/blob/main/docs/pg_upgrade_with_lolor.md This snippet demonstrates how to re-enable the 'lolor' PostgreSQL extension using `psql` after a successful `pg_upgrade`. This step should be performed after the database upgrade is complete and you have connected to the new database cluster. ```sql db1_18=# SELECT lolor.enable(); ``` -------------------------------- ### Read Large Object in Go with pgx Source: https://context7.com/pgedge/lolor/llms.txt Reads a PostgreSQL Large Object by its OID using the pgx Go library. It begins a transaction, opens the Large Object in read mode, reads the specified number of bytes into a byte slice, and commits the transaction. Returns the data as a string or an error. Requires a pgx connection. ```go package main import ( "context" "fmt" "github.com/jackc/pgx/v5" ) func readLargeObject(conn *pgx.Conn, oid uint32, size int) (string, error) { ctx := context.Background() tx, err := conn.Begin(ctx) if err != nil { return "", err } lo := tx.LargeObjects() obj, err := lo.Open(ctx, oid, pgx.LargeObjectModeRead) if err != nil { tx.Rollback(ctx) return "", err } data := make([]byte, size) _, err = obj.Read(data) if err != nil { tx.Rollback(ctx) return "", err } obj.Close() tx.Commit(ctx) return string(data), nil } ``` -------------------------------- ### Add lolor Tables to Replication Set Source: https://github.com/pgedge/lolor/blob/main/README.md Commands to add the 'lolor.pg_largeobject' and 'lolor.pg_largeobject_metadata' tables to a replication set using the 'pg_edge' tool. This is necessary for replicating large objects when using pg_edge replication. ```bash ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject' lolor_db ./pgedge spock repset-add-table spock_replication_set 'lolor.pg_largeobject_metadata' lolor_db ``` -------------------------------- ### lo_export - Export Large Object to file Source: https://context7.com/pgedge/lolor/llms.txt Exports a Large Object from the database to a file on the filesystem. ```APIDOC ## lo_export - Export Large Object to file Exports a Large Object from the database to a file on the filesystem. ### Method `SELECT` ### Endpoint `lo_export(oid, filepath)` ### Parameters #### Query Parameters - **oid** (oid) - Required - The OID of the large object to export. - **filepath** (text) - Required - The path on the filesystem where the large object will be exported. ### Response #### Success Response (200) - **lo_export** (integer) - Returns 1 on success. ### Example Usage ```sql -- First, create and populate a large object (assuming OID 1100450 is used) SELECT lo_from_bytea(0, 'This is the content to export'); -- Export the large object to a file SELECT lo_export(1100450, '/tmp/exported_data.txt'); ``` ``` -------------------------------- ### Configure Postgres Search Path for lolor Source: https://github.com/pgedge/lolor/blob/main/README.md Adjusting the 'search_path' in PostgreSQL to prioritize tables from the 'lolor' schema. This ensures that large object related tables managed by lolor are accessed correctly. ```sql set search_path=lolor,"$user",public,pg_catalog ``` -------------------------------- ### lo_create - Create empty Large Object with specified OID Source: https://context7.com/pgedge/lolor/llms.txt Creates a new empty Large Object with a specific OID. If the requested OID is already in use, the system will assign a new unique OID. ```APIDOC ## lo_create - Create empty Large Object with specified OID Creates a new empty Large Object with a specific OID. If the requested OID is already in use, the system will assign a new unique OID. ### Method `SELECT` ### Endpoint `lo_create(oid)` ### Parameters #### Query Parameters - **oid** (oid) - Required - The desired OID for the large object. ### Response #### Success Response (200) - **lo_create** (oid) - The OID of the created large object (either the specified OID or a newly assigned one if the specified OID was in use). ### Response Example ```json { "lo_create": 200000 } ``` ### Example Usage ```sql -- Create an empty large object with a specific OID SELECT lo_create(200000); ``` ### Verification Example ```sql -- Verify the object metadata SELECT * FROM lolor.pg_largeobject_metadata WHERE oid = 200000; ``` ``` -------------------------------- ### Store Large Object in Node.js with pg-large-object Source: https://context7.com/pgedge/lolor/llms.txt Stores binary data as a PostgreSQL Large Object using the pg-large-object library. It initializes the 'lolor' extension, creates a new Large Object within a transaction, writes the data, and commits. Returns the OID of the stored object. Requires a PostgreSQL connection pool and the 'pg-large-object' package. ```javascript const pg = require('pg'); const { LargeObjectManager, LargeObject } = require('pg-large-object'); const pool = new pg.Pool({ host: 'localhost', port: 5432, database: 'mydb', user: 'postgres', password: 'secret' }); async function storeLargeObject(data) { const client = await pool.connect(); // Initialize lolor await client.query('CREATE EXTENSION IF NOT EXISTS lolor'); await client.query('SET search_path TO lolor,"$user",public,pg_catalog'); const man = new LargeObjectManager({ pg: client }); // Create and write within transaction await client.query('BEGIN'); const oid = await man.createAsync(); await client.query('COMMIT'); await client.query('BEGIN'); const obj = await man.openAsync(oid, LargeObjectManager.WRITE); obj.write(Buffer.from(data)); await client.query('COMMIT'); await client.release(true); return oid; } ``` -------------------------------- ### lo_get / lo_get_fragment - Retrieve Large Object data Source: https://context7.com/pgedge/lolor/llms.txt Retrieves all or part of a Large Object as bytea without opening a descriptor. ```APIDOC ## lo_get / lo_get_fragment - Retrieve Large Object data ### Description Retrieves all or part of a Large Object as bytea without opening a descriptor. ### Method SQL ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql -- Get entire large object SELECT lo_get(1100500); -- Returns: \x536f6d652064617461 -- Get fragment: offset 5, length 10 SELECT lo_get(1100500, 5, 10); -- Returns: portion of data starting at byte 5 ``` ### Response #### Success Response (SQL Result) - **Return Value** (bytea) - The content of the large object or a fragment of it. #### Response Example `\x536f6d652064617461` `\x61746120737461` ``` -------------------------------- ### Toggle lolor mode (lolor.enable, lolor.disable) Source: https://context7.com/pgedge/lolor/llms.txt Controls whether the lolor extension or native PostgreSQL Large Object storage is utilized. `lolor.disable()` switches to native storage, and `lolor.enable()` switches back to lolor storage. This is crucial for operations like `pg_upgrade`. ```sql -- Disable lolor (use native LO storage) SELECT lolor.disable(); -- Objects created now go to native pg_largeobject SELECT lo_from_bytea(2, 'Stored in native LO storage'); -- Re-enable lolor SELECT lolor.enable(); -- Objects now go to lolor.pg_largeobject SELECT lo_from_bytea(3, 'Stored in lolor LO storage'); ``` -------------------------------- ### Lolor Large Object Management API Source: https://github.com/pgedge/lolor/blob/main/docs/using_lolor.md This section covers the core functionalities of the lolor extension for creating, importing, querying, and unlinking large objects. ```APIDOC ## Create Large Object ### Description Creates a large object with a specified OID (Object Identifier) or a system-generated OID if -1 is provided. Returns the OID of the created large object. ### Method SQL Function Call ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### SQL Function `lo_creat(oid)` or `lo_create(oid)` ### Parameters - **oid** (integer) - The desired Object Identifier for the large object. Use -1 to let the system generate an OID. ### Request Example ```sql -- Create a large object with no data and return the oid: lolor_db=# SELECT lo_creat (-1); lo_creat ---------- 1100433 (1 row) -- Creating an empty large object with oid 200000: lolor_db=# SELECT lo_create (200000); lo_create ----------- 200000 (1 row) ``` ### Response #### Success Response (200) - **lo_creat / lo_create** (integer) - The OID of the created large object. #### Response Example ```json { "oid": 1100433 } ``` ## Query Large Object Metadata ### Description Retrieves metadata for a large object, including its owner and access control list, based on its OID. ### Method SQL Query ### Endpoint N/A (SQL Query) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### SQL Query `SELECT * FROM lolor.pg_largeobject_metadata WHERE oid = [oid];` ### Parameters - **oid** (integer) - The Object Identifier of the large object to query. ### Request Example ```sql -- Querying the lolor schema for related stats: lolor_db=# SELECT * FROM lolor.pg_largeobject_metadata where oid = 1100433; oid | lomowner | lomacl ---------+----------+-------- 1100433 | 10 | (1 row) ``` ### Response #### Success Response (200) - **oid** (integer) - The Object Identifier of the large object. - **lomowner** (integer) - The user ID of the owner of the large object. - **lomacl** (aclitem[]) - The access control list for the large object. #### Response Example ```json { "oid": 1100433, "lomowner": 10, "lomacl": null } ``` ## Import Large Object ### Description Imports the content of an operating system file as a large object in PostgreSQL. Returns the OID of the newly created large object. ### Method SQL Function Call ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### SQL Function `lo_import(filepath)` ### Parameters - **filepath** (text) - The absolute path to the operating system file to import. ### Request Example ```sql -- Import an operating system file as a large object: lolor_db=# SELECT lo_import ('/etc/os-release'); lo_import ----------- 1100449 (1 row) ``` ### Response #### Success Response (200) - **lo_import** (integer) - The OID of the imported large object. #### Response Example ```json { "oid": 1100449 } ``` ## Get Large Object Data ### Description Retrieves the data content of a large object, page by page, based on its LOBject ID (loid). ### Method SQL Query ### Endpoint N/A (SQL Query) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### SQL Query `SELECT * FROM lolor.pg_largeobject WHERE loid = [loid];` ### Parameters - **loid** (integer) - The LOBject ID of the large object to retrieve data from. ### Request Example ```sql -- Return information about the large object: lolor_db=# SELECT * FROM lolor.pg_largeobject where loid = 1100449; loid | pageno | data 1100449 | 0 | \x5052455454595f4e414d453d2244656269616e20474e552f4c696e75782031322028626f6f6b776f726d29220a4e414d453d2244656269616e20474e552f4c696e7578220a56455253494f4e5f49443d223132220a56455253494f4e3d2231322028626f6f6b776f726d29220a56455253494f4e5f434f44454e414d453d626f6f6b776f726d0a49443d64656269616e0a484f4d455f55524c3d 2268747470733a2f2f7777772e64656269616e2e6f72672f220a535550504f52545f55524c3d2268747470733a2f2f7777772e64656269616e2e6f72672f737570706f7274220a4255475f5245504f52545f 55524c3d2268747470733a2f2f627567732e64656269616e2e6f72672f220a (1 row) ``` ### Response #### Success Response (200) - **loid** (integer) - The LOBject ID of the large object. - **pageno** (integer) - The page number of the data chunk. - **data** (bytea) - The binary data content of the large object page. #### Response Example ```json { "loid": 1100449, "pageno": 0, "data": "\\x5052455454595f4e414d453d2244656269616e20474e552f4c696e75782031322028626f6f6b776f726d29220a4e414d453d2244656269616e20474e552f4c696e7578220a56455253494f4e5f49443d223132220a56455253494f4e3d2231322028626f6f6b776f726d29220a56455253494f4e5f434f44454e414d453d626f6f6b776f726d0a49443d64656269616e0a484f4d455f55524c3d2268747470733a2f2f7777772e64656269616e2e6f72672f220a535550504f52545f55524c3d2268747470733a2f2f7777772e64656269616e2e6f72672f737570706f7274220a4255475f5245504f52545f55524c3d2268747470733a2f2f627567732e64656269616e2e6f72672f220a" } ``` ## Unlink Large Object ### Description Removes a large object from the database by its OID. Returns 1 if successful, 0 if the OID does not exist. ### Method SQL Function Call ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### SQL Function `lo_unlink(oid)` ### Parameters - **oid** (integer) - The Object Identifier of the large object to unlink. ### Request Example ```sql -- Unlink a large object: lolor_db=# SELECT lo_unlink (1100449); lo_unlink ----------- 1 (1 row) ``` ### Response #### Success Response (200) - **lo_unlink** (integer) - 1 if the large object was successfully unlinked, 0 otherwise. #### Response Example ```json { "result": 1 } ``` ``` -------------------------------- ### lolor.enable / lolor.disable - Toggle lolor mode Source: https://context7.com/pgedge/lolor/llms.txt Controls whether lolor or native PostgreSQL Large Object storage is used. Required for pg_upgrade operations. ```APIDOC ## lolor.enable / lolor.disable - Toggle lolor mode ### Description Controls whether lolor or native PostgreSQL Large Object storage is used. Required for pg_upgrade operations. ### Method SQL ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql -- Disable lolor (use native LO storage) SELECT lolor.disable(); -- Objects created now go to native pg_largeobject SELECT lo_from_bytea(2, 'Stored in native LO storage'); -- Re-enable lolor SELECT lolor.enable(); -- Objects now go to lolor.pg_largeobject SELECT lo_from_bytea(3, 'Stored in lolor LO storage'); ``` ### Response #### Success Response (SQL Result) - **Return Value** (void) - These functions do not return a value. #### Response Example (No output) ``` -------------------------------- ### lo_lseek / lo_lseek64 - Seek within Large Object Source: https://context7.com/pgedge/lolor/llms.txt Repositions the read/write cursor within an open Large Object. Supports 32-bit and 64-bit offsets. ```APIDOC ## lo_lseek / lo_lseek64 - Seek within Large Object ### Description Repositions the read/write cursor within an open Large Object. Supports 32-bit and 64-bit offsets. ### Method SQL (within a transaction) ### Endpoint N/A (SQL Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```sql BEGIN; -- Open existing large object for read/write SELECT lo_open(1100500, x'60000'::int) AS fd; -- Seek to position 15 from start (whence=0) SELECT lo_lseek(0, 15, 0); -- Returns: 15 -- For large files, use 64-bit version SELECT lo_lseek64(0, 1000000000, 0); -- Returns: 1000000000 SELECT lo_close(0); COMMIT; ``` ### Response #### Success Response (SQL Result) - **Return Value** (integer) - The new position of the cursor within the large object. #### Response Example `15` `1000000000` ```