HorizonDB - Resource Usage / Memory

This article lists parameters shared by PostgreSQL 17 and PostgreSQL 18 (Preview). Version-specific entries follow where their attributes or availability differ.

Template value is the configuration template's value, not a verification of your compute pool's effective value. A hyphen (-) means the template doesn't declare the attribute. It doesn't mean that a parameter is writable or dynamic.

For your compute pool's configured and effective values, see List and filter parameters.

Shared parameters

autovacuum_work_mem

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum memory each autovacuum worker process can use.
Data type integer
Template value -1
Unit kB
Allowed values -1-2097151
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

commit_timestamp_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the commit timestamp cache. Specify 0 to set this value as a fraction of shared_buffers.
Data type integer
Template value 0
Unit 8kB
Allowed values 0-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

hash_mem_multiplier

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Multiple of work_mem to use for hash tables.
Data type numeric
Template value 2
Allowed values 1-1000
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

huge_pages

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Use of huge pages on Linux or Windows.
Data type enumeration
Template value try
Allowed values on,off,try
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

Additional notes for PostgreSQL 17:

Description

Huge pages are a feature that allows for memory to be managed in larger blocks. You can typically manage blocks of up to 2 MB, as opposed to the standard 4-KB pages.

Using huge pages can offer performance advantages that effectively offload the CPU:

  • They reduce the overhead associated with memory management tasks like fewer translation lookaside buffer (TLB) misses.
  • They shorten the time needed for memory management.

Specifically, in PostgreSQL, you can use huge pages only for the shared memory area. A significant part of the shared memory area is allocated for shared buffers.

Another advantage is that huge pages prevent the swapping of the shared memory area out to disk, which further stabilizes performance.

Recommendations

  • For servers that have significant memory resources, avoid disabling huge pages. Disabling huge pages could compromise performance.
  • If you start with a smaller server that doesn't support huge pages but you anticipate scaling up to a server that does, keep the huge_pages setting at TRY for seamless transition and optimal performance.

Azure-specific notes

The parameter table lists the configuration template value and allowed values. For your compute pool's configured and effective values, see List and filter parameters.

logical_decoding_work_mem

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum memory for logical decoding. Each internal reorder buffer can use this much memory before it spills to disk.
Data type integer
Template value 65536
Unit kB
Allowed values 64-2147483647
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

maintenance_work_mem

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum memory for maintenance operations. These operations include VACUUM and CREATE INDEX.
Data type integer
Template value 131072
Unit kB
Allowed values 1024-2097151
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

Additional notes for PostgreSQL 17:

Description

maintenance_work_mem is a configuration parameter in PostgreSQL. It governs the amount of memory allocated for maintenance operations, such as VACUUM, CREATE INDEX, and ALTER TABLE. Unlike work_mem, which affects memory allocation for query operations, maintenance_work_mem is reserved for tasks that maintain and optimize the database structure.

Note

Setting maintenance_work_mem to overly aggressive values could periodically cause out of memory error in the system. It's extremely important to understand the amount of memory available on the server, and the number of concurrent operations that could allocate memory for the tasks described earlier, before making changes to this parameter.

Key points

  • Vacuum memory cap: If you want to speed up the cleanup of dead tuples by increasing maintenance_work_mem, be aware that VACUUM has a built-in limitation for collecting dead tuple identifiers. It can use only up to 1 GB of memory for this process.
  • Separation of memory for autovacuum: You can use the autovacuum_work_mem setting to control the memory that autovacuum operations use independently. This setting acts as a subset of maintenance_work_mem. You can decide how much memory autovacuum uses without affecting the memory allocation for other maintenance tasks and data definition operations.

Azure-specific notes

The parameter table lists the configuration template value and allowed values. For your compute pool's configured and effective values, see List and filter parameters.

max_prepared_transactions

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum number of simultaneously prepared transactions.
Data type integer
Template value 0
Allowed values 0-262143
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

multixact_member_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the MultiXact member cache.
Data type integer
Template value 32
Unit 8kB
Allowed values 16-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

multixact_offset_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the MultiXact offset cache.
Data type integer
Template value 16
Unit 8kB
Allowed values 16-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

notify_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the LISTEN/NOTIFY message cache.
Data type integer
Template value 16
Unit 8kB
Allowed values 16-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

serializable_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the serializable transaction cache.
Data type integer
Template value 32
Unit 8kB
Allowed values 16-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

shared_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the number of shared memory buffers used by the server.
Data type integer
Template value 1024
Unit 8kB
Allowed values 16-1073741823
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

Additional notes for PostgreSQL 17:

Description

The shared_buffers configuration parameter determines the amount of system memory allocated to the PostgreSQL database for buffering data. It serves as a centralized memory pool that's accessible to all database processes.

When data is needed, the database process first checks the shared buffer. If the required data is present, it's quickly retrieved and bypasses a more time-consuming disk read. Shared buffers serve as an intermediary between the database processes and the disk, and effectively reduces the number of required I/O operations.

Azure-specific notes

The parameter table lists the configuration template value and allowed values. For your compute pool's configured and effective values, see List and filter parameters.

subtransaction_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the subtransaction cache. Specify 0 to set this value as a fraction of shared_buffers.
Data type integer
Template value 0
Unit 8kB
Allowed values 0-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

temp_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum number of temporary buffers each session can use.
Data type integer
Template value 1024
Unit 8kB
Allowed values 100-1073741823
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

transaction_buffers

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the size of the dedicated buffer pool used for the transaction status cache. Specify 0 to set this value as a fraction of shared_buffers.
Data type integer
Template value 0
Unit 8kB
Allowed values 0-131072
Read-only -
Parameter type static
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

vacuum_buffer_usage_limit

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the buffer pool size for VACUUM, ANALYZE, and autovacuum.
Data type integer
Template value 2048
Unit kB
Allowed values 0-16777216
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

work_mem

Attribute Value
Category Resource Usage / Memory
PostgreSQL versions 17, 18 (Preview)
Description Sets the maximum memory for query workspaces. Each internal sort operation and hash table can use this memory amount before switching to temporary disk files.
Data type integer
Template value 4096
Unit kB
Allowed values 4096-2097151
Read-only -
Parameter type -
Documentation PostgreSQL 17, PostgreSQL 18 (Preview)

Additional notes for PostgreSQL 17:

Description

The work_mem parameter in PostgreSQL controls the amount of memory allocated for certain internal operations within each database session's private memory area. Examples of these operations are sorting and hashing.

Unlike shared buffers, which are in the shared memory area, work_mem is allocated in a per-session or per-query private memory space. By setting an adequate work_mem size, you can significantly improve the efficiency of these operations and reduce the need to write temporary data to disk.

Key points

  • Private connection memory: work_mem is part of the private memory that each database session uses. This memory is distinct from the shared memory area that shared_buffers uses.
  • Query-specific usage: Not all sessions or queries use work_mem. Simple queries like SELECT 1 are unlikely to require work_mem. However, complex queries that involve operations like sorting or hashing can consume one or multiple chunks of work_mem.
  • Parallel operations: For queries that span multiple parallel back ends, each back end could potentially use one or multiple chunks of work_mem.

Monitor and adjusting work_mem

It's essential to continuously monitor your system's performance and adjust work_mem as necessary, primarily if query execution times related to sorting or hashing operations are slow. Here are ways to monitor performance by using tools available in the Azure portal:

Granular adjustment

While you're managing the work_mem parameter, it's often more efficient to adopt a granular adjustment approach rather than setting a global value. This approach ensures that you allocate memory judiciously based on the specific needs of processes and users. It also minimizes the risk of encountering out-of-memory issues. Here's how you can go about it:

  • User level: If a specific user is primarily involved in aggregation or reporting tasks, which are memory intensive, consider customizing the work_mem value for that user. Use the ALTER ROLE command to enhance the performance of the user's operations.

  • Function/procedure level: If specific functions or procedures are generating substantial temporary files, increasing the work_mem value at the specific function or procedure level can be beneficial. Use the ALTER FUNCTION or ALTER PROCEDURE command to specifically allocate more memory to these operations.

  • Database level: Alter work_mem at the database level if only specific databases are generating high numbers of temporary files.

  • Global level: If an analysis of your system reveals that most queries are generating small temporary files, while only a few are creating large ones, it might be prudent to globally increase the work_mem value. This action facilitates most queries to process in memory, so you can avoid disk-based operations and improve efficiency. However, always be cautious and monitor the memory utilization on your server to ensure that it can handle the increased work_mem value.

Determine the minimum work_mem value for sorting operations

To find the minimum work_mem value for a specific query, especially one that generates temporary disk files during the sorting process, start by considering the temporary file size generated during the query execution. For instance, if a query is generating a 20-MB temporary file:

  1. Connect to your database by using psql or your preferred PostgreSQL client.
  2. Set an initial work_mem value slightly higher than 20 MB to account for additional headers when processing in memory. Use a command such as: SET work_mem TO '25MB'.
  3. Run EXPLAIN ANALYZE on the problematic query in the same session.
  4. Review the output for "Sort Method: quicksort Memory: xkB". If it indicates "external merge Disk: xkB", raise the work_mem value incrementally and retest until "quicksort Memory" appears. The appearance of "quicksort Memory" signals that the query is now operating in memory.
  5. After you determine the value through this method, you can apply it either globally or on more granular levels (as described earlier) to suit your operational needs.