Re: The uselessness of pgbouncer PAUSE

Lists: sfpug
From: Josh Berkus <josh(at)agliodbs(dot)com>
To: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 00:08:50
Message-ID: 52D72312.4040202@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: Postg토토 캔SQL : Postg토토 캔SQL 메일 링리스트 : 2014-01-16 00:08 이후의 SFPUG

Sergey,

I looked into this today, and it doesn't help at all. PAUSE will wait
for all current queries to complete before switching over, which isn't
tolerable in a failover situation. Unfortunately, there seems to be no
command which says "kill running query connections but leave idle
connections alone". Possible this is the idea behind SUSPEND, but if
so, it doesn't work.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 21:29:52
Message-ID: CAL_0b1tJiVkMQ07ZN03jX0x1gMH2-Dxz7_yfTDJ2u-oOKcdvSw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On Wed, Jan 15, 2014 at 4:08 PM, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> I looked into this today, and it doesn't help at all. PAUSE will wait
> for all current queries to complete before switching over, which isn't
> tolerable in a failover situation. Unfortunately, there seems to be no
> command which says "kill running query connections but leave idle
> connections alone". Possible this is the idea behind SUSPEND, but if
> so, it doesn't work.

Even more, it does not make any sense in a failover situation, when
the master is down or unavailable. I was talking about a manual
switchover case when one can control what is going on on master.

And yes, we need to keep in mind long running transactions. I always
turn off all the cron jobs and other stuff that might cause them
before switching over, and always have this query

SELECT pg_terminate_backend(pid) FROM pg_stat_activity
WHERE now() - xact_start > '3 seconds';

ready in case if something long appear after the pause. I think a
configuration parameter in HandyRep can be added to control how many
seconds it can wait for queries to complete after pausing PgBouncer.

Here is my notes for the PgBouncer based switchover process

https://github.com/grayhemp/pgcookbook/blob/master/switching_to_another_server_with_pgbouncer.md

Probably you will find there something else, that might be useful for you.

ps. And this is the correct version of byte lag measurement for <9.1 I
promised to send you

CREATE OR REPLACE FUNCTION hex_to_int(i_hex text, OUT o_dec integer)
RETURNS integer LANGUAGE 'plpgsql' IMMUTABLE STRICT AS $$
BEGIN
EXECUTE 'SELECT x''' || i_hex || '''::integer' INTO o_dec;
RETURN;
END $$;

SELECT
client_addr,
sent_offset - (
replay_offset - (sent_xlog - replay_xlog) * 255 * 16 ^ 6 ) AS byte_lag
FROM (
SELECT
client_addr,
hex_to_int(split_part(sent_location, '/', 1)) AS sent_xlog,
hex_to_int(split_part(replay_location, '/', 1)) AS replay_xlog,
hex_to_int(split_part(sent_location, '/', 2)) AS sent_offset,
hex_to_int(split_part(replay_location, '/', 2)) AS replay_offset
FROM pg_stat_replication
) AS s;

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 21:55:07
Message-ID: 52D8553B.9040906@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On 01/16/2014 01:29 PM, Sergey Konoplev wrote:
> On Wed, Jan 15, 2014 at 4:08 PM, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
>> I looked into this today, and it doesn't help at all. PAUSE will wait
>> for all current queries to complete before switching over, which isn't
>> tolerable in a failover situation. Unfortunately, there seems to be no
>> command which says "kill running query connections but leave idle
>> connections alone". Possible this is the idea behind SUSPEND, but if
>> so, it doesn't work.
>
> Even more, it does not make any sense in a failover situation, when
> the master is down or unavailable. I was talking about a manual
> switchover case when one can control what is going on on master.

That's far more complicated than just restarting pgbouncer, and doesn't
solve the problem I was trying to solve. Maybe I'll add something
later, but right now it's too limited to do anything with.

It would be nice to use PAUSE for reloading the configuration after, for
example, adding a new replica to the pool. However, that would take a
lot of experimentation to see if it even works.

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 22:02:01
Message-ID: 52D856D9.2070601@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On 01/16/2014 01:29 PM, Sergey Konoplev wrote:
> Here is my notes for the PgBouncer based switchover process
>
> https://github.com/grayhemp/pgcookbook/blob/master/switching_to_another_server_with_pgbouncer.md

BTW, the Debian/Ubuntu PostgreSQL packages don't support these commands:

/etc/init.d/pgbouncer pause
/etc/init.d/pgbouncer reload

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 22:19:55
Message-ID: CAL_0b1t6CkBKbqq6o5hsJoBKhc8_T6tCyhJTUCJcQrPGQGS_jA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On Thu, Jan 16, 2014 at 1:55 PM, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> On 01/16/2014 01:29 PM, Sergey Konoplev wrote:
> That's far more complicated than just restarting pgbouncer, and doesn't
> solve the problem I was trying to solve. Maybe I'll add something
> later, but right now it's too limited to do anything with.

Sure.

> It would be nice to use PAUSE for reloading the configuration after, for
> example, adding a new replica to the pool. However, that would take a
> lot of experimentation to see if it even works.

You just need to RELOAD if you added/changed something in the
[database] section of config. It will handle everything itself AFAIK.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 22:22:21
Message-ID: CAL_0b1tTZjw-tsncf2uDYVTJy=9yH3Au7LAtHOsao2-fH7-s5g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On Thu, Jan 16, 2014 at 2:02 PM, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
> On 01/16/2014 01:29 PM, Sergey Konoplev wrote:
>> Here is my notes for the PgBouncer based switchover process
>>
>> https://github.com/grayhemp/pgcookbook/blob/master/switching_to_another_server_with_pgbouncer.md
>
> BTW, the Debian/Ubuntu PostgreSQL packages don't support these commands:
>
> /etc/init.d/pgbouncer pause
> /etc/init.d/pgbouncer reload

Yes, in this case you can PAUSE-RELOAD ... RESUME via console.

I probably need to add a note about it to the document. Thanks for the hint.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com


From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 22:22:46
Message-ID: 52D85BB6.3030302@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug


>> It would be nice to use PAUSE for reloading the configuration after, for
>> example, adding a new replica to the pool. However, that would take a
>> lot of experimentation to see if it even works.
>
> You just need to RELOAD if you added/changed something in the
> [database] section of config. It will handle everything itself AFAIK.

The real issue here is that PAUSE can hang indefinitely. What happens
if I do RELOAD without doing PAUSE?

--
Josh Berkus
PostgreSQL Experts Inc.
http://pgexperts.com


From: Sergey Konoplev <gray(dot)ru(at)gmail(dot)com>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: SF Postgres <sfpug(at)postgresql(dot)org>
Subject: Re: The uselessness of pgbouncer PAUSE
Date: 2014-01-16 22:33:30
Message-ID: CAL_0b1sUU=MKWi1_GuWv_zq4PtRKKi2tXyd-nxdT31SSED+L-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: sfpug

On Thu, Jan 16, 2014 at 2:22 PM, Josh Berkus <josh(at)agliodbs(dot)com> wrote:
>>> It would be nice to use PAUSE for reloading the configuration after, for
>>> example, adding a new replica to the pool. However, that would take a
>>> lot of experimentation to see if it even works.
>>
>> You just need to RELOAD if you added/changed something in the
>> [database] section of config. It will handle everything itself AFAIK.
>
> The real issue here is that PAUSE can hang indefinitely. What happens
> if I do RELOAD without doing PAUSE?

I meant just RELOAD without PAUSE in case of adding a new replica. It
will simply start working with new entries you added to the [database]
section and change the way it worked with the existing ones that were
changed.

ps. Returning to the PAUSE - it can be prevented from hanging
indefinitely, but, yes, as you noted, it might require a lot of
additional logic and experimenting.

--
Kind regards,
Sergey Konoplev
PostgreSQL Consultant and DBA

http://www.linkedin.com/in/grayhemp
+1 (415) 867-9984, +7 (901) 903-0499, +7 (988) 888-1979
gray(dot)ru(at)gmail(dot)com