Sfoglia il codice sorgente

:bug: fix pg dump & restore

Jeremy Zheng 3 anni fa
parent
commit
e57c44395c

+ 5 - 3
documents/PostgreSQL.md

@@ -9,12 +9,14 @@
 - 导出数据库
 
   ```bash
-  pg_dump -Z 9 -h 127.0.0.1 -p 5432 -U www demo > $HOME/tmp/demo-20221009.sql.gz
+  pg_dump -O -s -h 127.0.0.1 -p 5432 -U www demo > $HOME/tmp/demo-schema-20221009.sql
+  pg_dump -Fc -O -a -h 127.0.0.1 -p 5432 -U www demo | gzip -9 > $HOME/tmp/demo-data-20221009.dump.gz
   ```
 
 - 导入数据库
 
   ```bash
-  gunzip demo-20221009.sql.gz
-  psql -h 127.0.0.1 -p 5432 -U www demo < demo-20221009.sql
+  psql -h 127.0.0.1 -p 5432 -U www demo < demo-schema-20221009.sql
+  gunzip demo-20221009.dump.gz
+  pg_restore -Fc -h 127.0.0.1 -p 5432 -U www -d demo < demo-20221009.dump
   ```

+ 0 - 0
scripts/spring/postgresql.sh → scripts/spring/postgresql/create.sh


+ 19 - 0
scripts/spring/postgresql/reset.sh

@@ -0,0 +1,19 @@
+#!/bin/bash
+
+set -e
+
+if [ "$#" -ne 1 ]
+then
+    echo "Usage: $0 USER"
+    exit 1
+fi
+
+psql << EOF
+DROP DATABASE $1_mint;
+CREATE DATABASE $1_mint WITH ENCODING = 'UTF8';
+GRANT ALL PRIVILEGES ON DATABASE $1_mint TO $1;
+EOF
+
+echo "done($1)."
+
+exit 0