# replacement_sort_tuples

> replacement_sort_tuples — Sets the maximum number of tuples to be sorted using replacement selection. Observed in PG9.6–10; its last measured boot default is 150000 in PG10, with user context. It was removed in PG11.
---

> [!NOTE]
> **Fact — official short description:** “Sets the maximum number of tuples to be sorted using replacement selection.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `integer` | Upstream pg_settings type |
| Context | `user` | Settable by an ordinary user |
| Unit | — | Raw unit |
| Range | `0` – `2147483647` | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Resource Usage / Memory | Upstream classification |
| Latest boot value | `150000` | 150000 |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG9.6 |
| Present in | PG9.6–10 |
| Removed in | PG11 |
| Introduction commit | [`0711803775a3`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=0711803775a37e0bf39d7efdd1e34d9d7e640ea1) — Use quicksort, not replacement selection, for external sorting. |
| Commit date | 2016-04-08 |
| Discussion | — |

## Default history {#default-history}

| Versions | Raw `boot_val` | Unit | Human value |
| --- | --- | --- | --- |
| PG9.6–10 | `150000` | — | 150000 |
{.full-width caption="Measured PG9.0–19 Beta 3 boot defaults"}

## How it works {#mechanism}

In PG10, replacement_sort_tuples selected when an in-memory sort used replacement selection to produce a long initial run for external merge sorting. It was removed in PG11 with the old replacement-selection path.

The value counted tuples, not bytes, so its memory implications depended on row width and work_mem. It was an algorithm threshold rather than a general sort-memory ceiling.

Modern PostgreSQL does not recognize the parameter. Migration should delete it and tune current sort behavior through work_mem, plan shape, and measured temporary-file use instead. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value.

## Tuning advice {#tuning-advice}

> [!TIP]
> **Advice.** These are workload-specific starting points and must be validated with measurements.

| Workload | Guidance |
| --- | --- |
| OLTP | Do not tune replacement_sort_tuples on current PostgreSQL: remove it from upgrade targets and use the current replacement behavior described above. Retain it only when reproducing the historical version. |
| OLAP | Do not carry replacement_sort_tuples into a modern analytical cluster. Benchmark the supported current mechanisms instead of trying to emulate a removed implementation detail. |
| Small nodes | Delete replacement_sort_tuples during version migration; an unknown-parameter startup failure is more likely than a benefit. Historical test instances should keep the old upstream default. |
{.full-width}

## Pigsty {#pigsty}

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG10; this does not assert current Pigsty support for that historical or beta release.

| Template | Effective value | Versus upstream boot | Source expression |
| --- | --- | --- | --- |
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG9.6–10 unmodified; OLAP: PG9.6–10 unmodified; CRIT: PG9.6–10 unmodified; TINY: PG9.6–10 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-pitfalls}

- Changing replacement_sort_tuples without applying its documented unit and configuration context.
- Optimizing an isolated benchmark while ignoring concurrent aggregate resource use.
- Assuming a configured value guarantees operating-system or storage behavior.
- Failing to retest startup, failover, and workload latency after the change.

## Related parameters {#related-parameters}

[`work_mem`](/parameters/work-mem/) · [`temp_file_limit`](/parameters/temp-file-limit/) · [`enable_sort`](/parameters/enable-sort/) · [`trace_sort`](/parameters/trace-sort/) · [`log_temp_files`](/parameters/log-temp-files/)

## References {#references}

- [PostgreSQL 10 — replacement_sort_tuples](https://www.postgresql.org/docs/10/runtime-config-resource.html#GUC-REPLACEMENT-SORT-TUPLES)
- [Machine-readable GUC export](/data/guc.jsonl)
