0

If a single application thread sends a series of INSERT statements and autocommit=true, will the statements be executed synchronously on the server?

I read that on the postgres server side, "there is one client process connected to exactly one server process", but haven't found much more beyond that. I need synchronous execution to satisfy foreign key relationships, but I suspect the server (9.6) may run the statements concurrently.

  • A single connection can never run more than one statement at a time, regardless of the autocommit setting – a_horse_with_no_name Jan 11 at 6:47
0

With autocommit enabled each statement forms a separate transaction. In a single session (connection) only one transaction can be active at a time. However, transactions in multiple concurrent sessions can, and will run simultaneously. In other words, as long as you issue your insert statements using the same database connection they will execute serially.

Whether you do that in a single application thread or not is irrelevant, since it's possible to open multiple database connections in a single thread, as it is possible to reuse the same connection between multiple threads (with proper synchronization, of course).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.