Thread: 'pg_ctl restart' does not terminate

'pg_ctl restart' does not terminate

From
twoflower
Date:
I am restarting the server using the following:
su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D /var/lib/postgresql/9.6/main -o '-c config_file=/etc/postgresql/9.6/main/postgresql.conf' restart"
The server is restarted properly, but the the command never finishes. After the restart, it displays the server's logfile. Is this intended?

View this message in context: 'pg_ctl restart' does not terminate
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: 'pg_ctl restart' does not terminate

From
Adrian Klaver
Date:
On 11/26/2016 07:15 AM, twoflower wrote:
> I am restarting the server using the following:
>
> su postgres -c "/usr/lib/postgresql/9.6/bin/pg_ctl -D /var/lib/postgresql/9.6/main -o '-c
config_file=/etc/postgresql/9.6/main/postgresql.conf'restart" 
>
> The server is restarted properly, but the the command never finishes.
> After the restart, it displays the server's logfile. Is this intended?

Do have logging set up in postgresql.conf to go to a file?

Even if you do have logging set to go to a file you will probably see a
couple of lines telling you it is redirecting to the file.

You also specify a log file to pg_ctl  by using -l:

https://www.postgresql.org/docs/9.5/static/app-pg-ctl.html


--
Adrian Klaver
adrian.klaver@aklaver.com


Re: 'pg_ctl restart' does not terminate

From
twoflower
Date:
Adrian Klaver-4 wrote
> You also specify a log file to pg_ctl  by using -l:
>
> https://www.postgresql.org/docs/9.5/static/app-pg-ctl.html

This did the trick, thank you!




--
View this message in context: http://postgresql.nabble.com/pg-ctl-restart-does-not-terminate-tp5932070p5932076.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: 'pg_ctl restart' does not terminate

From
Adrian Klaver
Date:
On 11/26/2016 07:47 AM, twoflower wrote:
> Adrian Klaver-4 wrote
>> You also specify a log file to pg_ctl  by using -l:
>>
>> https://www.postgresql.org/docs/9.5/static/app-pg-ctl.html
>
> This did the trick, thank you!

Great. Still I would suggest using the settings here:

https://www.postgresql.org/docs/9.5/static/runtime-config-logging.html#RUNTIME-CONFIG-LOGGING-WHERE

Then you will get logging however you start Postgres.




--
Adrian Klaver
adrian.klaver@aklaver.com


Re: 'pg_ctl restart' does not terminate

From
twoflower
Date:
Yes, I am using that, thank you. But just by themselves these settings do not make pg_ctl terminate.

View this message in context: Re: 'pg_ctl restart' does not terminate
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: 'pg_ctl restart' does not terminate

From
Adrian Klaver
Date:
On 11/26/2016 11:08 AM, twoflower wrote:
> Yes, I am using that, thank you. But just by themselves these settings
> do not make |pg_ctl| terminate.
>
You should see something like:

postgres@panda:~> /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/
restart
waiting for server to shut down..... done
server stopped
server starting
postgres@panda:~> -2016-11-26 11:16:40.737 PST-0 LOG:  redirecting log
output to logging collector process
-2016-11-26 11:16:40.737 PST-0 HINT:  Future log output will appear in
directory "pg_log".

If you hit Enter you get:

postgres@panda:~>

--
Adrian Klaver
adrian.klaver@aklaver.com


Re: 'pg_ctl restart' does not terminate

From
twoflower
Date:
Ah, it didn't occur to me to try hitting ENTER. Still, this would be fine for manually running the script, but as I am restarting the server as a part of SaltStack config, I need pg_ctl to terminate without me intervening.

The solution with the -l argument is fine, I think. Even if I use it, the server then logs its output into the file I specified in postgresql.conf (which I would not expect, by the way).

View this message in context: Re: 'pg_ctl restart' does not terminate
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Re: 'pg_ctl restart' does not terminate

From
Adrian Klaver
Date:
On 11/26/2016 11:33 AM, twoflower wrote:
> Ah, it didn't occur to me to try hitting ENTER. Still, this would be
> fine for manually running the script, but as I am restarting the server
> as a part of SaltStack config, I need |pg_ctl| to terminate without me
> intervening.
>
> The solution with the |-l| argument is fine, I think. Even if I use it,
> the server then logs its output into the file I specified in
> |postgresql.conf| (which I would not expect, by the way).

You are seeing the two stages of logging. The first stage, that you are
capturing with -l, is the early logging before the logging configuration
you set up in postgresql.conf kicks in. This is why you see this:

-2016-11-26 11:16:40.737 PST-0 LOG:  redirecting log output to logging
collector process
-2016-11-26 11:16:40.737 PST-0 HINT:  Future log output will appear in
directory "pg_log".

After the above the rest of the logging goes to whatever you set up in
postgresql.conf, assuming it was set up. Otherwise it will go to the
stdout of the terminal.

--
Adrian Klaver
adrian.klaver@aklaver.com


Re: 'pg_ctl restart' does not terminate

From
twoflower
Date:
That makes perfect sense.

Thank you for a great help, Adrian!



--
View this message in context: http://postgresql.nabble.com/pg-ctl-restart-does-not-terminate-tp5932070p5932095.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: 'pg_ctl restart' does not terminate

From
Melvin Davidson
Date:

On Sat, Nov 26, 2016 at 2:52 PM, twoflower <standa.kurik@gmail.com> wrote:
That makes perfect sense.

Thank you for a great help, Adrian!



--
View this message in context: http://postgresql.nabble.com/pg-ctl-restart-does-not-terminate-tp5932070p5932095.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

I feel it important to add one note to this thread. The version of PostgreSQL has not been stated, but it is very
important to note that the default behavior of pg_ctl has changed between v9.4 and 9.5.

https://www.postgresql.org/docs/9.5/static/release-9-5.html
  • Change pg_ctl's default shutdown mode from smart to fast (Bruce Momjian)

    This means the default behavior will be to forcibly cancel existing database sessions, not simply wait for them to exit.

So if the PostgreSQL version is 9.4 or lower, and there are any open connections, the pg_ctl will wait until all connections terminate (either normally or
are forced off). That "might " explain why pg_ctl never terminated (unless -m fast was also specified). However, if it is version 9.5 or above, then
-m fast is the default so existing connections will not be a problem.
--
Melvin Davidson
I reserve the right to fantasize.  Whether or not you
wish to share my fantasy is entirely up to you.