Search code examples
postgresqlnsis

NSIS running pg_restore or psql commands - failing to restore DB properly


In an NSIS installer, I use the following line to restore a PostgreSQL database from a file packaged with the installer.

ExecWait '$pg_restore_path --host 127.0.0.1 --no-password --port 5432 --username "postgres" --dbname "myDatabase" --verbose $EXEDIR/myDatabase.backup' $0

The command works but pg_restore seems to incorrectly set certain postgres sequences' current values (the current values either get reset to 1 or a number lower than that of the source) resulting in collisions. It seems to be a native bug with postgres but really not sure.

I have also tried replacing pg_restore with psql like this:

ExecWait '$psql_path -f "$EXEDIR/myDatabase.sql" myDatabase'

Which does not work; the terminal pops open and closes. Or like this:

ExecWait '$psql_path myDatabase < $EXEDIR/myDatabase.sql'

Which causes the error psql: warning: extra command-line argument "<" ignored

When I run the psql command manually from the command line it works like a charm, and sequences set properly. So my question is how to get the psql command working in NSIS with the file feeded < and avoiding the error. Failing that, any insight on using pg_restore differently that could work around the sequence issue?

Thanks


Solution

  • The following NSIS commands seem to have solved it.

    ExecWait '$createdb_path -h "127.0.0.1" -p "5432" -U "postgres" -T "template1" --owner "user_owner" myDatabase'
    ExecWait '$psql_path -f "$INSTDIR/myDatabase.sql" myDatabase user_owner'