apache / apache/cloudberry

Feature Request: Support `LOCK TABLE ... COORDINATOR ONLY` syntax

Open
#1,265 1 comment 0 reactions 0 assignees View on GitHub
cherry-pick
Dominant language
C
Stars
1.4k
Forks
247
Avg merge
4d 3h
Merged PRs (30d)
39

Description

## Issue Description

Cloudberry currently lacks support for the `LOCK TABLE ... IN ACCESS SHARE MODE COORDINATOR ONLY` syntax, a feature present in Greenplum Database 7 and later.

This option was introduced in GPDB 7 to provide a **performance boost** for utilities like `gpbackup` when locking a large number of tables. By acquiring locks only on the coordinator, it avoids the overhead of dispatching lock requests to all segment nodes. The original commit noted this was particularly useful for `ACCESS SHARE` locks, which are primarily used to prevent DDL changes (like `ALTER TABLE` or `DROP TABLE`) that are initiated through the coordinator anyway.

The absence of this feature in Cloudberry forces tools to use the standard `LOCK TABLE` command, which can lead to unnecessary network traffic and increased lock resource consumption in large-scale scenarios.

## Reproduction and Evidence

The following raw `psql` session logs demonstrate the syntax incompatibility on Cloudberry versus the expected behavior on Greenplum 7.

### Cloudberry (Actual Behavior)

The command fails with a syntax error.

```text
cbdb=# select version();
version
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 14.4 (Apache Cloudberry 2.1.0-devel+dev.2019.g1cc76495e18 build dev) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit compiled on Jul 18 2025 11:29:40
(1 row)

cbdb=# create table ao_test(a int, b int) with(appendonly=true);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Apache Cloudberry data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
cbdb=#
cbdb=# begin;
BEGIN
cbdb=*# lock table ao_test IN ACCESS SHARE MODE COORDINATOR ONLY;
ERROR: syntax error at or near "COORDINATOR"
LINE 1: lock table ao_test IN ACCESS SHARE MODE COORDINATOR ONLY;
^
cbdb=!# end;
ROLLBACK
```

### Greenplum 7 (Expected Behavior)

The command executes successfully.

```text
gpdb7=# select version();
version
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 12.12 (Greenplum Database 7.0.0-beta.0+482967c1b4 build dev) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit compiled on Nov 8 2024 23:43:47 Bhuvnesh C.
(1 row)

gpdb7=#
gpdb7=# create table ao_test(a int, b int) with(appendonly=true);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
CREATE TABLE
gpdb7=#
gpdb7=# begin;
BEGIN
gpdb7=# lock table ao_test IN ACCESS SHARE MODE COORDINATOR ONLY;
LOCK TABLE
gpdb7=#
gpdb7=# end;
COMMIT
```

## Impact

The lack of this feature creates a feature gap between Cloudberry and Greenplum 7+. While described as a "small performance boost" in the original implementation, for tools like `gpbackup` operating on databases with thousands of tables, this can translate to a noticeable difference in performance and resource usage.

Implementing this feature would bring Cloudberry into closer alignment with GPDB 7, allowing ecosystem tools to operate more efficiently and consistently across both platforms.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the LOCK TABLE syntax path for the COORDINATOR ONLY clause and how lock requests are dispatched between the coordinator and segment nodes. Reproduce the issue with the provided psql commands, then verify that ACCESS SHARE MODE COORDINATOR ONLY succeeds and avoids segment lock dispatch while standard LOCK TABLE behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, postgres
Domain
database, distributed-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.