In your situation I might keep the counter in another table of the same database. Make a Config table, and in one column of one row, keep your counter. <pre>UPDATE Config SET counter TO counter + 5 WHERE configItem='customers' RETURNING counter</pre> This does the update in one operation and returns a value which lets you figure out the ids for the 5 rows you want to insert. it is ACID, and threadsaf, given that you are correctly using separate connections.