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:
-N max-connections
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.
With 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.
Related:
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.
service
orsystemctl
are essentially wrappers around a shell script (e.g./etc/init.d/postgresql-9.6
) Although I don't know if that shell script gets overwritten if you install any updates using the repository manager (apt-get
,yum
) - I am not a Linux guy – a_horse_with_no_name Jun 20 '17 at 8:11pg_postmaster_start_time
stores the servers last start time if you find that useful. you could perhaps store it in aCOMMENT
on the table (table meta-data). – Evan Carroll Jun 20 '17 at 16:07