求助,升级了一下两年没升级的 archlinux, postgresql 挂了。。

2017-04-14 01:43:13 +08:00
 fl2d
以前没咋用过 linux 。最近用一个两年没 syu 的 archlinux 服务器,装啥都出奇怪的问题,但也不敢升级,上面跑着好多东西呢,怕出问题。刚才实在忍不了了,战战兢兢的 pacman -syu 了,结果,当真, owncloud 挂了,分析是由于 postgresql 挂了引起的。求助,哪位能指点一下么。。

还有,如果删除再重装 pgsql 的话,原来的数据库咋保留?网上查的都是在服务运行的状态下 dump ,再升到高版本的 reload ,可我已经升级了,并且服务也不启动了。


# systemctl start postgresql

Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xe" for details.



# systemctl status postgresql.service

postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-04-14 02:09:00 ; 7min ago
Process: 26394 ExecStop=/usr/bin/pg_ctl -s -D ${PGROOT}/data stop -m fast (code=exited, status=0/SUCCESS)
Process: 5814 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=1/FAILURE)
Main PID: 17344 (code=exited, status=0/SUCCESS)

Apr 14 02:09:00 xxx.xxx systemd[1]: Starting PostgreSQL database server...
Apr 14 02:09:00 xxx.xxx postgres[5814]: An old version of the database format was found.
Apr 14 02:09:00 xxx.xxx postgres[5814]: You need to dump and reload before using PostgreSQL 9.6.
Apr 14 02:09:00 xxx.xxx postgres[5814]: See http://www.postgresql.org/docs/9.6/static/upgrading.html
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Control process exited, code=exited status=1
Apr 14 02:09:00 xxx.xxx systemd[1]: Failed to start PostgreSQL database server.
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Unit entered failed state.
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Failed with result 'exit-code'.



# journalctl -xe

Unit postgresql.service has begun starting up.
Apr 14 02:09:00 xxx.xxx postgres[5814]: An old version of the database format was found.
Apr 14 02:09:00 xxx.xxx postgres[5814]: You need to dump and reload before using PostgreSQL 9.6.
Apr 14 02:09:00 xxx.xxx postgres[5814]: See http://www.postgresql.org/docs/9.6/static/upgrading.html
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Control process exited, code=exited status=1
Apr 14 02:09:00 xxx.xxx systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit postgresql.service has failed.
--
-- The result is failed.
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Unit entered failed state.
Apr 14 02:09:00 xxx.xxx systemd[1]: postgresql.service: Failed with result 'exit-code'.
4941 次点击
所在节点    问与答
41 条回复
cnnblike
2017-04-14 02:20:23 +08:00
You need to dump and reload before using PostgreSQL 9.6.
fl2d
2017-04-14 02:36:35 +08:00
@cnnblike
为了让 pgsql 启动,我需要 dump ;为了 dump ,需要启动 pgsql 。死循环了啊。。

# pg_dumpall > ./backdir/pgsql.old
pg_dumpall: could not connect to database "template1": could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/run/postgresql/.s.PGSQL.5432"?
sagaxu
2017-04-14 06:00:20 +08:00
升级 pgsql 前没读 release notes 么,跨度比较大的版本之间,二进制 db 文件是不兼容的,要用老版本 pgsql 启动 dump 出兼容性高的导出格式,然后导入到新版本 pgsql
fl2d
2017-04-14 08:16:49 +08:00
@sagaxu
没看 T T 。。 直接更新所有了。。我现在已经把 pgsql 升级了,还有办法 dump 以前的数据库不?
t123yh
2017-04-14 08:44:13 +08:00
@fl2d 可以的,删掉 pgsql ,手动装老版本就可以了,最好把数据库文件手动复制出来备份一下。
kemad
2017-04-14 09:16:16 +08:00
binjoo
2017-04-14 09:18:13 +08:00
生产上的版本更新难道不应该很慎重吗?
ChasYuan
2017-04-14 09:19:39 +08:00
两年没升级都敢这么玩。心疼~
fl2d
2017-04-14 09:24:43 +08:00
@t123yh
把 /var/lib/postgres/data 考出来, 然后删了现在的 pgsql ,然后再装老版本,再把 data 文件夹拷回去,是吧?
多谢!我试试!
重新装了老版本后,还需要 import 老数据库之类的不?
murusu
2017-04-14 09:25:57 +08:00
@fl2d 文档不是说了可以用 pg_upgrade 来离线升级数据库吗?试过还是不行?
fl2d
2017-04-14 09:28:08 +08:00
@binjoo
@ChasYuan 不升级实在没法儿用了,加上我又掉以轻心了。。。。。都是泪。。。。
noqwerty
2017-04-14 09:29:36 +08:00
感觉到了 docker 的重要性
klesh
2017-04-14 10:15:26 +08:00
我记得是有个升级的工具的 pg 会带,就是 10 楼说的。你查下文档
klesh
2017-04-14 10:16:03 +08:00
另生产环境用 arch 有点不太妥当吧
msg7086
2017-04-14 11:03:47 +08:00
我给你的建议,去 Linode/DO/Vultr 任何一个能按小时算钱的地方。
开一台新机器,装一个 Debian 老版本系统,找版本对应的,数据复制进去, dump 出来。
再开一台新机器,装一个 Debian 最新版的系统,数据 dump 回去,然后检查数据完整性。
一切都 OK 的话,再删掉原机器上的库。

永远不要在没有验证新数据的情况下删除旧数据。
msg7086
2017-04-14 11:05:03 +08:00
另外 Arch 天生就是必须要经常滚的,你两年不滚的话妥妥要出事啊。
不滚的话, CentOS / Debian 系都是很好的。
fl2d
2017-04-14 12:00:11 +08:00
@t123yh
我发现我不知道以前老版本是啥啊。。而且,我看文档说,大版本才有不兼容的问题,小版本问题不大啊, 2 年前也是 9.4 9.5 了,现在 9.6 。我 pacman -Rns postgresql 然后再用 pacman -S postgresql 装了几遍,还不行。。

@murusu
@klesh
有点奇怪,按照 pg_upgrade 文档说明,数据目录下面应该有老版本和新版本两个目录,类似于
/var/lib/postgres/8.4/data
/var/lib/postgres/9.6/data
可是我的数据目录只有一个 /var/lib/postgres/data 。。
根据我贴出来的 systemctl status postgresql.service 的输出结果,能确认是久数据库造成的无法启动么?
或者那其实只是个 warning 而不是 error ?


@msg7086
这个服务器以前不是我玩儿的。我有升级强迫症,要换我,肯定整天 syu 。。
fl2d
2017-04-14 12:24:51 +08:00
@t123yh
@murusu
@klesh
@msg7086

额。。发现了。。源代码里显示完提示就 exit 了。。确实是由于老版本数据格式造成的。。
可是我咋升级啊?服务不能启动, dump 不能用。 pg_upgrade 也完全和文档里对不上啊。。。

还有,请问,怎能确定我之前的版本号啊?
我下到我的 mac 里,装老版本 pgsql , dump 一下,再恢复会去,可以不?



# Check version of existing PGDATA
+ if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
+ then
+ : A-OK
+ elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
+ then
+ echo $"An old version of the database format was found."
+ echo $"See https://wiki.archlinux.org/index.php/PostgreSQL#Upgrading_PostgreSQL"
+ exit 1
+ else
+ echo $"An old version of the database format was found."
+ echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
+ echo $"See http://www.postgresql.org/docs/$PGMAJORVERSION/static/upgrading.html"
+ exit 1
+ fi
ho121
2017-04-14 12:31:43 +08:00
看看 pacman 的 cache 里有没有老版本的包
jhaohai
2017-04-14 13:10:47 +08:00
arch 两年动过居然没升死?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/354746

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX