Skip to content

Instantly share code, notes, and snippets.

@yogithesymbian
Created October 20, 2025 03:07
Show Gist options
  • Select an option

  • Save yogithesymbian/3e4a0d2628a9f0c2e0a07850b7c4b572 to your computer and use it in GitHub Desktop.

Select an option

Save yogithesymbian/3e4a0d2628a9f0c2e0a07850b7c4b572 to your computer and use it in GitHub Desktop.
Menghindari bottleneck dari ribuan koneksi langsung ke Postgres.
[databases]
explorer = host=localhost port=5432 dbname=explorer
[pgbouncer]
listen_port = 6432
listen_addr = 0.0.0.0
auth_type = md5
pool_mode = transaction
max_client_conn = 1000
default_pool_size = 100
@yogithesymbian
Copy link
Author

yogithesymbian commented Oct 20, 2025

change connection into

const client = drizzle({
  connectionString: "postgres://user:pass@localhost:6432/explorer"
});

instead of

import 'dotenv/config';
import { drizzle } from 'drizzle-orm/bun-sql';
import { SQL } from 'bun';

const client = new SQL(process.env.DATABASE_URL!);
export const db = drizzle({ client });

test

psql -h localhost -p 6432 -U user explorer

@yogithesymbian
Copy link
Author

before

import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
});

export const db = drizzle(pool);

after

import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';

const pool = new Pool({
  connectionString: process.env.DATABASE_URL ?? 'postgres://user:pass@localhost:6432/explorer',
  // Optional: tambahkan idleTimeoutMillis, max, dll
});

export const db = drizzle(pool);

@yogithesymbian
Copy link
Author

localhost:5432

@yogithesymbian
Copy link
Author

localhost:6432

@yogithesymbian
Copy link
Author

jalankan salah satu query / migrate

bun run migrate

monitoring koneksi di PgBouncer:

SHOW POOLS;
SHOW STATS;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment