Question

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.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top