如何在NixOS中升级postgresql?

时间:2018-08-04 17:48:50

标签: postgresql nixos

我正在尝试将NixOS计算机上的Postgresql服务器从9.4更新到(至少)9.6。

我在services.postgres.package中编辑了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 section,但是“ Upgradeing”小节尚未填写。关于如何解决此错误并升级PostgreSQL的任何想法?

1 个答案:

答案 0 :(得分:1)

我通过创建所有服务器数据库的转储,修改旧的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 manual做贡献吗? 我很高兴使用在这里学到的知识来撰写updating postgres section