Chapter 34. Multi-Segment Insertion
Table of Contents
Warning
Multi-segment insertion is currently experimental and is not recommended for using in production. For information about its limitations, refer to Section 34.1.
Postgres Pro allows you to bulk insert data into the same table in multiple threads simultaneously, bypassing the Postgres Pro buffer manager. This feature is designed for the following scenarios:
data migration from a consistent database
restoring data from pg_dump
loading data from a consistent backup
Using multi-segment insertion requires no special preparation or custom parameters when connecting a new client. Any client backend process can start inserting data in multi-segment mode.
Before writing data to a table, specify the name of the table in the multi_segment_relname parameter. You can set this parameter multiple times in a session so that a single client backend can perform multi-segment insertion into several tables, switching between its dedicated table segments.
Tip
Multi-segment insertion performs better if wal_compression is enabled due to full page image (FPI) compression.
To avoid lock conflicts, each backend creates a dedicated table segment for inserting data. The backends that are not performing multi-segment insertion cannot access this segment and the corresponding table, even for reading. The backends that are currently using the multi-segment mechanism can read data from the dedicated table segments that do not belong to them, but they can write data only to their own segments. When a segment is full, the backend immediately creates another segment and continues writing data to the new segment.
Before performing the first INSERT, a backend acquires a session-level exclusive lock on the table specified in the multi_segment_relname parameter. This lock blocks access to the table for all processes, including autovacuum, except the backends that perform multi-segment insertion to this table. No operations other than multi-segment insertion are available.
Important
The table is unlocked when all backends that performed multi-segment insertion to this table disconnect from the database.
Data pages that have been inserted via the multi-segment mechanism act like regular Postgres Pro data pages: they are synced to disk during the COMMIT or CHECKPOINT operations for a higher level of safety.
Important
Use the multi-segment mechanism only for INSERT operations. Using it with UPDATE and DELETE operations might lead to unexpected behavior.