Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-carpets-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@electric-sql/pglite': patch
---

Disable background workers.
5 changes: 5 additions & 0 deletions docs/components/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { PGlite } from '@electric-sql/pglite'
import { vector } from '@electric-sql/pglite/vector'

const pg = new PGlite({
startParams: [
...PGlite.defaultStartParams,
'-c',
'application_name=PGlite REPL',
],
extensions: {
vector,
},
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ Path to the directory for storing the Postgres database. You can provide a URI s
})
```

- `startParams?: string[]` <br />
An array of strings that will be passed to the Postgres process. This is the set of parameters one would pass to a native PostgreSQL instance.

```ts
import { PGlite } from '@electric-sql/pglite'

const pg = await PGlite.create({
startParams: [
...PGlite.defaultStartParams,
'-c',
'application_name=My awesome backend',
],
})
```

#### `options.extensions`

PGlite and Postgres extensions are loaded into a PGLite instance on start, and can include both a WASM build of a Postgres extension and/or a PGlite client plugin.
Expand Down
9 changes: 7 additions & 2 deletions docs/repl/ReplPlayground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ async function loadPg() {
try {
console.log(`Creating PGlite instance with idb://${dbName}`)
return await PGlite.create({
startParams: [
...PGlite.defaultStartParams,
'-c',
'application_name=PGlite REPL Playground',
],
dataDir: `idb://${dbName}`,
extensions,
})
Expand Down Expand Up @@ -93,7 +98,7 @@ async function loadPg() {
}

onMounted(async () => {
pg.value = await loadPg()
doLoadPg()
})

const rootStyle = window.getComputedStyle(document.body)
Expand Down Expand Up @@ -179,7 +184,7 @@ async function clearDb() {
if (closed) break
await new Promise((resolve) => setTimeout(resolve, 10))
}
pg.value = await loadPg()
doLoadPg()
}
</script>

Expand Down
6 changes: 6 additions & 0 deletions packages/pglite/src/pglite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export class PGlite
'exit_on_error=false',
'-c',
'log_checkpoints=false',
'-c',
'max_worker_processes=0',
'-c',
'max_parallel_workers=0',
'-c',
'max_parallel_workers_per_gather=0',
]

/**
Expand Down
40 changes: 40 additions & 0 deletions packages/pglite/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,45 @@ await testEsmCjsAndDTC(async (importType) => {
current_role: 'postgres',
})
})

// this tests the parameter 'max_parallel_workers_per_gather=0',
it('it shouldnt use parallel workers on gather', async () => {
const db = await PGlite.create()

const ROWS = 400_000

await db.exec(`
CREATE TABLE t (id SERIAL PRIMARY KEY, val TEXT);
INSERT INTO t (val)
SELECT md5(i::text) FROM generate_series(1, ${ROWS}) AS i;
`)

// when using workers for GATHER, the query plans contains Gather
const plan = await db.query('EXPLAIN SELECT COUNT(*) FROM t')

const hasGather = plan.rows.some((r: any) =>
r['QUERY PLAN'].includes('Gather'),
)
expect(hasGather).toBeFalsy()

const result = await db.query<any>('SELECT COUNT(*) FROM t')
expect(result.rows[0].count).toEqual(ROWS)
})

it('altering startParams should work"', async () => {
const dateTime = Date.now().toString()
const db = await PGlite.create({
startParams: [
...PGlite.defaultStartParams,
'-c',
`application_name=${dateTime}`,
],
})

const databaseAndRole = await db.exec(
`SELECT setting FROM pg_settings WHERE name='application_name'`,
)
expect(databaseAndRole[0].rows[0].setting).toEqual(dateTime)
})
})
})
Loading