[{"data":1,"prerenderedAt":463},["ShallowReactive",2],{"navigation":3,"\u002Fguide\u002Fsocket\u002Fadvanced":208,"\u002Fguide\u002Fsocket\u002Fadvanced-surround":458},[4,98,175],{"title":5,"path":6,"stem":7,"children":8,"icon":97},"Guide","\u002Fguide","1.guide\u002F1.index",[9,12,17,22,46,61,79],{"title":10,"path":6,"stem":7,"icon":11},"Introduction","i-lucide-house",{"title":13,"path":14,"stem":15,"icon":16},"Installation","\u002Fguide\u002Finstallation","1.guide\u002F2.installation","i-lucide-download",{"title":18,"path":19,"stem":20,"icon":21},"Quick start","\u002Fguide\u002Fquick-start","1.guide\u002F3.quick-start","i-lucide-rocket",{"title":23,"path":24,"stem":25,"children":26,"icon":45},"Server","\u002Fguide\u002Fserver","1.guide\u002F4.server\u002F1.index",[27,30,35,40],{"title":28,"path":24,"stem":25,"icon":29},"Usage","i-lucide-server",{"title":31,"path":32,"stem":33,"icon":34},"Config file","\u002Fguide\u002Fserver\u002Fconfig-file","1.guide\u002F4.server\u002F2.config-file","i-lucide-file-cog",{"title":36,"path":37,"stem":38,"icon":39},"Options","\u002Fguide\u002Fserver\u002Foptions","1.guide\u002F4.server\u002F3.options","i-lucide-settings",{"title":41,"path":42,"stem":43,"icon":44},"Advanced","\u002Fguide\u002Fserver\u002Fadvanced","1.guide\u002F4.server\u002F4.advanced","i-lucide-flask-conical",false,{"title":47,"path":48,"stem":49,"children":50,"icon":45},"Client","\u002Fguide\u002Fclient","1.guide\u002F5.client\u002F1.index",[51,53,58],{"title":28,"path":48,"stem":49,"icon":52},"i-lucide-monitor-smartphone",{"title":54,"path":55,"stem":56,"icon":57},"Live queries","\u002Fguide\u002Fclient\u002Flive-queries","1.guide\u002F5.client\u002F2.live-queries","i-lucide-radio",{"title":41,"path":59,"stem":60,"icon":44},"\u002Fguide\u002Fclient\u002Fadvanced","1.guide\u002F5.client\u002F3.advanced",{"title":62,"path":63,"stem":64,"children":65,"icon":45},"Development socket","\u002Fguide\u002Fsocket","1.guide\u002F6.socket\u002F1.index",[66,68,71,74],{"title":28,"path":63,"stem":64,"icon":67},"i-lucide-plug",{"title":36,"path":69,"stem":70,"icon":39},"\u002Fguide\u002Fsocket\u002Foptions","1.guide\u002F6.socket\u002F2.options",{"title":41,"path":72,"stem":73,"icon":44},"\u002Fguide\u002Fsocket\u002Fadvanced","1.guide\u002F6.socket\u002F3.advanced",{"title":75,"path":76,"stem":77,"icon":78},"PGlite in dev, Postgres in prod","\u002Fguide\u002Fsocket\u002Fdevelopment-only","1.guide\u002F6.socket\u002F4.development-only","i-lucide-cloud-upload",{"title":80,"path":81,"stem":82,"children":83,"icon":45},"DevTools & tooling","\u002Fguide\u002Fdevtools","1.guide\u002F7.devtools\u002F1.index",[84,87,92],{"title":85,"path":81,"stem":82,"icon":86},"DevTools tab","i-lucide-wrench",{"title":88,"path":89,"stem":90,"icon":91},"Actions","\u002Fguide\u002Fdevtools\u002Factions","1.guide\u002F7.devtools\u002F2.actions","i-lucide-zap",{"title":93,"path":94,"stem":95,"icon":96},"Terminal","\u002Fguide\u002Fdevtools\u002Fterminal","1.guide\u002F7.devtools\u002F3.terminal","i-lucide-square-terminal","i-lucide-book-open",{"title":99,"icon":100,"path":101,"stem":102,"children":103,"page":45},"Recipes","i-lucide-chef-hat","\u002Frecipes","2.recipes",[104,116,138,159,171],{"title":105,"path":106,"stem":107,"children":108,"icon":45},"Migrations","\u002Frecipes\u002Fmigrations","2.recipes\u002F1.migrations\u002F1.index",[109,111],{"title":28,"path":106,"stem":107,"icon":110},"i-lucide-database-backup",{"title":112,"path":113,"stem":114,"icon":115},"Edited migrations","\u002Frecipes\u002Fmigrations\u002Fedited-migrations","2.recipes\u002F1.migrations\u002F2.edited-migrations","i-lucide-file-diff",{"title":117,"path":118,"stem":119,"children":120,"icon":45},"Testing","\u002Frecipes\u002Ftesting","2.recipes\u002F2.testing\u002F1.index",[121,123,128,133],{"title":28,"path":118,"stem":119,"icon":122},"i-lucide-test-tube",{"title":124,"path":125,"stem":126,"icon":127},"Isolation","\u002Frecipes\u002Ftesting\u002Fisolation","2.recipes\u002F2.testing\u002F2.isolation","i-lucide-git-fork",{"title":129,"path":130,"stem":131,"icon":132},"vitest","\u002Frecipes\u002Ftesting\u002Fvitest","2.recipes\u002F2.testing\u002F3.vitest","i-simple-icons-vitest",{"title":134,"path":135,"stem":136,"icon":137},"@nuxt\u002Ftest-utils","\u002Frecipes\u002Ftesting\u002Fnuxt-test-utils","2.recipes\u002F2.testing\u002F4.nuxt-test-utils","i-simple-icons-nuxt",{"title":139,"path":140,"stem":141,"children":142,"icon":45},"Deploy","\u002Frecipes\u002Fdeploy","2.recipes\u002F3.deploy\u002F1.index",[143,144,149,154],{"title":139,"path":140,"stem":141},{"title":145,"path":146,"stem":147,"icon":148},"Any Postgres","\u002Frecipes\u002Fdeploy\u002Fpostgres","2.recipes\u002F3.deploy\u002F2.postgres","i-lucide-database",{"title":150,"path":151,"stem":152,"icon":153},"Netlify","\u002Frecipes\u002Fdeploy\u002Fnetlify","2.recipes\u002F3.deploy\u002F3.netlify","i-simple-icons-netlify",{"title":155,"path":156,"stem":157,"icon":158},"Neon","\u002Frecipes\u002Fdeploy\u002Fneon","2.recipes\u002F3.deploy\u002F4.neon","i-simple-icons-neon",{"title":160,"path":161,"stem":162,"children":163,"icon":45},"Outside Nuxt","\u002Frecipes\u002Foutside-nuxt","2.recipes\u002F4.outside-nuxt\u002F1.index",[164,167],{"title":165,"path":161,"stem":162,"icon":166},"Config and provider","i-lucide-package",{"title":168,"path":169,"stem":170,"icon":67},"Socket server","\u002Frecipes\u002Foutside-nuxt\u002Fsocket","2.recipes\u002F4.outside-nuxt\u002F2.socket",{"title":172,"path":173,"stem":174,"icon":67},"Nitro's useDatabase","\u002Frecipes\u002Fnitro-database","2.recipes\u002F5.nitro-database",{"title":176,"icon":177,"path":178,"stem":179,"children":180,"page":45},"Reference","i-lucide-code-xml","\u002Freference","3.reference",[181,185,189,193,198,203],{"title":182,"path":183,"stem":184,"icon":34},"Config files","\u002Freference\u002Fconfig-files","3.reference\u002F1.config-files",{"title":186,"path":187,"stem":188,"icon":39},"Module options","\u002Freference\u002Fmodule-options","3.reference\u002F2.module-options",{"title":190,"path":191,"stem":192,"icon":67},"Socket options","\u002Freference\u002Fsocket-options","3.reference\u002F3.socket-options",{"title":194,"path":195,"stem":196,"icon":197},"Exports","\u002Freference\u002Fexports","3.reference\u002F4.exports","i-lucide-boxes",{"title":199,"path":200,"stem":201,"icon":202},"Hooks","\u002Freference\u002Fhooks","3.reference\u002F5.hooks","i-lucide-anchor",{"title":204,"path":205,"stem":206,"icon":207},"Environment","\u002Freference\u002Fenvironment","3.reference\u002F6.environment","i-lucide-variable",{"id":209,"title":41,"body":210,"description":451,"extension":452,"links":453,"meta":454,"navigation":455,"path":72,"seo":456,"stem":73,"__hash__":457},"docs\u002F1.guide\u002F6.socket\u002F3.advanced.md",{"type":211,"value":212,"toc":439},"minimark",[213,222,227,242,259,263,277,283,287,290,331,335,361,368,394,408,412],[214,215,216,217,221],"p",{},"PGlite is a single Postgres backend: one session, one connection's worth of state. The socket lets many clients use it by taking turns, and resets what each client leaves behind. For the usual development workload (an app's pool, a migration tool, ",[218,219,220],"code",{},"psql","), this behaves like a server. The details below matter when something does not.",[223,224,226],"h2",{"id":225},"one-owner-at-a-time","One owner at a time",[214,228,229,230,233,234,237,238,241],{},"A client owns the database for the length of a transaction or pipeline; the others queue until it is done. The process's own ",[218,231,232],{},"db.query()"," \u002F ",[218,235,236],{},"db.transaction()"," calls (a ",[218,239,240],{},"server"," action, the DevTools SQL box) queue the same way, so neither side's statements land inside the other's transaction.",[214,243,244,245,251,252,255,256,258],{},"An owner that stays idle inside a transaction or pipeline for longer than ",[246,247,248],"a",{"href":69},[218,249,250],{},"idleInTransactionTimeout"," is disconnected, which rolls its transaction back and lets the queue move. It is off by default; set it if a crashed tool or a forgotten ",[218,253,254],{},"BEGIN"," in ",[218,257,220],{}," can stall your app.",[223,260,262],{"id":261},"session-state","Session state",[214,264,265,266,269,270,255,273,276],{},"When a client disconnects, what it set up in the session is dropped, as a real server would: its settings, temp tables, advisory locks, prepared statements and ",[218,267,268],{},"LISTEN"," subscriptions. The settings the process set before the socket started (for example a ",[218,271,272],{},"SET search_path",[218,274,275],{},"init",") are kept.",[214,278,279,280,282],{},"Notifications reach the clients that ran ",[218,281,268],{}," on the channel, and no others.",[223,284,286],{"id":285},"known-differences","Known differences",[214,288,289],{},"Inherent to sharing one session:",[291,292,293,304,325,328],"ul",{},[294,295,296,299,300,303],"li",{},[218,297,298],{},"COPY … FROM STDIN"," is refused with SQLSTATE ",[218,301,302],{},"0A000",": PGlite cannot run it.",[294,305,306,233,308,311,312,233,315,233,318,321,322,324],{},[218,307,268],{},[218,309,310],{},"UNLISTEN"," and SQL-level ",[218,313,314],{},"PREPARE",[218,316,317],{},"EXECUTE",[218,319,320],{},"DEALLOCATE"," are recognised as single statements, the way drivers send them. ",[218,323,268],{}," takes effect regardless of the transaction it ran in.",[294,326,327],{},"Temp tables and advisory locks taken by the process itself are released when any client disconnects.",[294,329,330],{},"Connections are not authenticated, and every database name reaches the same database.",[223,332,334],{"id":333},"the-config-file-outside-the-bundle","The config file outside the bundle",[214,336,337,338,341,342,348,349,352,353,356,357,360],{},"The socket imports ",[218,339,340],{},"server\u002Fpglite.config.ts"," in the Nuxt process through ",[246,343,347],{"href":344,"rel":345},"https:\u002F\u002Fgithub.com\u002Funjs\u002Fjiti",[346],"nofollow","jiti",", not through Nuxt's bundler, with the app's aliases: ",[218,350,351],{},"~~",", ",[218,354,355],{},"#pglite\u002Fmigrations"," and the aliases of other modules resolve as they do in the server bundle. ",[218,358,359],{},"definePGliteServerConfig"," is provided as a global while it loads, so a file written for the server works unchanged; other auto-imports are not available there.",[223,362,364,365,367],{"id":363},"when-init-fails","When ",[218,366,275],{}," fails",[214,369,370,371,373,374,377,378,381,382,385,386,389,390,393],{},"The instance is created, and ",[218,372,275],{}," (migrations, seeding) run, when ",[218,375,376],{},"nuxt dev"," starts. If either fails, the dev server keeps running: the error is logged, the socket listens at its usual URL with its variables exported, and every client is refused with a FATAL ",[218,379,380],{},"57P03"," (",[218,383,384],{},"cannot_connect_now",") error, ",[218,387,388],{},"PGlite is not ready: \u003Cthe error>",", whose hint points at the fix. Your app's routes then fail with that message rather than with a connection error, and the ",[246,391,85],{"href":392},"\u002Fguide\u002Fdevtools#when-init-fails"," shows the reason.",[214,395,396,397,399,400,407],{},"Restart ",[218,398,376],{}," once the cause is fixed (a change to the config file restarts it), or run the ",[246,401,403,406],{"href":402},"\u002Fguide\u002Fdevtools\u002Factions#reset-database",[218,404,405],{},"reset-database"," action"," to start from an empty database.",[223,409,411],{"id":410},"bun-and-deno","Bun and Deno",[214,413,414,415,352,418,421,422,424,425,428,429,431,432,435,436,438],{},"The socket uses only Node built-ins (",[218,416,417],{},"node:net",[218,419,420],{},"node:fs","), so it runs wherever ",[218,423,376],{}," does, including Bun and Deno. It has been tested with ",[218,426,427],{},"pg",", postgres.js, ",[218,430,220],{}," and ",[218,433,434],{},"drizzle-kit push"," on all three. To serve PGlite without Nuxt, see ",[246,437,160],{"href":169},".",{"title":440,"searchDepth":441,"depth":442,"links":443},"",1,2,[444,445,446,447,448,450],{"id":225,"depth":442,"text":226},{"id":261,"depth":442,"text":262},{"id":285,"depth":442,"text":286},{"id":333,"depth":442,"text":334},{"id":363,"depth":442,"text":449},"When init fails",{"id":410,"depth":442,"text":411},"How many clients share one PGlite session, and where that differs from a real server.","md",null,{},{"icon":44},{"title":41,"description":451},"OhaV3xCOWhzQOo9umA3V3tmyxqJkXRvNTtrDlGFX3Rg",[459,461],{"title":36,"path":69,"stem":70,"description":460,"icon":39,"children":-1},"Where the socket listens, how it publishes its URL and how it treats clients.",{"title":75,"path":76,"stem":77,"description":462,"icon":78,"children":-1},"Develop against PGlite with nothing to install, deploy against any Postgres, with the same code and no PGlite in the build.",1791474260718]