How to shutdown postgres through psql?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












The recommended way to shutdown postgres is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql than docker exec and thus more convenient to stop the server through psql. Is there a way to do that (given that the privileges have been granted)?



The solution can be hacky since this will mostly be used to stop a postgres to delete a PostgreSQL data directory in a development environment.










share|improve this question









New contributor




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

























    up vote
    2
    down vote

    favorite












    The recommended way to shutdown postgres is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql than docker exec and thus more convenient to stop the server through psql. Is there a way to do that (given that the privileges have been granted)?



    The solution can be hacky since this will mostly be used to stop a postgres to delete a PostgreSQL data directory in a development environment.










    share|improve this question









    New contributor




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





















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      The recommended way to shutdown postgres is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql than docker exec and thus more convenient to stop the server through psql. Is there a way to do that (given that the privileges have been granted)?



      The solution can be hacky since this will mostly be used to stop a postgres to delete a PostgreSQL data directory in a development environment.










      share|improve this question









      New contributor




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











      The recommended way to shutdown postgres is to send a signal representing the different shutdown modes (fast, smart, immediate). In a containerized environment it's sometimes more convenient to gain access through psql than docker exec and thus more convenient to stop the server through psql. Is there a way to do that (given that the privileges have been granted)?



      The solution can be hacky since this will mostly be used to stop a postgres to delete a PostgreSQL data directory in a development environment.







      postgresql psql shutdown






      share|improve this question









      New contributor




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











      share|improve this question









      New contributor




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









      share|improve this question




      share|improve this question








      edited 29 mins ago





















      New contributor




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









      asked 1 hour ago









      Karl Richter

      1113




      1113




      New contributor




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





      New contributor





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






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




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          The documentation tells you to send a signal to the master postgres process, or to let pg_ctl do this.



          In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid'), but pg_cancel_backend() does not accept this PID.



          However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):



          COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';




          COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';





          share|improve this answer



























            up vote
            1
            down vote













            No, that's not possible, you can not shutdown Postgres using psql.



            You can only shut it down through pg_ctl or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ... in Ubuntu it would be service postgresql stop or pg_ctlcluster 11 main stop in Windows net stop ...






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "182"
              ;
              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );






              Karl Richter 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%2fdba.stackexchange.com%2fquestions%2f221063%2fhow-to-shutdown-postgres-through-psql%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              The documentation tells you to send a signal to the master postgres process, or to let pg_ctl do this.



              In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid'), but pg_cancel_backend() does not accept this PID.



              However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):



              COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';




              COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';





              share|improve this answer
























                up vote
                2
                down vote













                The documentation tells you to send a signal to the master postgres process, or to let pg_ctl do this.



                In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid'), but pg_cancel_backend() does not accept this PID.



                However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):



                COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';




                COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';





                share|improve this answer






















                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  The documentation tells you to send a signal to the master postgres process, or to let pg_ctl do this.



                  In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid'), but pg_cancel_backend() does not accept this PID.



                  However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):



                  COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';




                  COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';





                  share|improve this answer












                  The documentation tells you to send a signal to the master postgres process, or to let pg_ctl do this.



                  In SQL, you can extract the PID of the master process from pg_read_file('postmaster.pid'), but pg_cancel_backend() does not accept this PID.



                  However, you should be able to execute these commands with COPY (depending on what rights the postgres OS user has):



                  COPY (SELECT 1) TO PROGRAM 'kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`';




                  COPY (SELECT 1) TO PROGRAM 'pg_ctl -D /usr/local/pgsql/data stop';






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 48 mins ago









                  CL.

                  2,35011114




                  2,35011114






















                      up vote
                      1
                      down vote













                      No, that's not possible, you can not shutdown Postgres using psql.



                      You can only shut it down through pg_ctl or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ... in Ubuntu it would be service postgresql stop or pg_ctlcluster 11 main stop in Windows net stop ...






                      share|improve this answer


























                        up vote
                        1
                        down vote













                        No, that's not possible, you can not shutdown Postgres using psql.



                        You can only shut it down through pg_ctl or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ... in Ubuntu it would be service postgresql stop or pg_ctlcluster 11 main stop in Windows net stop ...






                        share|improve this answer
























                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          No, that's not possible, you can not shutdown Postgres using psql.



                          You can only shut it down through pg_ctl or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ... in Ubuntu it would be service postgresql stop or pg_ctlcluster 11 main stop in Windows net stop ...






                          share|improve this answer














                          No, that's not possible, you can not shutdown Postgres using psql.



                          You can only shut it down through pg_ctl or - preferrably - the "service control" of the underlying operating system, e.g. in CentOS that would be systemctl stop ... in Ubuntu it would be service postgresql stop or pg_ctlcluster 11 main stop in Windows net stop ...







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 57 mins ago

























                          answered 1 hour ago









                          a_horse_with_no_name

                          37.2k772110




                          37.2k772110




















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









                               

                              draft saved


                              draft discarded


















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












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











                              Karl Richter 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%2fdba.stackexchange.com%2fquestions%2f221063%2fhow-to-shutdown-postgres-through-psql%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              One-line joke