Skip to content

Truncate causes performance issues with locksΒ #258

@EricSoroos

Description

@EricSoroos

Describe the bug

# truncate table to use copy freeze option and further increase

Here, you note that truncate increases the speed that copy runs at. We're finding that with larger CSVs, the combination of truncate + a long running operation causes lock issues.

Truncate acquires an AccessExclusive lock, which essentially blocks all other queries, including select. This includes the select count(_id) from tbl that datastore's resource_fields runs .

This has the effect of blocking datastore_info or any datastore_search queries until the copy command terminates, which can be well over the time that the load balancer is willing to wait. Since we're (datastore) not takaing explicit nowait AccessShare locks prior to running queries, we just wait and wait and wait until the copy completes.

The PG documentation that you link to goes on to say:

However, this consideration only applies when wal_level is minimal as all commands must write WAL otherwise.

AFAIK, WAL Minimal isn't a common configuration for organizations interested in durable storage.

To Reproduce
Steps to reproduce the behavior:

  1. Upload a big CSV. OMM, 40Mb will cause a 100 sec copy command
  2. Run datastore_info, or possibly indexing, or other operations on that resource using datastore at that time.
  3. See select count(*) block till the copy is complete and committed.

This might be clearer if you upload enough to generate the view, then upload a new, huge CSV, and visit the view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions