{
 "kind": "tool",
 "slug": "pg",
 "path": "tools/pg/",
 "name": "pg",
 "maker": null,
 "density": "profile",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Databases, ORMs and clients",
   "tools/databases-orms/"
  ]
 ],
 "lead": "PostgreSQL client for Node.js with pure JavaScript and libpq API compatibility.",
 "chips": [
  {
   "label": "Databases, ORMs and clients",
   "path": "tools/databases-orms/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install pg"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/brianc/node-postgres"
  },
  {
   "label": "Website",
   "href": "https://github.com/brianc/node-postgres"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": null,
   "note": "License from npm.",
   "src": "https://github.com/brianc/node-postgres"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Oct 23, 2026",
   "note": "",
   "src": "https://github.com/brianc/node-postgres"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "298 projects",
   "status": "info",
   "sub": "#1 of 120 in its category",
   "note": "Dependency in 298 public GitHub projects set up for AI coding agents that we scanned (4.8%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What pg does",
   "parts": [
    {
     "t": "prose",
     "text": "pg is a deliberately thin PostgreSQL client that ships a pure-JavaScript driver and optional native libpq bindings behind the same API, and leaves the higher-level abstractions to you."
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "pg popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "81",
       "of": "/ 100",
       "l": "Gid Score, #81 overall"
      },
      {
       "n": "106M",
       "l": "downloads a week, npm"
      },
      {
       "n": "13.2K",
       "l": "GitHub stars"
      },
      {
       "n": "298",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How pg is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "pg is a dependency in 298 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (6.1% of the 4,867 JavaScript/TypeScript ones), #1 of 120 in databases, orms and clients.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 878; those are left out of every share on this page.",
      "The most used alternative in our scan is Drizzle ORM (253 projects).",
      "Projects that use it most often also use dotenv (62.1%), tsx (52.7%), Next.js (53.4%).",
      "It is more common in projects set up for Devin Desktop (8.2%) than for GitHub Copilot (5.0%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "173 projects, 5.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "153 projects, 5.0%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "130 projects, 5.3%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "33 projects, 7.0%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "26 projects, 5.5%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "23 projects, 8.2%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "20 projects, 5.8%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      },
      {
       "l": "17 projects, 5.1%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 62.1% of its projects",
       "v": "dotenv",
       "path": "tools/dotenv/"
      },
      {
       "l": "In 52.7% of its projects",
       "v": "tsx",
       "path": "tools/tsx/"
      },
      {
       "l": "In 53.4% of its projects",
       "v": "Next.js",
       "path": "tools/next/"
      },
      {
       "l": "In 62.8% of its projects",
       "v": "Zod",
       "path": "tools/zod/"
      },
      {
       "l": "In 55.7% of its projects",
       "v": "Lucide React",
       "path": "tools/lucide-react/"
      },
      {
       "l": "In 91.6% of its projects",
       "v": "TypeScript",
       "path": "tools/typescript/"
      },
      {
       "l": "In 69.5% of its projects",
       "v": "React",
       "path": "tools/react/"
      },
      {
       "l": "In 69.1% of its projects",
       "v": "Tailwind CSS",
       "path": "tools/tailwindcss/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "pg in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Parameters travel apart from the SQL",
       "v": "The FAQ calls parameterized query support \"first class\". Values are sent to the server separately from the query text. Its example passes <code>\"'; DROP TABLE user;\"</code> as a parameter and states that this will not inject SQL."
      },
      {
       "l": "JavaScript or libpq, same calls",
       "v": "You can run the pure-JavaScript client or the optional libpq bindings. The maintainer writes that \"they both work equally\" and have full feature parity, which he credits to \"the extensive overlapping test suite\"."
      },
      {
       "l": "PostgreSQL-specific features exposed",
       "v": "Beyond plain queries, the README lists named statements with query plan caching, <code>LISTEN/NOTIFY</code> notifications, and bulk import and export with <code>COPY</code>."
      },
      {
       "l": "Old servers and several runtimes",
       "v": "The docs say pg supports every PostgreSQL version from 8.x to the latest. They say it runs on current and LTS Node releases, and on bun, deno and Cloudflare Workers."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "Few abstractions on purpose",
       "v": "Higher-level helpers are not in the core. The README points to a wiki list of extra modules \"to complete the picture.\""
      },
      {
       "l": "The pool won't end your transaction",
       "v": "According to the FAQ, nothing happens to an open transaction when a client goes back to the pool. You must issue <code>COMMIT</code> or <code>ROLLBACK</code> yourself."
      },
      {
       "l": "pg-native on Windows needs a local PostgreSQL",
       "v": "The FAQ documents <code>npm install pg-native</code> failing on Windows while trying to load <code>binding.gyp</code>. The fix is to install PostgreSQL and add its bin directory, where <code>pg_config</code> lives, to PATH."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Connect, run a parameterized query, and clean up"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Javascript",
       "code": "import { Client } from 'pg'\nconst client = await new Client (). connect ()\ntry {\n  const res = await client. query ( 'SELECT $1::text as message' , [ 'Hello world!' ])\n  console. log (res.rows[ 0 ].message) // Hello world!\n} catch (err) {\n  console. error (err)\n} finally {\n  await client. end ()\n}"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about pg",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "GitHub Sponsors: https://github.com/brianc",
        "17 GitHub sponsors"
       ]
      },
      {
       "title": "Head to head",
       "items": [
        {
         "text": "pg vs Neon Serverless Driver",
         "note": "used together in 31 projects",
         "path": "tools/compare/pg-vs-neon-serverless-driver/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "dotenv: Loads .env config",
        "zod: Schema validation",
        "tsx: Runs TypeScript files",
        "class-variance-authority: Component style variants",
        "lucide-react: React icons",
        "tailwind-merge: Merges Tailwind classes"
       ]
      },
      {
       "title": "More in Databases, ORMs and clients",
       "path": "tools/databases-orms/",
       "items": [
        {
         "text": "Drizzle Kit",
         "path": "tools/drizzle-kit/"
        },
        {
         "text": "SQLAlchemy",
         "path": "tools/sqlalchemy/"
        },
        {
         "text": "better-sqlite3",
         "path": "tools/better-sqlite3/"
        },
        {
         "text": "psycopg2",
         "path": "tools/psycopg2-binary/"
        },
        {
         "text": "Alembic",
         "path": "tools/alembic/"
        },
        {
         "text": "psycopg",
         "path": "tools/psycopg/"
        },
        {
         "text": "asyncpg",
         "path": "tools/asyncpg/"
        },
        {
         "text": "aiosqlite",
         "path": "tools/aiosqlite/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "pg",
       "me": true,
       "facts": [
        "MIT",
        "Gid 81",
        "106M/wk"
       ]
      },
      {
       "name": "Drizzle ORM",
       "why": "TypeScript ORM for SQL databases with type safety and zero-runtime overhead.",
       "path": "tools/drizzle-orm/",
       "facts": [
        "Apache-2.0",
        "Gid 86",
        "49.6M/wk"
       ]
      },
      {
       "name": "Prisma",
       "why": "Modern ORM with intuitive schema, migrations, and type-safe database queries.",
       "path": "tools/prisma/",
       "facts": [
        "Apache-2.0",
        "Gid 64",
        "26M/wk"
       ]
      },
      {
       "name": "Neon Serverless Driver",
       "why": "PostgreSQL driver optimized for serverless environments from Neon.",
       "path": "tools/neondatabase/",
       "facts": [
        "MIT",
        "Gid 60",
        "8.8M/wk"
       ]
      },
      {
       "name": "mysql2",
       "why": "Fast MySQL driver with native protocol implementation, prepared statements and SSL.",
       "path": "tools/mysql2/",
       "facts": [
        "MIT",
        "Gid 66",
        "25.6M/wk"
       ]
      },
      {
       "name": "sqlite3",
       "why": "Asynchronous, non-blocking SQLite3 database bindings for Node.js.",
       "path": "tools/sqlite3/",
       "facts": [
        "BSD-3-Clause",
        "Gid 58",
        "2.9M/wk"
       ]
      }
     ],
     "more": "Compare pg with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "install",
     "intro": "Install it.",
     "code": "npm install pg"
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## pg (node-postgres)\n- Pass values as parameters (`$1`, `$2`, ...) in the second argument of `query()`. The FAQ says parameters are sent separately from the SQL.\n- If you must build an `IN (...)` list, generate only the `$n` placeholders and pass the values as the parameter array, as the FAQ example does.\n- Use a `Pool` in most applications. The docs say \"In most applications you’ll want to use a connection pool\".\n- After a transaction on a pooled client, run `COMMIT` or `ROLLBACK` before releasing it. The pool does nothing to open transactions.\n- Wrap queries in `try/catch` and call `client.end()` in `finally`. The docs' short examples assume success.\n- To match a list of values, pass a JavaScript array to `= ANY ($1)`.\n- A named prepared statement is parsed once. Later calls with the same name reuse it regardless of the query text, so don't reuse a name for different SQL.\n"
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm pg"
  ],
  [
   "Category",
   "Databases, ORMs and clients"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "8.23.1, September 30, 2026"
  ],
  [
   "On GitHub since",
   "October 2010"
  ],
  [
   "Gid Score",
   "80.9"
  ],
  [
   "Rank in category",
   "#1 of 120"
  ],
  [
   "GitHub",
   "brianc/node-postgres"
  ],
  [
   "Last change",
   "Oct 23, 2026"
  ]
 ],
 "good": [],
 "checked_line": "From the package registry, GitHub and our scan of public agent projects; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/brianc.png"
}