PostgreSQL

Backup

Backup a plain sql script:


./pg_dump.exe --host thehost-server.postgres.database.azure.com --username theusername --exclude-table-data 'public.tableprefix1*' --exclude-table-data 'public.tableprefix2*' --file C:\thepath\backup.sql thedatabasename

Backup a custom-format sql script:


./pg_dump.exe --host thehost-server.postgres.database.azure.com --username theusername --format custom --exclude-table-data 'public.tableprefix1*' --exclude-table-data 'public.tableprefix2*' --file C:\thepath\backup.dump thedatabasename

Restore

Restore a plain sql script (database should be newly created):


./psql --host thehost-server.postgres.database.azure.com --username theusername -d thedatabasename -f C:\thepath\backup.sql

Restore a custom-format sql script (data-only for a specific table):


./pg_restore --host thehost-server.postgres.database.azure.com --username theusername --data-only -d thedatabasename -t thetabletorestore C:\thepath\backup.dump

Identity Sequences

Reset the sequence to the next value after the maximum ID in the table


SELECT setval((select pg_get_serial_sequence('footnote', 'Id')), (SELECT MAX("Id") + 1 FROM footnote));