LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects
https://linuxforhealth.github.io/FHIR
Apache License 2.0
330 stars 157 forks source link

Change PostgreSQL TOAST storage type from EXTENDED to EXTERNAL for payload data column #2831

Open punktilious opened 3 years ago

punktilious commented 3 years ago

Describe the bug The PostgreSQL TOAST algorithm attempts to compress data before offloading to the TOAST table. In our case, the payload data is already compressed, so it is more efficient if we change the storage type from EXTENDED to EXTERNAL.

Environment 4.10.0

To Reproduce

  1. Run the schema creation tool to build a schema in PostgreSQL
  2. Inspect the definition of fhirdata.patient_resources
  3. Observe that the Storage definition for the data column is EXTENDED:
fhirdb=# \d+ fhirdata.patient_resources
                                             Table "fhirdata.patient_resources"
       Column        |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description 
---------------------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 resource_id         | bigint                      |           | not null |         | plain    |              | 
 logical_resource_id | bigint                      |           | not null |         | plain    |              | 
 version_id          | integer                     |           | not null |         | plain    |              | 
 last_updated        | timestamp without time zone |           | not null |         | plain    |              | 
 is_deleted          | character(1)                |           | not null |         | extended |              | 
 data                | bytea                       |           |          |         | extended |              | 
Indexes:
    "patient_resources_pk" PRIMARY KEY, btree (resource_id)
    "patient_resources_prf_in1" UNIQUE, btree (resource_id)
    "idx_patient_resources_lupd" btree (last_updated)
    "idx_patient_resourceslogical_resource_id" btree (logical_resource_id)
Access method: heap

Expected behavior Storage type for the data column should be EXTERNAL.

Additional context

ALTER TABLE xx_RESOURCES ALTER COLUMN data SET storage EXTERNAL;
lmsurpre commented 3 years ago

Postgresql will "do the right thing" for existing rows and just update the new/updated rows going forward. No migration...let it happen naturally.