diff --git a/2024/Postgres and ZFS snapshots.md b/2024/Postgres and ZFS snapshots.md index 9e5fb5e..810b77a 100644 --- a/2024/Postgres and ZFS snapshots.md +++ b/2024/Postgres and ZFS snapshots.md @@ -1 +1,21 @@ -https://github.com/jibudata/amberapp/blob/34852920052c58f3d518a28e4d09a50584cf40f8/pkg/postgres/postgres.go \ No newline at end of file +* https://github.com/jibudata/amberapp/blob/34852920052c58f3d518a28e4d09a50584cf40f8/pkg/postgres/postgres.go +* Quiesce & Unquiesce + +```go +func takeSnapshot(db *sql.DB, dataset string, height int, tag string) error { + log.Printf("Taking a ZFS snapshot: %s@%d%s", dataset, height, tag) + log.Printf(" calling pg_backup_start('blkchain', true)") // pg < 15 use pg_start_backup + if _, err := db.Exec(`SELECT pg_backupstart('blkchain', true)`); err != nil { + return err + } + log.Printf(" executing COPY (SELECT) TO PROGRAM 'zfs snapshot %s@%d%s'", dataset, height, tag) + if _, err := db.Exec(fmt.Sprintf(`COPY (SELECT) TO PROGRAM 'zfs snapshot %s@%d%s'`, dataset, height, tag)); err != nil { + return err + } + log.Printf(" calling pg_backup_stop()") // pg < 15 use pg_stop_backup + if _, err := db.Exec(`SELECT pg_backup_stop()`); err != nil { + return err + } + return nil +} +``` \ No newline at end of file