AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 436802
Accepted
icecream_hobbit
icecream_hobbit
Asked: 2018-04-11 07:27:53 +0800 CST2018-04-11 07:27:53 +0800 CST 2018-04-11 07:27:53 +0800 CST

postgresql.service 如何知道要启动哪些 postgresql 实例?

  • 772

我已经在 ubuntu 16.04 上安装了 postgres 9.5,它创建postgresql.service和[email protected].

我知道postgresql.service生成所有启用的 postgres 实例,我可以使用模板文件调用特定实例,[email protected]但[email protected]我看不到实例字符串(由模板中的 %i 或 %I 表示)的任何地方被路过postgresql.service。

如何postgresql.service知道启用了哪些实例,以及如何将它们传递给 systemd 模板文件?

systemd postgresql
  • 2 2 个回答
  • 8492 Views

2 个回答

  • Voted
  1. Best Answer
    Mark Stosberg
    2018-04-11T10:45:55+08:002018-04-11T10:45:55+08:00

    要回答这个问题,首先要检查有问题的两个文件的内容。如果您不确定在哪里可以找到它们,您可以在包内容中搜索systemd文件:

     dpkg -L postgresql-common| grep systemd
    

    通过查看postgresql.service文件,您可以看到您根本没有做太多事情:

    # systemd service for managing all PostgreSQL clusters on the system. This
    # service is actually a systemd target, but we are using a service since
    # targets cannot be reloaded.
    
    [Unit]
    Description=PostgreSQL RDBMS
    
    [Service]
    Type=oneshot
    ExecStart=/bin/true
    ExecReload=/bin/true
    RemainAfterExit=on
    
    [Install]
    WantedBy=multi-user.target
    

    从评论中,我们了解到该文件被用作 systemd “目标”。转到模板文件:

    # systemd service template for PostgreSQL clusters. The actual instances will
    # be called "postgresql@version-cluster", e.g. "[email protected]". The
    # variable %i expands to "version-cluster", %I expands to "version/cluster".
    # (%I breaks for cluster names containing dashes.)
    
    [Unit]
    Description=PostgreSQL Cluster %i
    ConditionPathExists=/etc/postgresql/%I/postgresql.conf
    PartOf=postgresql.service
    ReloadPropagatedFrom=postgresql.service
    Before=postgresql.service
    
    [Service]
    Type=forking
    # @: use "postgresql@%i" as process name
    ExecStart=@/usr/bin/pg_ctlcluster postgresql@%i --skip-systemctl-redirect %i start
    ExecStop=/usr/bin/pg_ctlcluster --skip-systemctl-redirect -m fast %i stop
    ExecReload=/usr/bin/pg_ctlcluster --skip-systemctl-redirect %i reload
    PIDFile=/var/run/postgresql/%i.pid
    SyslogIdentifier=postgresql@%i
    # prevent OOM killer from choosing the postmaster (individual backends will
    # reset the score to 0)
    OOMScoreAdjust=-900
    # restarting automatically will prevent "pg_ctlcluster ... stop" from working,
    # so we disable it here. Also, the postmaster will restart by itself on most
    # problems anyway, so it is questionable if one wants to enable external
    # automatic restarts.
    #Restart=on-failure
    # (This should make pg_ctlcluster stop work, but doesn't:)
    #RestartPreventExitStatus=SIGINT SIGTERM
    
    [Install]
    WantedBy=multi-user.target
    

    有趣的指令是:

    PartOf=postgresql.service
    ReloadPropagatedFrom=postgresql.service
    

    如果您不确定在哪里可以找到systemd指令的文档,您可以检查:man systemd.directives. 从那里,我们在man systemd.unit.

    当您启用服务时,您最大的线索是:

    sudo systemctl enable [email protected]
    Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /lib/systemd/system/[email protected].
    

    把它们放在一起:

    • 符号链接是如何systemd知道在服务器启动时启动 PostgreSQL 9.6。
    • PartOf=和ReloadPropagatedFrom=指令确保服务上的、 和最终stop应用于start所有相关的已安装 PostgreSQL 实例。restartreloadpostgresql
    • 10
  2. Sebastian Wiesinger
    2021-08-18T04:14:24+08:002021-08-18T04:14:24+08:00

    至少在较新版本的 postgres 中有一个 systemd 生成器脚本

    /lib/systemd/system-generators/postgresql-generator
    

    它将启动所有在它们的值为“auto”的 postgresql 实例

    /etc/postgresql/VERSION/main/start.conf
    

    配置。所以不需要通过符号链接systemctl enable或类似的东西手动启用这些。只需更改启动模式start.conf并执行systemctl daemon-reload.

    • 1

相关问题

  • journalctl 中的区分级别

  • 将默认编辑器更改为 vim for _ sudo systemctl edit [unit-file] _

  • systemd:如何在服务启动时运行脚本,而不编辑服务定义

  • 使用 systemd 看门狗支持重新启动应用程序

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve