Will query continue to run even after network times-out
If your database connection is terminated without properly closing it (from the server side: if the client just silently dies), and running query will continue until one of these two things happen:


The query produces a result row, the server tries to send it to the client and gets a network error.
The operating system starts sending keepalive packages, because the connection has been idle for a long time (by default, 2 hours). The system will lend a couple of these packages, and when there is no answer, the connection is closed. As soon as PostgreSQL checks for interrupts, the running query should terminate.


You can set the tcp_keepalives_idle parameter to adjust that timeout. This can help the server to detect broken connections more quickly.

When the client is gone, and the query is still running, system resources are used, but there is no danger that this will cause any modifications in the database: eventually the transaction (be it a single statement or a longer transaction) will encounter an error and will be rolled back.