I am finding it difficult to find the best way to set Postgres options for a pg_restore session only. It would be nice to be able to do this in the environment in which I run pg_restore and not change global sessions or have to initiate an interactive psql session. E.g. I would like to set these values during the restore only.
work_mem = 32MB
shared_buffers = 4GB
maintenance_work_mem = 2GB
full_page_writes = off
autovacuum = off
wal_buffers = -1
I did try using export PGOPTIONS
for the values, but I am not sure it actually worked or whether the format for setting them was correct, e.g. export PGOPTIONS='-c work_mem=32MB -c shared_buffers=4GB'
etc.
2
Answers
Most of the parameters you want to set don’t make any sense. Here is my recommendation:
increase
max_wal_size
a lotincrease
maintenance_work_mem
a lotset
wal_level = minimal
and use--single-transaction
withpg_restore
, so that PostgreSQL can skip writing WALThe first two options can be set via
PGOPTIONS
like you show in your question, the third requires changing parameters in the configuration file or on the server command line and a restart.To see if
PGOPTIONS
works, tryIf you can restart Postgresql (I didn’t see you mention one way or another), you can pass ad hoc parameters there.
For example:
Then do the
pg_restore
,vacuumdb --analyze-only
and lastlypg_ctl stop -wt9999 -mfast && pg_ctl start -wt9999
.(The explicit stop/start are required because
pg_ctl restart
retains the passed parameters, while stop/start wipes them out.)