我试图在我的NixOS机器上将postgresql服务器从9.4更新到(至少) 9.6。
我在configuration.nix中编辑了configuration.nix以反映此更改,将其更改为:
services.postgresql.package = pkgs.postgresql94至
services.postgresql.package = pkgs.postgresql96但是,这会导致运行nixos-rebuild switch时出现错误,即:
$ sudo nixos-rebuild switch
building Nix...
building the system configuration...
stopping the following units: postgresql.service
NOT restarting the following changed units: display-manager.service
activating the configuration...
setting up /etc...
setting up tmpfiles
reloading the following units: dbus.service
restarting the following units: polkit.service
starting the following units: postgresql.service
Job for postgresql.service failed because the control process exited with error code.
See "systemctl status postgresql.service" and "journalctl -xe" for details.
warning: the following units failed: postgresql.service
● postgresql.service - PostgreSQL Server
Loaded: loaded (/nix/store/bh7vzvacc9y56w0kzs1mwgb1jy9bwvf6-unit-postgresql.service/postgresql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2018-08-04 17:39:33 UTC; 26ms ago
Process: 25399 ExecStartPost=/nix/store/hj8lfb9bbspn76nwm0qmx0xr4466gh0a-unit-script/bin/postgresql-post-start (code=exited, status=1/FAILURE)
Process: 25398 ExecStart=/nix/store/qhdnk3qsw00igzadqfxf7kpp3a48z368-unit-script/bin/postgresql-start (code=exited, status=1/FAILURE)
Process: 25395 ExecStartPre=/nix/store/qg6s6mph3jmrsgr67vh4bsydxrrbmvrr-unit-script/bin/postgresql-pre-start (code=exited, status=0/SUCCESS)
Main PID: 25398 (code=exited, status=1/FAILURE)
Aug 04 17:39:33 nixos systemd[1]: Starting PostgreSQL Server...
Aug 04 17:39:33 nixos systemd[1]: postgresql.service: Main process exited, code=exited, status=1/FAILURE
Aug 04 17:39:33 nixos systemd[1]: postgresql.service: Control process exited, code=exited status=1
Aug 04 17:39:33 nixos systemd[1]: Failed to start PostgreSQL Server.
Aug 04 17:39:33 nixos systemd[1]: postgresql.service: Unit entered failed state.
Aug 04 17:39:33 nixos systemd[1]: postgresql.service: Failed with result 'exit-code'.
warning: error(s) occurred while switching to the new configuration我注意到NixOS手册包含一个PostgreSQL剖面,但是“升级”小节尚未填写。对于如何解决这个错误并升级我的PostgreSQL,有什么想法吗?
发布于 2018-08-16 05:53:25
我通过创建所有服务器数据库的转储、删除旧data_directory和卸载旧版本、安装新版本、然后从转储恢复来解决这个问题。下文对这些步骤作了详细说明。
创建所有服务器数据库的转储。
$ pg_dumpall -U root > sql-dump标识当前版本的data_directory的位置。
root=# SHOW data_directory;
data_directory
--------------------
/var/db/postgresql
(1 row)更改services.postgresql.package在/etc/nixos/configuration.nix中的版本。
services.postgresql.package = pkgs.postgresql100根据$ nix-env -qaP '*' --description的说法,这显然是10.4版的表达式。
接下来,使用当前版本的data_directory。
$ sudo rm -rf /var/db/postgresql/并切换到在configuration.nix中标记的新版本
$ sudo nixos-rebuild switch我必须创建一个root数据库。
$ sudo createdb root(我还必须将postgres的一些实例更改为root文件中的sql-dump文件。)
将数据还原到新版本中。
$ psql -U root -f sql-dump有人知道如何为nixos手册做出贡献吗?我很高兴用我在这里学到的东西来编写更新postgres部分。
https://stackoverflow.com/questions/51688193
复制相似问题