Skip to content

Commit d26e658

Browse files
copiltembeltudor
and
tudor
authored
Run DEALLOCATE ALL; after pg_dump (#563)
* run DEALLOCATE ALL after pgdump --------- Co-authored-by: tudor <tudor@swisstch.com>
1 parent 8545760 commit d26e658

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

.changeset/moody-knives-allow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@electric-sql/pglite-tools': patch
3+
---
4+
5+
Run a DEALLOCATE ALL after each pg_dump to cleanup the prepared statements.

packages/pglite-tools/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ npm install @electric-sql/pglite-tools
1212

1313
pg_dump is a tool for dumping a PGlite database to a SQL file, this is a WASM build of pg_dump that can be used in a browser or other JavaScript environments. You can read more about pg_dump [in the Postgres docs](https://www.postgresql.org/docs/current/app-pgdump.html).
1414

15+
Note: pg_dump will execute `DEALLOCATE ALL;` after each dump. Since this is running on the same (single) connection, any prepared statements that you have made before running pg_dump will be affected.
16+
1517
### Options
1618

1719
- `pg`: A PGlite instance.

packages/pglite-tools/src/pg_dump.ts

+2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ export async function pgDump({
182182
args: [...(args ?? []), ...baseArgs],
183183
})
184184

185+
pg.query(`DEALLOCATE ALL;`)
186+
185187
if (exitCode !== 0) {
186188
throw new Error(
187189
`pg_dump failed with exit code ${exitCode}. \nError message: ${errorMessage}`,

packages/pglite-tools/tests/pg_dump.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ describe('pgDump', () => {
1414
expect(content).toContain('PostgreSQL database dump')
1515
})
1616

17+
it('should dump an empty database multiple times', async () => {
18+
const pg = await PGlite.create()
19+
20+
for (let i = 0; i < 5; i++) {
21+
const fileName = `dump_${i}.sql`
22+
const dump = await pgDump({ pg, fileName })
23+
24+
expect(dump).toBeInstanceOf(File)
25+
expect(dump.name).toBe(fileName)
26+
27+
const content = await dump.text()
28+
expect(content).toContain('PostgreSQL database dump')
29+
}
30+
})
31+
1732
it('should dump a database with tables and data', async () => {
1833
const pg = await PGlite.create()
1934

0 commit comments

Comments
 (0)