代码之家  ›  专栏  ›  技术社区  ›  mherzl

如何在NixOS中升级postgresql?

  •  1
  • mherzl  · 技术社区  · 8 年前

    我正试图在我的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 ,但“升级”部分尚未填写。关于如何解决这个错误并升级PostgreSQL有什么想法吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   mherzl    8 年前

    我通过创建所有服务器数据库的转储,清除旧数据目录并卸载旧版本,安装新版本,然后从转储还原来解决此问题。 下面将详细描述这些步骤。


    创建所有服务器数据库的转储。

    $ 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
    

    这显然是版本10.4的表达式,根据 $ nix-env -qaP '*' --description .

    下一个重击 数据目录 对于当前版本。

    $ sudo rm -rf /var/db/postgresql/
    

    并切换到中标记的新版本 configuration.nix

    $ sudo nixos-rebuild switch
    

    我必须创造一个 root 分贝。

    $ sudo createdb root
    

    (我还不得不改变一些 postgres 在我的 sql-dump 文件。)

    将数据还原到新版本中。

    $ psql -U root -f sql-dump
    

    任何人都知道如何为 nixos manual ? 我很高兴用我在这里学到的东西来写 updating postgres section .

    推荐文章