> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PostgreSQL Instrumentation

export const Compatibility = ({versions = [], label = "Available in"}) => {
  if (!Array.isArray(versions) || versions.length === 0) {
    return null;
  }
  const defaultPillStyle = {
    borderColor: "#d4d4d8",
    background: "#f4f4f5",
    color: "#3f3f46"
  };
  const pillStyles = {
    "AppSignal for Elixir": {
      background: "#f3e8ff",
      borderColor: "#d8b4fe",
      color: "#6b21a8"
    },
    "AppSignal for Front-end": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Go": {
      background: "#ccfbf1",
      borderColor: "#5eead4",
      color: "#115e59"
    },
    "AppSignal for JavaScript": {
      background: "#fef9c3",
      borderColor: "#fde047",
      color: "#854d0e"
    },
    "AppSignal for Node.js": {
      background: "#dcfce7",
      borderColor: "#86efac",
      color: "#166534"
    },
    "AppSignal for Python": {
      background: "#dbeafe",
      borderColor: "#93c5fd",
      color: "#1e40af"
    },
    "AppSignal for Ruby": {
      background: "#fee2e2",
      borderColor: "#fca5a5",
      color: "#991b1b"
    },
    "AppSignal for Rust": {
      background: "#ffedd5",
      borderColor: "#fdba74",
      color: "#9a3412"
    }
  };
  const getPillStyle = name => ({
    ...defaultPillStyle,
    ...pillStyles[name] || ({})
  });
  return <div className="not-prose my-4 rounded-lg border border-zinc-200 bg-zinc-50 px-4 py-3 text-sm dark:border-white/10 dark:bg-white/5">
      <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
        <span className="font-semibold text-zinc-700 dark:text-zinc-200">
          {label}:
        </span>
        {versions.map((v, i) => <span key={`${v.name}-${v.version}-${i}`} className="inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs font-medium" style={getPillStyle(v.name)}>
            <span>{v.name}</span>
            <span className="opacity-70">
              {v.version}
              {v.exact ? "" : "+"}
            </span>
          </span>)}
      </div>
    </div>;
};

## Installation

<Note>
  🐍 Don't forget to [install the AppSignal for Python package](/python/installation) in your application first.
</Note>

The installation instructions differ based on the PostgreSQL adapter package you are using:

* [`aiopg`](#using-aiopg)
* [`asyncpg`](#using-asyncpg)
* [`psycopg2`](#using-psycopg2)
* [`psycopg`](#using-psycopg) (version 3)

<Warning>
  When using [SQLAlchemy](/python/instrumentations/sqlalchemy), **do not** install these instrumentation packages. The instrumentation for SQLAlchemy will automatically instrument queries to the underlying database. Installing both instrumentation packages will result in duplicate events.
</Warning>

### Using `aiopg`

<Compatibility
  versions={[
{ name: "AppSignal for Python", version: "1.3.2" },
{ name: "aiopg", version: "0.13.0" },
]}
/>

When using the `aiopg` PostgreSQL adapter package, install the `opentelemetry-instrumentation-aiopg` package. To add it to your project, add the following line to your `requirements.txt` file:

<CodeGroup>
  ```python Python theme={null}

  <PythonDisableInstrumentations />
  # requirements.txt
  opentelemetry-instrumentation-aiopg
  ```
</CodeGroup>

### Using `asyncpg`

<Compatibility
  versions={[
{ name: "AppSignal for Python", version: "1.3.2" },
{ name: "asyncpg", version: "0.12.0" },
]}
/>

When using the `asyncpg` PostgreSQL adapter package, install the `opentelemetry-instrumentation-asyncpg` package. To add it to your project, add the following line to your `requirements.txt` file:

<CodeGroup>
  ```python Python theme={null}
  # requirements.txt
  opentelemetry-instrumentation-asyncpg
  ```
</CodeGroup>

### Using `psycopg2`

<Compatibility
  versions={[
{ name: "AppSignal for Python", version: "0.1.0" },
{ name: "psycopg2", version: "2.7.3.1" },
]}
/>

When using the `psycopg2` PostgreSQL adapter package, install the `opentelemetry-instrumentation-psycopg2` package. To add it to your project, add the following line to your `requirements.txt` file:

<CodeGroup>
  ```python Python theme={null}
  # requirements.txt
  opentelemetry-instrumentation-psycopg2
  ```
</CodeGroup>

### Using `psycopg`

<Compatibility
  versions={[
{ name: "AppSignal for Python", version: "1.3.1" },
{ name: "psycopg", version: "3.1.0" },
]}
/>

When using the `psycopg` (version 3) PostgreSQL adapter package, install the `opentelemetry-instrumentation-psycopg` package. To add it to your project, add the following line to your `requirements.txt` file:

<CodeGroup>
  ```python Python theme={null}
  # requirements.txt
  opentelemetry-instrumentation-psycopg
  ```
</CodeGroup>
