2.删除 important_table 表
cost=# begin;
BEGIN
cost=*# drop table important_table;
DROP TABLE
cost=*# commit;
COMMIT
cost=# select * from important_table;
ERROR: relation "important_table" does not exist
LINE 1: select * from important_table;
^
cost=#
3.做一个备份
postgres@pg181:/home$ pgbackrest --stanza=regcost --type=incr backup
2026-01-02 18:38:12.000 P00 WARN: a timeline switch has occurred since the 20260102-172025F backup, enabling delta checksum
HINT: this is normal after restoring from backup or promoting a standby.
4.查看当前备份
postgres@pg181:/home$ pgbackrest --stanza=regcost info
stanza: regcost
status: ok
cipher: none
db (current)
wal archive min/max (18): 000000010000000000000009/00000002000000000000000E
postgres@pg181:/home$ pg_ctl start
waiting for server to start....2026-01-02 18:47:43.439 CST [13770] LOG: redirecting log output to logging collector process
2026-01-02 18:47:43.439 CST [13770] HINT: Future log output will appear in directory "pg_log".
stopped waiting
pg_ctl: could not start server
Examine the log output.
查看日志
postgres@pg181:/home$ tail -20 /pg18/data/pg_log/postgresql.log
2026-01-02 18:47:43.439 CST [13770] LOG: starting PostgreSQL 18.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 14.3.1 20250617 (Red Hat 14.3.1-2), 64-bit
2026-01-02 18:47:43.440 CST [13770] LOG: listening on IPv4 address "0.0.0.0", port 5432
2026-01-02 18:47:43.440 CST [13770] LOG: listening on IPv6 address "::", port 5432
2026-01-02 18:47:43.442 CST [13770] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2026-01-02 18:47:43.446 CST [13777] LOG: database system was interrupted; last known up at 2026-01-02 18:38:10 CST
2026-01-02 18:47:43.459 CST [13777] LOG: starting backup recovery with redo LSN 0/E000028, checkpoint LSN 0/E000080, on timeline ID 2
2026-01-02 18:47:43.472 CST [13777] LOG: restored log file "00000002.history" from archive
2026-01-02 18:47:43.499 CST [13777] LOG: restored log file "00000002000000000000000E" from archive
2026-01-02 18:47:43.514 CST [13777] LOG: starting point-in-time recovery to 2026-01-02 18:29:59.769442+08
2026-01-02 18:47:43.515 CST [13777] LOG: redo starts at 0/E000028
2026-01-02 18:47:43.541 CST [13777] LOG: restored log file "00000002000000000000000F" from archive
2026-01-02 18:47:43.569 CST [13777] LOG: completed backup recovery with redo LSN 0/E000028 and end LSN 0/E000158
2026-01-02 18:47:43.569 CST [13777] LOG: consistent recovery state reached at 0/E000158
2026-01-02 18:47:43.569 CST [13770] LOG: database system is ready to accept read-only connections
2026-01-02 18:47:43.582 CST [13777] LOG: redo done at 0/F000060 system usage: CPU: user: 0.00 s, system: 0.01 s, elapsed: 0.06 s
2026-01-02 18:47:43.582 CST [13777] FATAL: recovery ended before configured recovery target was reached
2026-01-02 18:47:43.583 CST [13770] LOG: startup process (PID 13777) exited with exit code 1
2026-01-02 18:47:43.583 CST [13770] LOG: terminating any other active server processes
2026-01-02 18:47:43.584 CST [13770] LOG: shutting down due to startup process failure
2026-01-02 18:47:43.586 CST [13770] LOG: database system is shut down
postgres@pg181:/pg18/data$ pg_ctl start
waiting for server to start....2026-01-02 18:59:44.985 CST [14799] LOG: redirecting log output to logging collector process
2026-01-02 18:59:44.985 CST [14799] HINT: Future log output will appear in directory "pg_log".
done
server started
查看日志
postgres@pg181:/pg18/data$ tail -20 /pg18/data/pg_log/postgresql.log
2026-01-02 18:59:45.070 CST [14806] LOG: restored log file "00000001000000000000000B" from archive
2026-01-02 18:59:45.084 CST [14806] LOG: starting point-in-time recovery to 2026-01-02 18:29:59.769442+08
2026-01-02 18:59:45.085 CST [14806] LOG: redo starts at 0/B000028
2026-01-02 18:59:45.113 CST [14806] LOG: restored log file "00000001000000000000000C" from archive
2026-01-02 18:59:45.128 CST [14806] LOG: completed backup recovery with redo LSN 0/B000028 and end LSN 0/B000158
2026-01-02 18:59:45.128 CST [14806] LOG: consistent recovery state reached at 0/B000158
2026-01-02 18:59:45.128 CST [14799] LOG: database system is ready to accept read-only connections
2026-01-02 18:59:45.177 CST [14806] LOG: restored log file "00000002000000000000000D" from archive
2026-01-02 18:59:45.221 CST [14806] LOG: restored log file "00000002000000000000000E" from archive
2026-01-02 18:59:45.280 CST [14806] LOG: restored log file "00000002000000000000000F" from archive
2026-01-02 18:59:45.309 CST [14806] LOG: recovery stopping before commit of transaction 768, time 2026-01-02 18:32:02.347646+08
2026-01-02 18:59:45.309 CST [14806] LOG: redo done at 0/D021600 system usage: CPU: user: 0.00 s, system: 0.07 s, elapsed: 0.22 s
2026-01-02 18:59:45.309 CST [14806] LOG: last completed transaction was at log time 2026-01-02 18:29:06.511318+08
2026-01-02 18:59:45.378 CST [14806] LOG: restored log file "00000002000000000000000D" from archive
2026-01-02 18:59:45.409 CST [14806] LOG: selected new timeline ID: 3
2026-01-02 18:59:45.452 CST [14806] LOG: restored log file "00000002.history" from archive
2026-01-02 18:59:45.453 CST [14806] LOG: archive recovery complete
2026-01-02 18:59:45.454 CST [14804] LOG: checkpoint starting: end-of-recovery immediate wait
2026-01-02 18:59:45.503 CST [14804] LOG: checkpoint complete: wrote 985 buffers (6.0%), wrote 3 SLRU buffers; 0 WAL file(s) added, 0 removed, 2 recycled; write=0.044 s, sync=0.003 s, total=0.049 s; sync files=307, longest=0.001 s, average=0.001 s; distance=32901 kB, estimate=32901 kB; lsn=0/D021600, redo lsn=0/D021600
2026-01-02 18:59:45.505 CST [14799] LOG: database system is ready to accept connections
查看数据
psql
postgres@pg181:/pg18/data$ psql
psql (18.1)
Type "help" for help.
postgres=# \c cost
You are now connected to database "cost" as user "postgres".
cost=# select * from important_table ;
message
----------------
Important Data
(1 row)