Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: brianc/node-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: pg@8.14.0
Choose a base ref
...
head repository: brianc/node-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 477f812984a9d75346e8ec37eefa3f79a117d581
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 17, 2025

  1. Batch network packets in prepared statements (#3402)

    * Batch network packets in prepared statements
    
    Fixes #3340
    Fixes #3325
    Fixes #3098
    
    * Fix type-o but mostly retrigger build for CF pages preview
    brianc authored Mar 17, 2025
    Copy the full SHA
    c53a472 View commit details
  2. Publish

     - pg-cursor@2.13.1
     - pg-query-stream@4.8.1
     - pg@8.14.1
    brianc committed Mar 17, 2025
    Copy the full SHA
    477f812 View commit details
Showing with 32 additions and 12 deletions.
  1. +2 −2 packages/pg-cursor/package.json
  2. +3 −3 packages/pg-query-stream/package.json
  3. +11 −5 packages/pg/bench.js
  4. +15 −1 packages/pg/lib/query.js
  5. +1 −1 packages/pg/package.json
4 changes: 2 additions & 2 deletions packages/pg-cursor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-cursor",
"version": "2.13.0",
"version": "2.13.1",
"description": "Query cursor extension for node-postgres",
"main": "index.js",
"directories": {
@@ -18,7 +18,7 @@
"license": "MIT",
"devDependencies": {
"mocha": "^10.5.2",
"pg": "^8.14.0"
"pg": "^8.14.1"
},
"peerDependencies": {
"pg": "^8"
6 changes: 3 additions & 3 deletions packages/pg-query-stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-query-stream",
"version": "4.8.0",
"version": "4.8.1",
"description": "Postgres query result returned as readable stream",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
@@ -37,7 +37,7 @@
"concat-stream": "~1.0.1",
"eslint-plugin-promise": "^6.0.1",
"mocha": "^10.5.2",
"pg": "^8.14.0",
"pg": "^8.14.1",
"stream-spec": "~0.3.5",
"ts-node": "^8.5.4",
"typescript": "^4.0.3"
@@ -46,6 +46,6 @@
"pg": "^8"
},
"dependencies": {
"pg-cursor": "^2.13.0"
"pg-cursor": "^2.13.1"
}
}
16 changes: 11 additions & 5 deletions packages/pg/bench.js
Original file line number Diff line number Diff line change
@@ -47,21 +47,27 @@ const run = async () => {
for (let i = 0; i < 4; i++) {
let queries = await bench(client, params, seconds * 1000)
console.log('')
console.log('little queries:', queries)
console.log('param queries:', queries)
console.log('qps', queries / seconds)
console.log('on my laptop best so far seen 733 qps')
console.log('on my laptop best so far seen 987 qps')

queries = await bench(client, { ...params, name: 'params' }, seconds * 1000)
console.log('')
console.log('named queries:', queries)
console.log('qps', queries / seconds)
console.log('on my laptop best so far seen 937 qps')

console.log('')
queries = await bench(client, seq, seconds * 1000)
console.log('sequence queries:', queries)
console.log('qps', queries / seconds)
console.log('on my laptop best so far seen 1309 qps')
console.log('on my laptop best so far seen 2725 qps')

console.log('')
queries = await bench(client, insert, seconds * 1000)
console.log('insert queries:', queries)
console.log('qps', queries / seconds)
console.log('on my laptop best so far seen 6445 qps')
console.log('on my laptop best so far seen 27383 qps')

console.log('')
console.log('Warming up bytea test')
@@ -75,7 +81,7 @@ const run = async () => {
const time = Date.now() - start
console.log('bytea time:', time, 'ms')
console.log('bytea length:', results.rows[0].data.byteLength, 'bytes')
console.log('on my laptop best so far seen 1107ms and 104857600 bytes')
console.log('on my laptop best so far seen 1407ms and 104857600 bytes')
await new Promise((resolve) => setTimeout(resolve, 250))
}

16 changes: 15 additions & 1 deletion packages/pg/lib/query.js
Original file line number Diff line number Diff line change
@@ -161,7 +161,21 @@ class Query extends EventEmitter {
return new Error('Query values must be an array')
}
if (this.requiresPreparation()) {
this.prepare(connection)
// If we're using the extended query protocol we fire off several separate commands
// to the backend. On some versions of node & some operating system versions
// the network stack writes each message separately instead of buffering them together
// causing the client & network to send more slowly. Corking & uncorking the stream
// allows node to buffer up the messages internally before sending them all off at once.
// note: we're checking for existence of cork/uncork because some versions of streams
// might not have this (cloudflare?)
connection.stream.cork && connection.stream.cork()
try {
this.prepare(connection)
} finally {
// while unlikely for this.prepare to throw, if it does & we don't uncork this stream
// this client becomes unresponsive, so put in finally block "just in case"
connection.stream.uncork && connection.stream.uncork()
}
} else {
connection.query(this.text)
}
2 changes: 1 addition & 1 deletion packages/pg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg",
"version": "8.14.0",
"version": "8.14.1",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"database",