{
  "schema": 1,
  "sqlstate": "57P01",
  "condition_name": "admin_shutdown",
  "runner": "scripts/verify_cases.py",
  "targets": {
    "latest": {
      "binary": "Homebrew PostgreSQL 18.6",
      "required": true
    },
    "pg10": {
      "image": "postgres:10",
      "required": true
    }
  },
  "cases": [
    {
      "id": "admin_terminate_backend",
      "versions": [
        "10",
        "18"
      ],
      "preconditions": [
        "A runner-owned disposable target is provisioned.",
        "The victim PID is obtained from the connection being terminated."
      ],
      "trigger": "Create a runner client session, terminate only its backend PID from a separate runner session, and reconnect.",
      "assertions": [
        "The terminated backend reports SQLSTATE 57P01 and FATAL administrator-command text",
        "The selected PID is verified as a runner-created client backend and differs from the admin PID",
        "The victim connection closes after termination",
        "A fresh runner connection executes SELECT 1 successfully"
      ],
      "repair": "Treat the old connection as unusable after administrator termination; inspect the operation outcome and establish a fresh connection before continuing.",
      "cleanup": "Close all runner connections and drop the case schema with an owner connection."
    }
  ],
  "evidence_status": "authored",
  "snippets": [
    {
      "id": "admin_terminate_backend",
      "case_id": "admin_terminate_backend",
      "language": "sql",
      "statements": {
        "victim_pid": "SELECT pg_backend_pid()",
        "victim_probe": "SELECT 1",
        "admin_pid": "SELECT pg_backend_pid()",
        "identify": "SELECT pid, backend_type FROM pg_stat_activity WHERE pid = backend_pid",
        "terminate": "SELECT pg_terminate_backend(backend_pid)",
        "fresh_probe": "SELECT 1"
      }
    }
  ],
  "runtime": [
    {
      "id": "runtime.ops-57p01-latest-2.latest",
      "run_id": "ops-57p01-latest-2",
      "target": "latest",
      "status": "passed",
      "server_version": "18.6 (Homebrew)",
      "server_version_num": 180006,
      "summary_sha256": "3bb14b5b69013d2eae2eff3288abce3c8a03ebe37eb91f2cc1102b9554236ec0",
      "raw_sha256": "af36e671c47c60a79b375f939a35abd8fcc1c1276362ca6c1f344ee90f18ab61",
      "case_manifest": {
        "id": "manifest.57P01",
        "kind": "local_artifact",
        "source_role": "case_manifest"
      },
      "snippet_registry": {
        "id": "snippet-registry.57P01",
        "kind": "local_artifact",
        "source_role": "snippet_registry",
        "sha256": "114acc382b3918b4151994d137f245e0de3a7ea8cc194bf053eff4926626f3d1"
      },
      "environment": {
        "server_version": "18.6 (Homebrew)",
        "server_version_num": "180006",
        "current_user": "runner",
        "connection_scope": "runner-owned localhost port",
        "log_destination": "csvlog,jsonlog",
        "log_error_verbosity": "verbose",
        "psycopg_version": "3.3.5",
        "libpq_version": "18.6",
        "target_kind": "latest"
      },
      "cases": [
        "admin_terminate_backend"
      ],
      "observed": {
        "admin_pid": "distinct admin PID",
        "admin_status": "IDLE",
        "backend_identity": [
          "runner-created victim",
          "client backend"
        ],
        "driver_diagnostic": {
          "column_name": null,
          "constraint_name": null,
          "context": null,
          "datatype_name": null,
          "exception_type": "AdminShutdown",
          "internal_position": null,
          "internal_query": null,
          "message_detail": null,
          "message_hint": null,
          "message_primary": "terminating connection due to administrator command",
          "schema_name": null,
          "severity": "FATAL",
          "severity_nonlocalized": "FATAL",
          "source_file": "postgres.c",
          "source_function": "ProcessInterrupts",
          "source_line": "3356",
          "sqlstate": "57P01",
          "statement_position": null,
          "table_name": null,
          "text": "terminating connection due to administrator command"
        },
        "fresh_probe": 1,
        "fresh_status": "IDLE",
        "terminate_result": true,
        "termination_scope": "Only the runner-created client backend PID was targeted; the target postmaster and unrelated sessions were not targeted.",
        "victim_connection_closed": true,
        "victim_pid": "runner-created victim PID",
        "victim_probe_before": 1
      },
      "assertions": [
        {
          "expected": "57P01",
          "name": "57P01 SQLSTATE",
          "observed": "57P01",
          "passed": true
        },
        {
          "expected": "FATAL",
          "name": "57P01 FATAL severity",
          "observed": "FATAL",
          "passed": true
        },
        {
          "expected": {
            "admin_pid_distinct": true,
            "backend_type": "client backend",
            "pid": 44110
          },
          "name": "victim was a runner client backend",
          "observed": {
            "admin_pid": 44111,
            "identity": [
              44110,
              "client backend"
            ],
            "victim_pid": 44110
          },
          "passed": true
        },
        {
          "expected": true,
          "name": "pg_terminate_backend confirms termination",
          "observed": true,
          "passed": true
        },
        {
          "expected": {
            "message": "terminating connection due to administrator command",
            "severity": "FATAL"
          },
          "name": "terminated driver reports FATAL admin shutdown",
          "observed": {
            "driver": {
              "column_name": null,
              "constraint_name": null,
              "context": null,
              "datatype_name": null,
              "exception_type": "AdminShutdown",
              "internal_position": null,
              "internal_query": null,
              "message_detail": null,
              "message_hint": null,
              "message_primary": "terminating connection due to administrator command",
              "schema_name": null,
              "severity": "FATAL",
              "severity_nonlocalized": "FATAL",
              "source_file": "postgres.c",
              "source_function": "ProcessInterrupts",
              "source_line": "3356",
              "sqlstate": "57P01",
              "statement_position": null,
              "table_name": null,
              "text": "terminating connection due to administrator command"
            },
            "message": "terminating connection due to administrator command",
            "severity": "FATAL"
          },
          "passed": true
        },
        {
          "expected": true,
          "name": "terminated victim connection is closed",
          "observed": true,
          "passed": true
        },
        {
          "expected": {
            "admin_status": "IDLE",
            "fresh": 1,
            "fresh_status": "IDLE",
            "victim_before": 1
          },
          "name": "fresh connection recovers after targeted termination",
          "observed": {
            "admin_status": "IDLE",
            "fresh": 1,
            "fresh_status": "IDLE",
            "victim_before": 1
          },
          "passed": true
        }
      ],
      "cleanup": {
        "errors": [],
        "passed": true
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Asia/Shanghai",
          "backend_pid": 44106,
          "binary": {
            "bindir": "/opt/homebrew/Cellar/postgresql@18/18.6/bin",
            "pg_config": "/opt/homebrew/bin/pg_config",
            "pg_config_version": "PostgreSQL 18.6 (Homebrew)",
            "postgres": "/opt/homebrew/Cellar/postgresql@18/18.6/bin/postgres"
          },
          "connection_scope": "runner-owned localhost port",
          "current_user": "runner",
          "docker": {},
          "lc_messages": "C",
          "libpq_version": "18.6",
          "locale": "C.UTF-8",
          "log_destination": "csvlog,jsonlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "18.6 (Homebrew)",
          "server_version_num": "180006",
          "target_kind": "latest",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "57P01",
                "name": "57P01 SQLSTATE",
                "observed": "57P01",
                "passed": true
              },
              {
                "expected": "FATAL",
                "name": "57P01 FATAL severity",
                "observed": "FATAL",
                "passed": true
              },
              {
                "expected": {
                  "admin_pid_distinct": true,
                  "backend_type": "client backend",
                  "pid": 44110
                },
                "name": "victim was a runner client backend",
                "observed": {
                  "admin_pid": 44111,
                  "identity": [
                    44110,
                    "client backend"
                  ],
                  "victim_pid": 44110
                },
                "passed": true
              },
              {
                "expected": true,
                "name": "pg_terminate_backend confirms termination",
                "observed": true,
                "passed": true
              },
              {
                "expected": {
                  "message": "terminating connection due to administrator command",
                  "severity": "FATAL"
                },
                "name": "terminated driver reports FATAL admin shutdown",
                "observed": {
                  "driver": {
                    "column_name": null,
                    "constraint_name": null,
                    "context": null,
                    "datatype_name": null,
                    "exception_type": "AdminShutdown",
                    "internal_position": null,
                    "internal_query": null,
                    "message_detail": null,
                    "message_hint": null,
                    "message_primary": "terminating connection due to administrator command",
                    "schema_name": null,
                    "severity": "FATAL",
                    "severity_nonlocalized": "FATAL",
                    "source_file": "postgres.c",
                    "source_function": "ProcessInterrupts",
                    "source_line": "3356",
                    "sqlstate": "57P01",
                    "statement_position": null,
                    "table_name": null,
                    "text": "terminating connection due to administrator command"
                  },
                  "message": "terminating connection due to administrator command",
                  "severity": "FATAL"
                },
                "passed": true
              },
              {
                "expected": true,
                "name": "terminated victim connection is closed",
                "observed": true,
                "passed": true
              },
              {
                "expected": {
                  "admin_status": "IDLE",
                  "fresh": 1,
                  "fresh_status": "IDLE",
                  "victim_before": 1
                },
                "name": "fresh connection recovers after targeted termination",
                "observed": {
                  "admin_status": "IDLE",
                  "fresh": 1,
                  "fresh_status": "IDLE",
                  "victim_before": 1
                },
                "passed": true
              }
            ],
            "case_id": "admin_terminate_backend",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.011,
            "observed": {
              "admin_pid": 44111,
              "admin_status": "IDLE",
              "backend_identity": [
                44110,
                "client backend"
              ],
              "driver_diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "AdminShutdown",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "terminating connection due to administrator command",
                "schema_name": null,
                "severity": "FATAL",
                "severity_nonlocalized": "FATAL",
                "source_file": "postgres.c",
                "source_function": "ProcessInterrupts",
                "source_line": "3356",
                "sqlstate": "57P01",
                "statement_position": null,
                "table_name": null,
                "text": "terminating connection due to administrator command"
              },
              "fresh_probe": 1,
              "fresh_status": "IDLE",
              "terminate_result": true,
              "termination_scope": "Only the runner-created client backend PID was passed to pg_terminate_backend; the target postmaster and other sessions were not targeted.",
              "victim_connection_closed": true,
              "victim_pid": 44110,
              "victim_probe_before": 1
            },
            "schema": "c57p01_admin_terminate_backend",
            "status": "passed"
          }
        ]
      }
    },
    {
      "id": "runtime.ops-57p01-pg10-1.pg10",
      "run_id": "ops-57p01-pg10-1",
      "target": "pg10",
      "status": "passed",
      "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
      "server_version_num": 100021,
      "summary_sha256": "de98dafdcac66227274122faace891de1444dbfc75e14b92ba42c036a7373f0e",
      "raw_sha256": "d48f7bfdbedd98370ac1c10a36ae95bff1cec34b740baf258508e3c4fdd4ec6f",
      "case_manifest": {
        "id": "manifest.57P01",
        "kind": "local_artifact",
        "source_role": "case_manifest"
      },
      "snippet_registry": {
        "id": "snippet-registry.57P01",
        "kind": "local_artifact",
        "source_role": "snippet_registry",
        "sha256": "114acc382b3918b4151994d137f245e0de3a7ea8cc194bf053eff4926626f3d1"
      },
      "environment": {
        "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
        "server_version_num": "100021",
        "current_user": "postgres",
        "connection_scope": "runner-owned localhost port",
        "log_destination": "csvlog",
        "log_error_verbosity": "verbose",
        "psycopg_version": "3.3.5",
        "libpq_version": "18.6",
        "target_kind": "pg10"
      },
      "cases": [
        "admin_terminate_backend"
      ],
      "observed": {
        "admin_pid": "distinct admin PID",
        "admin_status": "IDLE",
        "backend_identity": [
          "runner-created victim",
          "client backend"
        ],
        "driver_diagnostic": {
          "column_name": null,
          "constraint_name": null,
          "context": null,
          "datatype_name": null,
          "exception_type": "AdminShutdown",
          "internal_position": null,
          "internal_query": null,
          "message_detail": null,
          "message_hint": null,
          "message_primary": "terminating connection due to administrator command",
          "schema_name": null,
          "severity": "FATAL",
          "severity_nonlocalized": "FATAL",
          "source_file": "postgres.c",
          "source_function": "ProcessInterrupts",
          "source_line": "2931",
          "sqlstate": "57P01",
          "statement_position": null,
          "table_name": null,
          "text": "terminating connection due to administrator command"
        },
        "fresh_probe": 1,
        "fresh_status": "IDLE",
        "terminate_result": true,
        "termination_scope": "Only the runner-created client backend PID was targeted; the target postmaster and unrelated sessions were not targeted.",
        "victim_connection_closed": true,
        "victim_pid": "runner-created victim PID",
        "victim_probe_before": 1
      },
      "assertions": [
        {
          "expected": "57P01",
          "name": "57P01 SQLSTATE",
          "observed": "57P01",
          "passed": true
        },
        {
          "expected": "FATAL",
          "name": "57P01 FATAL severity",
          "observed": "FATAL",
          "passed": true
        },
        {
          "expected": {
            "admin_pid_distinct": true,
            "backend_type": "client backend",
            "pid": 81
          },
          "name": "victim was a runner client backend",
          "observed": {
            "admin_pid": 82,
            "identity": [
              81,
              "client backend"
            ],
            "victim_pid": 81
          },
          "passed": true
        },
        {
          "expected": true,
          "name": "pg_terminate_backend confirms termination",
          "observed": true,
          "passed": true
        },
        {
          "expected": {
            "message": "terminating connection due to administrator command",
            "severity": "FATAL"
          },
          "name": "terminated driver reports FATAL admin shutdown",
          "observed": {
            "driver": {
              "column_name": null,
              "constraint_name": null,
              "context": null,
              "datatype_name": null,
              "exception_type": "AdminShutdown",
              "internal_position": null,
              "internal_query": null,
              "message_detail": null,
              "message_hint": null,
              "message_primary": "terminating connection due to administrator command",
              "schema_name": null,
              "severity": "FATAL",
              "severity_nonlocalized": "FATAL",
              "source_file": "postgres.c",
              "source_function": "ProcessInterrupts",
              "source_line": "2931",
              "sqlstate": "57P01",
              "statement_position": null,
              "table_name": null,
              "text": "terminating connection due to administrator command"
            },
            "message": "terminating connection due to administrator command",
            "severity": "FATAL"
          },
          "passed": true
        },
        {
          "expected": true,
          "name": "terminated victim connection is closed",
          "observed": true,
          "passed": true
        },
        {
          "expected": {
            "admin_status": "IDLE",
            "fresh": 1,
            "fresh_status": "IDLE",
            "victim_before": 1
          },
          "name": "fresh connection recovers after targeted termination",
          "observed": {
            "admin_status": "IDLE",
            "fresh": 1,
            "fresh_status": "IDLE",
            "victim_before": 1
          },
          "passed": true
        }
      ],
      "cleanup": {
        "errors": [],
        "passed": true
      },
      "result": {
        "status": "passed",
        "environment": {
          "TimeZone": "Etc/UTC",
          "backend_pid": 79,
          "binary": {},
          "connection_scope": "runner-owned localhost port",
          "current_user": "postgres",
          "docker": {
            "architecture": "arm64",
            "command": "/usr/local/bin/docker",
            "digest": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "id": "sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "image": "postgres:10",
            "image_created": "2022-06-23T09:11:18.374607054Z",
            "image_ref": "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc",
            "log_destination": "csvlog",
            "os": "linux",
            "repo_digests": [
              "postgres@sha256:b2baf8998630663d21370da06387c950e587071bdd307ee34e661cdcc7442bcc"
            ]
          },
          "lc_messages": "en_US.utf8",
          "libpq_version": "18.6",
          "locale": "C.UTF-8",
          "log_destination": "csvlog",
          "log_error_verbosity": "verbose",
          "log_min_error_statement": "error",
          "log_min_messages": "error",
          "logging_collector": "on",
          "machine": "arm64",
          "max_connections": "100",
          "platform": "macOS-26.6.2-arm64-arm-64bit-Mach-O",
          "psycopg_version": "3.3.5",
          "python_version": "3.14.6 (main, Jun 10 2026, 10:03:53) [Clang 21.0.0 (clang-2100.0.123.102)]",
          "server_encoding": "UTF8",
          "server_version": "10.21 (Debian 10.21-1.pgdg90+1)",
          "server_version_num": "100021",
          "target_kind": "pg10",
          "wal_level": "logical"
        },
        "cases": [
          {
            "assertions": [
              {
                "expected": "57P01",
                "name": "57P01 SQLSTATE",
                "observed": "57P01",
                "passed": true
              },
              {
                "expected": "FATAL",
                "name": "57P01 FATAL severity",
                "observed": "FATAL",
                "passed": true
              },
              {
                "expected": {
                  "admin_pid_distinct": true,
                  "backend_type": "client backend",
                  "pid": 81
                },
                "name": "victim was a runner client backend",
                "observed": {
                  "admin_pid": 82,
                  "identity": [
                    81,
                    "client backend"
                  ],
                  "victim_pid": 81
                },
                "passed": true
              },
              {
                "expected": true,
                "name": "pg_terminate_backend confirms termination",
                "observed": true,
                "passed": true
              },
              {
                "expected": {
                  "message": "terminating connection due to administrator command",
                  "severity": "FATAL"
                },
                "name": "terminated driver reports FATAL admin shutdown",
                "observed": {
                  "driver": {
                    "column_name": null,
                    "constraint_name": null,
                    "context": null,
                    "datatype_name": null,
                    "exception_type": "AdminShutdown",
                    "internal_position": null,
                    "internal_query": null,
                    "message_detail": null,
                    "message_hint": null,
                    "message_primary": "terminating connection due to administrator command",
                    "schema_name": null,
                    "severity": "FATAL",
                    "severity_nonlocalized": "FATAL",
                    "source_file": "postgres.c",
                    "source_function": "ProcessInterrupts",
                    "source_line": "2931",
                    "sqlstate": "57P01",
                    "statement_position": null,
                    "table_name": null,
                    "text": "terminating connection due to administrator command"
                  },
                  "message": "terminating connection due to administrator command",
                  "severity": "FATAL"
                },
                "passed": true
              },
              {
                "expected": true,
                "name": "terminated victim connection is closed",
                "observed": true,
                "passed": true
              },
              {
                "expected": {
                  "admin_status": "IDLE",
                  "fresh": 1,
                  "fresh_status": "IDLE",
                  "victim_before": 1
                },
                "name": "fresh connection recovers after targeted termination",
                "observed": {
                  "admin_status": "IDLE",
                  "fresh": 1,
                  "fresh_status": "IDLE",
                  "victim_before": 1
                },
                "passed": true
              }
            ],
            "case_id": "admin_terminate_backend",
            "cleanup": {
              "errors": [],
              "passed": true
            },
            "elapsed_seconds": 0.016,
            "observed": {
              "admin_pid": 82,
              "admin_status": "IDLE",
              "backend_identity": [
                81,
                "client backend"
              ],
              "driver_diagnostic": {
                "column_name": null,
                "constraint_name": null,
                "context": null,
                "datatype_name": null,
                "exception_type": "AdminShutdown",
                "internal_position": null,
                "internal_query": null,
                "message_detail": null,
                "message_hint": null,
                "message_primary": "terminating connection due to administrator command",
                "schema_name": null,
                "severity": "FATAL",
                "severity_nonlocalized": "FATAL",
                "source_file": "postgres.c",
                "source_function": "ProcessInterrupts",
                "source_line": "2931",
                "sqlstate": "57P01",
                "statement_position": null,
                "table_name": null,
                "text": "terminating connection due to administrator command"
              },
              "fresh_probe": 1,
              "fresh_status": "IDLE",
              "terminate_result": true,
              "termination_scope": "Only the runner-created client backend PID was passed to pg_terminate_backend; the target postmaster and other sessions were not targeted.",
              "victim_connection_closed": true,
              "victim_pid": 81,
              "victim_probe_before": 1
            },
            "schema": "c57p01_admin_terminate_backend",
            "status": "passed"
          }
        ]
      }
    }
  ]
}
