Skip to content
Written with Claude
IMPORTANT

As you may notice, this page and pretty much the entire website were obviously created with the help of AI. I wonder how you could tell? Was it a big "Written With Claude" badge on every page? I moved it to the top now (with the help of AI of course) to make it even more obvious. There are a few blogposts that were written by me manually, the old-fashioned way, I hope there will be more in the future, and those have a similar "Human Written" badge. This project (not the website), on the other hand, is a very, very different story. It took me more than two years of painstaking and unpaid work in my own free time. A story that, hopefully, I will tell someday. But meanwhile, what would you like me to do? To create a complex documentation website with a bunch of highly technical articles with the help of AI and fake it, to give you an illusion that I also did that manually? Like the half of itnernet is doing at this point? How does that makes any sense? Is that even fair to you? Or maybe to create this website manually, the old-fashioned way, just for you? While working a paid job for a salary, most of you wouldn't even get up in the morning. Would you like me to sing you a song while we're at it? For your personal entertainment? Seriously, get a grip. Do you find this information less valuable because of the way this website was created? I give my best to fix it to keep the information as accurate as possible, and I think it is very accurate at this point. If you find some mistakes, inaccurancies or problems, there is a comment section at the bottom of every page, which I also made with the help of the AI. And I woould very much appreciate if you leave your feedback there. Look, I'm just a guy who likes SQL, that's all. If you don't approve of how this website was constructed and the use of AI tools, I suggest closing this page and never wever coming back. And good riddance. And I would ban your access if I could know how. Thank you for your attention to this matter.

Command Retry

Command retry strategies and options for handling transient database errors.

Overview

json
{
  "CommandRetryOptions": {
    "Enabled": true,
    "DefaultStrategy": "default",
    "Strategies": {
      "default": {
        "RetrySequenceSeconds": [0, 1, 2, 5, 10],
        "ErrorCodes": [
          "40001", "40P01",
          "08000", "08003", "08006", "08001", "08004", "08007", "08P01",
          "53000", "53100", "53200", "53300", "53400",
          "57P01", "57P02", "57P03", "58000", "58030",
          "55P03", "55006", "55000"
        ]
      }
    }
  }
}

Settings Reference

SettingTypeDefaultDescription
EnabledbooltrueEnable command retry functionality.
DefaultStrategystring"default"Name of the default retry strategy to use when no strategy is specified.
Strategiesobject(see below)Named retry strategies with their configurations.

Strategies can be assigned to endpoints using the retry_strategy annotation.

Strategy Settings

Each strategy has the following settings:

SettingTypeDefaultDescription
RetrySequenceSecondsarray[0, 1, 2, 5, 10]Retry delays in seconds. Array length determines maximum retries.
ErrorCodesarray(see below)PostgreSQL error codes that trigger retries.

Retry Sequence

The RetrySequenceSeconds array defines delay between retries:

json
{
  "RetrySequenceSeconds": [0, 1, 2, 5, 10]
}
  • First retry: immediate (0 seconds)
  • Second retry: after 1 second
  • Third retry: after 2 seconds
  • Fourth retry: after 5 seconds
  • Fifth retry: after 10 seconds

Accepts decimal values (e.g., 0.25 for 250ms, 0.5 for 500ms).

Default Error Codes

The default strategy retries on these PostgreSQL error codes:

Serialization Failures

CodeNameDescription
40001serialization_failureMust retry for correctness
40P01deadlock_detectedDeadlock resolved by aborting transaction

Connection Issues (Class 08)

CodeName
08000connection_exception
08003connection_does_not_exist
08006connection_failure
08001sqlclient_unable_to_establish_sqlconnection
08004sqlserver_rejected_establishment_of_sqlconnection
08007transaction_resolution_unknown
08P01protocol_violation

Resource Constraints (Class 53)

CodeName
53000insufficient_resources
53100disk_full
53200out_of_memory
53300too_many_connections
53400configuration_limit_exceeded

System Errors (Class 57/58)

CodeName
57P01admin_shutdown
57P02crash_shutdown
57P03cannot_connect_now
58000system_error
58030io_error

Lock Acquisition Issues (Class 55)

CodeName
55P03lock_not_available
55006object_in_use
55000object_not_in_prerequisite_state

See PostgreSQL Error Codes for the complete list.

Multiple Strategies

Define multiple strategies for different use cases:

json
{
  "CommandRetryOptions": {
    "Enabled": true,
    "DefaultStrategy": "default",
    "Strategies": {
      "default": {
        "RetrySequenceSeconds": [0, 1, 2, 5, 10],
        "ErrorCodes": ["40001", "40P01", "08000", "08003", "08006"]
      },
      "aggressive": {
        "RetrySequenceSeconds": [0, 0.5, 1, 2, 5, 10, 30],
        "ErrorCodes": ["40001", "40P01", "08000", "08003", "08006", "53300", "57P03"]
      },
      "minimal": {
        "RetrySequenceSeconds": [0, 1],
        "ErrorCodes": ["40001", "40P01"]
      }
    }
  }
}

Example Configuration

Production configuration with extended retries:

json
{
  "CommandRetryOptions": {
    "Enabled": true,
    "DefaultStrategy": "default",
    "Strategies": {
      "default": {
        "RetrySequenceSeconds": [0, 0.5, 1, 2, 5, 10, 30],
        "ErrorCodes": [
          "40001", "40P01",
          "08000", "08003", "08006", "08001", "08004",
          "53300", "57P03"
        ]
      }
    }
  }
}

Using Strategies in Annotations

Assign strategies to specific endpoints using the retry_strategy annotation:

sql
-- Use aggressive retry for critical operations
comment on function process_payment() is
'HTTP POST
@retry aggressive';

-- Use minimal retry for fast queries
comment on function quick_lookup() is
'HTTP GET
@retry minimal';

-- Use default strategy explicitly
comment on function standard_operation() is
'HTTP POST
@retry_strategy default';

Next Steps

Comments

Released under the MIT License.