im trying to inserting hundred / thousand data based on selected data from others table, but i found an error "too many clients", here is the error
Im using pgp (pg promise) lib, here is my snippet
function call(){
for (let index = 0; index < 5; index++) {
getPendingData().then((result) => {
db.tx((t) => {
let counter = 0;
const queries = result.map((data) => {
counter++;
return db.none(`insert into test_data (id, isdeleted, parentid) values ('${uuidv1()}', 0, '${uuidv1()}x-${uuidv1()}' ) `);
});
return t.batch(queries);
});
});
}
}
let getPendingData = async () => {
return db.task('getPendingData', async (t) => {
return await t.any('select * from other_table');
});
}
(call())
im setup max pg conn is 100, any clue how to solved this without add max conn?