Separate systemd script for postgresql instances












0















I have PostgreSQL-11 installed on Ubuntu 18.04 via apt-get, and based from here, I managed to install 2 instances of postgreSQL on port 5432 and 5433.



My Question is, can I have separate start-stop script for these two instances? As my other server running postgresql 9.6 on Centos 7, has several startup script which are:



postgresql-9.6-instanceA.service
postgresql-9.6-instanceB.service
postgresql-9.6-instanceC.service
postgresql-9.6-instanceD.service
postgresql-9.6-instanceE.service



Where those files difference only in the environment (notice the Environment section):



[root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/postgresql-9.6.service",
# containing
# .include /lib/systemd/system/postgresql-9.6.service
# ...make your changes here...
# For more info about custom unit files, see
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.

# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL 9.6 database server
Documentation=https://www.postgresql.org/docs/9.6/static/
After=syslog.target
After=network.target

[Service]
Type=notify

User=postgres
Group=postgres

# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/instanceA/9.6/data

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
Environment=PG_OOM_ADJUST_VALUE=0

ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA}
ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA}
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT


# Do not set any timeout value, so that systemd will not kill postmaster
# during crash recovery.
TimeoutSec=0

[Install]
WantedBy=multi-user.target


Based from what I read here, the script above can be created if the installation is from source, thus we need to add systemd unit file.



These are the content of the systemd script on my ubuntu server.
These below are the postgresql.service file on my ubuntu 18.04:
The first one is /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service, which is empty:



root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
-rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service


The second and third file has the same content:



/etc/systemd/system/multi-user.target.wants/postgresql.service
/lib/systemd/system/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


So again, can I have such situation with my ubuntu server? So that I can have start-stop-reload-restart script for my two postgres instances, as I'm not sure where or which file to edit.









share







New contributor




buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I have PostgreSQL-11 installed on Ubuntu 18.04 via apt-get, and based from here, I managed to install 2 instances of postgreSQL on port 5432 and 5433.



    My Question is, can I have separate start-stop script for these two instances? As my other server running postgresql 9.6 on Centos 7, has several startup script which are:



    postgresql-9.6-instanceA.service
    postgresql-9.6-instanceB.service
    postgresql-9.6-instanceC.service
    postgresql-9.6-instanceD.service
    postgresql-9.6-instanceE.service



    Where those files difference only in the environment (notice the Environment section):



    [root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.service
    # It's not recommended to modify this file in-place, because it will be
    # overwritten during package upgrades. If you want to customize, the
    # best way is to create a file "/etc/systemd/system/postgresql-9.6.service",
    # containing
    # .include /lib/systemd/system/postgresql-9.6.service
    # ...make your changes here...
    # For more info about custom unit files, see
    # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

    # Note: changing PGDATA will typically require adjusting SELinux
    # configuration as well.

    # Note: do not use a PGDATA pathname containing spaces, or you will
    # break postgresql-setup.
    [Unit]
    Description=PostgreSQL 9.6 database server
    Documentation=https://www.postgresql.org/docs/9.6/static/
    After=syslog.target
    After=network.target

    [Service]
    Type=notify

    User=postgres
    Group=postgres

    # Note: avoid inserting whitespace in these Environment= lines, or you may
    # break postgresql-setup.

    # Location of database directory
    Environment=PGDATA=/var/lib/pgsql/instanceA/9.6/data

    # Where to send early-startup messages from the server (before the logging
    # options of postgresql.conf take effect)
    # This is normally controlled by the global default set by systemd
    # StandardOutput=syslog

    # Disable OOM kill on the postmaster
    OOMScoreAdjust=-1000
    Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
    Environment=PG_OOM_ADJUST_VALUE=0

    ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA}
    ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA}
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=mixed
    KillSignal=SIGINT


    # Do not set any timeout value, so that systemd will not kill postmaster
    # during crash recovery.
    TimeoutSec=0

    [Install]
    WantedBy=multi-user.target


    Based from what I read here, the script above can be created if the installation is from source, thus we need to add systemd unit file.



    These are the content of the systemd script on my ubuntu server.
    These below are the postgresql.service file on my ubuntu 18.04:
    The first one is /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service, which is empty:



    root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
    -rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service


    The second and third file has the same content:



    /etc/systemd/system/multi-user.target.wants/postgresql.service
    /lib/systemd/system/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


    So again, can I have such situation with my ubuntu server? So that I can have start-stop-reload-restart script for my two postgres instances, as I'm not sure where or which file to edit.









    share







    New contributor




    buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I have PostgreSQL-11 installed on Ubuntu 18.04 via apt-get, and based from here, I managed to install 2 instances of postgreSQL on port 5432 and 5433.



      My Question is, can I have separate start-stop script for these two instances? As my other server running postgresql 9.6 on Centos 7, has several startup script which are:



      postgresql-9.6-instanceA.service
      postgresql-9.6-instanceB.service
      postgresql-9.6-instanceC.service
      postgresql-9.6-instanceD.service
      postgresql-9.6-instanceE.service



      Where those files difference only in the environment (notice the Environment section):



      [root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.service
      # It's not recommended to modify this file in-place, because it will be
      # overwritten during package upgrades. If you want to customize, the
      # best way is to create a file "/etc/systemd/system/postgresql-9.6.service",
      # containing
      # .include /lib/systemd/system/postgresql-9.6.service
      # ...make your changes here...
      # For more info about custom unit files, see
      # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

      # Note: changing PGDATA will typically require adjusting SELinux
      # configuration as well.

      # Note: do not use a PGDATA pathname containing spaces, or you will
      # break postgresql-setup.
      [Unit]
      Description=PostgreSQL 9.6 database server
      Documentation=https://www.postgresql.org/docs/9.6/static/
      After=syslog.target
      After=network.target

      [Service]
      Type=notify

      User=postgres
      Group=postgres

      # Note: avoid inserting whitespace in these Environment= lines, or you may
      # break postgresql-setup.

      # Location of database directory
      Environment=PGDATA=/var/lib/pgsql/instanceA/9.6/data

      # Where to send early-startup messages from the server (before the logging
      # options of postgresql.conf take effect)
      # This is normally controlled by the global default set by systemd
      # StandardOutput=syslog

      # Disable OOM kill on the postmaster
      OOMScoreAdjust=-1000
      Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
      Environment=PG_OOM_ADJUST_VALUE=0

      ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA}
      ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA}
      ExecReload=/bin/kill -HUP $MAINPID
      KillMode=mixed
      KillSignal=SIGINT


      # Do not set any timeout value, so that systemd will not kill postmaster
      # during crash recovery.
      TimeoutSec=0

      [Install]
      WantedBy=multi-user.target


      Based from what I read here, the script above can be created if the installation is from source, thus we need to add systemd unit file.



      These are the content of the systemd script on my ubuntu server.
      These below are the postgresql.service file on my ubuntu 18.04:
      The first one is /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service, which is empty:



      root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
      -rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service


      The second and third file has the same content:



      /etc/systemd/system/multi-user.target.wants/postgresql.service
      /lib/systemd/system/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


      So again, can I have such situation with my ubuntu server? So that I can have start-stop-reload-restart script for my two postgres instances, as I'm not sure where or which file to edit.









      share







      New contributor




      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have PostgreSQL-11 installed on Ubuntu 18.04 via apt-get, and based from here, I managed to install 2 instances of postgreSQL on port 5432 and 5433.



      My Question is, can I have separate start-stop script for these two instances? As my other server running postgresql 9.6 on Centos 7, has several startup script which are:



      postgresql-9.6-instanceA.service
      postgresql-9.6-instanceB.service
      postgresql-9.6-instanceC.service
      postgresql-9.6-instanceD.service
      postgresql-9.6-instanceE.service



      Where those files difference only in the environment (notice the Environment section):



      [root@root]# cat /etc/systemd/system/postgresql-9.6-instanceA.service
      # It's not recommended to modify this file in-place, because it will be
      # overwritten during package upgrades. If you want to customize, the
      # best way is to create a file "/etc/systemd/system/postgresql-9.6.service",
      # containing
      # .include /lib/systemd/system/postgresql-9.6.service
      # ...make your changes here...
      # For more info about custom unit files, see
      # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

      # Note: changing PGDATA will typically require adjusting SELinux
      # configuration as well.

      # Note: do not use a PGDATA pathname containing spaces, or you will
      # break postgresql-setup.
      [Unit]
      Description=PostgreSQL 9.6 database server
      Documentation=https://www.postgresql.org/docs/9.6/static/
      After=syslog.target
      After=network.target

      [Service]
      Type=notify

      User=postgres
      Group=postgres

      # Note: avoid inserting whitespace in these Environment= lines, or you may
      # break postgresql-setup.

      # Location of database directory
      Environment=PGDATA=/var/lib/pgsql/instanceA/9.6/data

      # Where to send early-startup messages from the server (before the logging
      # options of postgresql.conf take effect)
      # This is normally controlled by the global default set by systemd
      # StandardOutput=syslog

      # Disable OOM kill on the postmaster
      OOMScoreAdjust=-1000
      Environment=PG_OOM_ADJUST_FILE=/proc/self/oom_score_adj
      Environment=PG_OOM_ADJUST_VALUE=0

      ExecStartPre=/usr/pgsql-9.6/bin/postgresql96-check-db-dir ${PGDATA}
      ExecStart=/usr/pgsql-9.6/bin/postmaster -D ${PGDATA}
      ExecReload=/bin/kill -HUP $MAINPID
      KillMode=mixed
      KillSignal=SIGINT


      # Do not set any timeout value, so that systemd will not kill postmaster
      # during crash recovery.
      TimeoutSec=0

      [Install]
      WantedBy=multi-user.target


      Based from what I read here, the script above can be created if the installation is from source, thus we need to add systemd unit file.



      These are the content of the systemd script on my ubuntu server.
      These below are the postgresql.service file on my ubuntu 18.04:
      The first one is /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service, which is empty:



      root@hostname:~# ls -lah /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service
      -rw-r--r-- 1 root root 0 Feb 25 03:50 /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/postgresql.service


      The second and third file has the same content:



      /etc/systemd/system/multi-user.target.wants/postgresql.service
      /lib/systemd/system/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


      So again, can I have such situation with my ubuntu server? So that I can have start-stop-reload-restart script for my two postgres instances, as I'm not sure where or which file to edit.







      linux scripting systemd postgresql





      share







      New contributor




      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 7 mins ago









      buzzing_beebuzzing_bee

      1




      1




      New contributor




      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      buzzing_bee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          buzzing_bee is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502788%2fseparate-systemd-script-for-postgresql-instances%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          buzzing_bee is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          buzzing_bee is a new contributor. Be nice, and check out our Code of Conduct.













          buzzing_bee is a new contributor. Be nice, and check out our Code of Conduct.












          buzzing_bee is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502788%2fseparate-systemd-script-for-postgresql-instances%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          サソリ

          広島県道265号伴広島線

          Setup Asymptote in Texstudio