postgreSQL 如果没有正常关闭数据库且丢失了xlog 或者说wal日志文件的话 会导致启动时出现上述错误,对于pg而言可以通过pg_resetxlog或pg_resetwal(pg 10以后)来绕过该问题,即跳过这些日志。不像在oracle中,如果是没有clean close database且丢失了acitve或current的重做日志的话,会导致oracle数据库也无法打开,且强制开库的话步骤十分复杂,要比pg困难很多。
PG中可以执行如下命令来重置日志,但是注意做这些操作之前应该对$PGDATA目录做一个tarbar备份:
2019-11-19 06:37:09.459 UTC [2705] FATAL: terminating autovacuum process due to administrator command 2019-11-19 06:38:35.142 UTC [2791] LOG: listening on IPv6 address "::1", port 5432 2019-11-19 06:38:35.142 UTC [2791] LOG: listening on IPv4 address "127.0.0.1", port 5432 2019-11-19 06:38:35.143 UTC [2791] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2019-11-19 06:38:35.162 UTC [2792] LOG: database system was interrupted; last known up at 2019-11-19 06:36:47 UTC 2019-11-19 06:38:35.162 UTC [2792] LOG: creating missing WAL directory "pg_wal/archive_status" 2019-11-19 06:38:35.209 UTC [2792] LOG: invalid primary checkpoint record 2019-11-19 06:38:35.210 UTC [2792] LOG: invalid secondary checkpoint record 2019-11-19 06:38:35.210 UTC [2792] PANIC: could not locate a valid checkpoint record 2019-11-19 06:38:37.204 UTC [2791] LOG: startup process (PID 2792) was terminated by signal 6: Aborted 2019-11-19 06:38:37.206 UTC [2791] LOG: aborting startup due to startup process failure 2019-11-19 06:38:37.222 UTC [2791] LOG: database system is shut down pg_ctl: could not start server Examine the log output. tar -jcvf pgdata.tar.bz2 $PGDATA # Postgres < 10.0 pg_resetxlog -f $PGDATA # Postgres >= 10.0 pg_resetwal -f $PGDATA
Leave a Reply