PageSourceSearch

https://node-postgres.com/_next/static/chunks/pages/features/native-0ff91370421a235c.js

js node-postgres.com collected 2026-10-01 08:41:36 UTC 9,945 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[222],{1257:function(e,t,i){(window.__NEXT_P=window.__NEXT_P||[]).push(["/features/native",function(){return i(2500)}])},2500:function(e,t,i){"use strict";i.r(t),i.d(t,{useTOC:function(){return useTOC}});var s=i(5893),n=i(7812),r=i(3151),a=i(9299),l=i(5192);function useTOC(e){return[]}t.default=(0,n.c)(function(e){let t={a:"a",code:"code",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",ul:"ul",...(0,a.a)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(t.p,{children:["Native bindings between node.js & ",(0,s.jsx)(t.a,{href:"https://www.postgresql.org/docs/9.5/static/libpq.html",children:"libpq"})," are provided by the ",(0,s.jsx)(t.a,{href:"https://github.com/brianc/node-pg-native",children:"node-pg-native"})," package. node-postgres can consume this package & use the native bindings to access the PostgreSQL server while giving you the same interface that is used with the JavaScript version of the library."]}),"\n",(0,s.jsxs)(t.p,{children:["You need PostgreSQL client libraries & tools installed. An easy way to check is to type ",(0,s.jsx)(t.code,{children:"pg_config"}),". If ",(0,s.jsx)(t.code,{children:"pg_config"})," is in your path, you should be good to go. If it’s not in your path you’ll need to consult operating specific instructions on how to go about getting it there."]}),"\n",(0,s.jsx)(t.p,{children:"Some ways I’ve done it in the past:"}),"\n",(0,s.jsxs)(t.ul,{children:["\n",(0,s.jsxs)(t.li,{children:["On macOS: ",(0,s.jsx)(t.code,{children:"brew install libpq"})]}),"\n",(0,s.jsxs)(t.li,{children:["On Ubuntu/Debian and Debian-based Node images: ",(0,s.jsx)(t.code,{children:"apt-get install libpq-dev python3 g++ make"})]}),"\n",(0,s.jsxs)(t.li,{children:["On RHEL/CentOS: ",(0,s.jsx)(t.code,{children:"yum install postgresql-devel"})]}),"\n",(0,s.jsx)(t.li,{children:"On Windows:"}),"\n"]}),"\n",(0,s.jsxs)(t.ol,{children:["\n",(0,s.jsx)(t.li,{children:"Install Visual Studio C++ (successfully built with Express 2010). Express is free."}),"\n",(0,s.jsxs)(t.li,{children:["Install PostgreSQL (",(0,s.jsx)(t.code,{children:"http://www.postgresql.org/download/windows/"}),")"]}),"\n",(0,s.jsxs)(t.li,{children:["Add your Postgre Installation’s ",(0,s.jsx)(t.code,{children:"bin"})," folder to the system path (i.e. ",(0,s.jsx)(t.code,{children:"C:\\Program Files\\PostgreSQL\\9.3\\bin"}),")."]}),"\n",(0,s.jsxs)(t.li,{children:["Make sure that both ",(0,s.jsx)(t.code,{children:"libpq.dll"})," and ",(0,s.jsx)(t.code,{children:"pg_config.exe"})," are in that folder."]}),"\n"]}),"\n",(0,s.jsxs)(t.p,{children:["Install ",(0,s.jsx)(t.code,{children:"pg"})," and ",(0,s.jsx)(t.code,{children:"pg-native"})," them:"]}),"\n",(0,s.jsx)(t.pre,{icon:l.Fx,tabIndex:"0","data-language":"sh","data-word-wrap":"",children:(0,s.jsx)(t.code,{children:(0,s.jsxs)(t.span,{children:[(0,s.jsx)(t.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"$"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" npm"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" install"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" pg"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" pg-native"})]})})}),"\n",(0,s.jsxs)(t.p,{children:["Once ",(0,s.jsx)(t.code,{children:"pg-native"})," is installed instead of requiring a ",(0,s.jsx)(t.code,{children:"Client"})," or ",(0,s.jsx)(t.code,{children:"Pool"})," constructor from ",(0,s.jsx)(t.code,{children:"pg"})," you do the following:"]}),"\n",(0,s.jsx)(t.pre,{icon:l.Dr,tabIndex:"0","data-language":"js","data-word-wrap":"",children:(0,s.jsxs)(t.code,{children:[(0,s.jsxs)(t.span,{children:[(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" pg "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" 'pg'"})]}),"\n",(0,s.jsxs)(t.span,{children:[(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"native"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" } "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"="}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" pg"})]}),"\n",(0,s.jsxs)(t.span,{children:[(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"Client"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:", "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"Pool"}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" } "}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"="}),(0,s.jsx)(t.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" native"})]})]})}),"\n",(0,s.jsxs)(t.p,{children:["When you access the ",(0,s.jsx)(t.code,{children:".native"})," property on ",(0,s.jsx)(t.code,{children:"'pg'"})," it will automatically require the ",(0,s.jsx)(t.code,{children:"pg-native"})," package and wrap it in the same API."]}),"\n",(0,s.jsx)("div",{class:"alert alert-warning",children:(0,s.jsxs)(t.p,{children:["Care has been taken to normalize between the two, but there might still be edge cases where things behave subtly differently due to the nature of using libpq over handling the binary protocol directly in JavaScript, so it’s recommended you chose to either use the JavaScript driver or the native bindings both in development and production.  For what its worth: I use the pure JavaScript driver because the JavaScript driver is more portable (doesn’t need a compiler), and the pure JavaScript driver is ",(0,s.jsx)("em",{children:"plenty"})," fast."]})}),"\n",(0,s.jsxs)(t.p,{children:["Some of the modules using advanced features of PostgreSQL such as ",(0,s.jsx)(t.a,{href:"https://github.com/brianc/node-pg-query-stream",children:"pg-query-stream"}),", ",(0,s.jsx)(t.a,{href:"https://github.com/brianc/node-pg-cursor",children:"pg-cursor"}),",and ",(0,s.jsx)(t.a,{href:"https://github.com/brianc/node-pg-copy-stream
1s",children:"pg-copy-streams"})," need to operate directly on the binary stream and therefore are incompatible with the native bindings."]})]})},"/features/native",{filePath:"pages/features/native.mdx",timestamp:179078257e4,pageMap:r.v,frontMatter:{title:"Native Bindings",slug:"/features/native",metaTitle:"bar"},title:"Native Bindings"},"undefined"==typeof RemoteContent?useTOC:RemoteContent.useTOC)},3151:function(e,t,i){"use strict";i.d(t,{v:function(){return s}});let s=[{data:{index:"Welcome",announcements:"Announcements",apis:"API"}},{name:"announcements",route:"/announcements",frontMatter:{sidebarTitle:"Announcements"}},{name:"apis",route:"/apis",children:[{data:{client:"pg.Client",pool:"pg.Pool",result:"pg.Result",types:"pg.Types",cursor:"Cursor",utilities:"Utilities"}},{name:"client",route:"/apis/client",frontMatter:{title:"pg.Client"}},{name:"cursor",route:"/apis/cursor",frontMatter:{title:"pg.Cursor",slug:"/apis/cursor"}},{name:"pool",route:"/apis/pool",frontMatter:{title:"pg.Pool"}},{name:"result",route:"/apis/result",frontMatter:{title:"pg.Result",slug:"/apis/result"}},{name:"types",route:"/apis/types",frontMatter:{title:"Types",slug:"/apis/types"}},{name:"utilities",route:"/apis/utilities",frontMatter:{title:"Utilities"}}]},{name:"features",route:"/features",children:[{data:{connecting:"Connecting",queries:"Queries",pipelining:"Pipelining",pooling:"Pooling",transactions:"Transactions",types:"Data Types",ssl:"SSL",native:"Native",esm:"ESM",callbacks:"Callbacks"}},{name:"callbacks",route:"/features/callbacks",frontMatter:{title:"Callbacks"}},{name:"connecting",route:"/features/connecting",frontMatter:{title:"Connecting"}},{name:"esm",route:"/features/esm",frontMatter:{title:"ESM"}},{name:"native",route:"/features/native",frontMatter:{title:"Native Bindings",slug:"/features/native",metaTitle:"bar"}},{name:"pipelining",route:"/features/pipelining",frontMatter:{title:"Pipelining"}},{name:"pooling",route:"/features/pooling",frontMatter:{title:"Pooling"}},{name:"queries",route:"/features/queries",frontMatter:{title:"Queries",slug:"/features/queries"}},{name:"ssl",route:"/features/ssl",frontMatter:{title:"SSL",slug:"/features/ssl"}},{name:"transactions",route:"/features/transactions",frontMatter:{title:"Transactions"}},{name:"types",route:"/features/types",frontMatter:{title:"Data Types"}}]},{name:"guides",route:"/guides",children:[{data:{"project-structure":"Suggested Code Structure","async-express":"Express with Async/Await","pool-sizing":"Pool Sizing",upgrading:"Upgrading"}},{name:"async-express",route:"/guides/async-express",frontMatter:{title:"Express with async/await"}},{name:"pool-sizing",route:"/guides/pool-sizing",frontMatter:{title:"Pool Sizing"}},{name:"project-structure",route:"/guides/project-structure",frontMatter:{title:"Suggested Project Structure"}},{name:"upgrading",route:"/guides/upgrading",frontMatter:{title:"Upgrading",slug:"/guides/upgrading"}}]},{name:"index",route:"/",frontMatter:{title:"Welcome",slug:"/"}}]}},function(e){e.O(0,[794,774,888,179],function(){return e(e.s=1257)}),_N_E=e.O()}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.