The simple way to ensure no other connections would be to start the server in single-user mode. Run your commands, then terminate the session with Control+D (typically) and restart the server in your standard operation mode. You can wrap all of this into a shell script to replace plain server start ...
Consider instructions in the manual.
Or you could start the server with
-N 1. The manual:
Sets the maximum number of client connections that this server will accept. The default value of this parameter is chosen automatically by initdb. Specifying this option is equivalent to setting the
max_connections configuration parameter.
superuser_reserved_connections at least
1 (default is
3), only a superuser can connect. You still need to restart the server (without this setting) when done because, the manual again:
This parameter can only be set at server start.
Aside: while a temp table seems to be no option for you, an
UNLOGGED table might be. Visible to all sessions, but faster than a plain table. Since you truncate the table at server start anyway, the risk of data loss after a server crash seems irrelevant to the use case.