Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0aku-0001ZN-VG for pgsql-general@arkaria.postgresql.org; Thu, 13 Sep 2018 23:10:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0akq-0002h6-Dv for pgsql-general@arkaria.postgresql.org; Thu, 13 Sep 2018 23:10:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0akp-0002gu-HF for pgsql-general@lists.postgresql.org; Thu, 13 Sep 2018 23:10:32 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0akk-0006me-G9 for pgsql-general@lists.postgresql.org; Thu, 13 Sep 2018 23:10:31 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D6D0E21B98; Thu, 13 Sep 2018 19:10:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 13 Sep 2018 19:10:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=V8+jftwcYJjJcp40U4ifeq/jytBVj xu5coktp01N/jA=; b=TVRLyhsH/bGZGbT8ejqUMuk33LV4FvWOdPGI1SV2soXhy 1IrBD9/RPDSejQ5ETxGxDhACDrOoHbMARAgxlvExUxHt6LJYSLR/TWLydgIkr4xv Z+eStuXUjHcg3BoKDcS9Q6RqxHtLhhgNCAfvq7yT3pS4m9Vc1pUlURZoruoGaCZP 1IF+hOhI3SPjnjYnWJln3UantRR/nL5gfyb1aRdutS9PQWOWRoUdiaxAX2BDvriv yfP51LnkLjSZdvTgUiBX7jW2AKE6khcb46PoCGElt8DYfE+RzR75yL06vTixEwZd dnBGfK9z6096ujzaOQXi7+rAyDfshqAnatL4uCBvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=V8+jft wcYJjJcp40U4ifeq/jytBVjxu5coktp01N/jA=; b=BuJxyFDaqViKozLfoMk8JZ I1el1uWLnT9NIZ+8zpGVU4py0b4FzkTJAbDD4Iz3G2WvctdbjW6Hi3NDwgRSlX6j GRKyR1HDSbKnZ4zn6ZaWQ0eC7zvGLVBhVKKLmh+TV8+Ix5JdDZU8oHWZEAyz2jn3 IFyuu2F3pOUiET9HdrCoTUqT+yG8HGPV2OY1Lq71SajuI8ltGElLf2wXYbjVebdE 4xCmcni0pOWXbMqnb6wlT1xT3dJ3x3v4Y6XbesWmz0Wl2riVyLmYMiVtnevPFZVp ZAF5UbfwCQ4qqftWQDHoHCpDoMoUVLdNNSmoIcxHMe1OBzorBiHlK5FcJ3304RlQ == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id C8F26E46B6; Thu, 13 Sep 2018 19:10:23 -0400 (EDT) Subject: Re: Slow shutdowns sometimes on RDS Postgres To: Chris Williams , pgsql-general@lists.postgresql.org References: <2029f1ad-23e5-5e81-4409-a76386f71382@commandprompt.com> From: Adrian Klaver Message-ID: <23780483-c3f2-d150-1c28-c6488eda1d0b@aklaver.com> Date: Thu, 13 Sep 2018 16:10:22 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/13/18 3:59 PM, Chris Williams wrote: > Yeah, I figured that.  Unfortunately, every time it happens, I open a > support ticket with them, but they always just tell me that this is > normal behavior for postgres.  Whether it's "normal" or not, I really > would like to get my db to shut down faster, and their suggestion of > manually shutting down all of my apps ahead of time is a real headache. > Given that I haven't gotten anywhere with their support, I figured I'd > try asking on the mailing list. The thing is, what you are doing ("(e.g. reboot, changing instance size, etc.)") are instance operations not database operations. That comes under AWS's purview. For what it is worth the behavior is documented: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RebootInstance.html "The time required to reboot your DB instance depends on the crash recovery process of your specific database engine. To improve the reboot time, we recommend that you reduce database activity as much as possible during the reboot process. Reducing database activity reduces rollback activity for in-transit transactions. " Pretty sure shutting down those 600 connections and uncoupling the replication(s) goes a long way to the time elapsed. > > Thanks, > Chris > > On Thu, Sep 13, 2018 at 3:17 PM Joshua D. Drake > wrote: > > On 09/13/2018 03:04 PM, Chris Williams wrote: > > Hi, > > > > I'm using AWS RDS Postgres (9.6.6) and have run into very slow > > shutdowns (10+ minutes) a few times when making database > modifications > > (e.g. reboot, changing instance size, etc.).  Other times, it shuts > > down quickly (1 minute or so).  I have not been able to figure > out why > > sometimes it takes a long time to shutdown. > > This is probably something you would have to talk to Amazon about. AWS > RDS Postgres is a fork of PostgreSQL and not 100% compatible from an > administrative perspective. > > JD > > > > > > > When it happens, I see a bunch of lines in the postgres log like the > > following over and over (almost every second or two) during this 10 > > minute shutdown period: > > 2018-09-12 06:37:01 > > UTC:XXX.XXX.XXX.XXX(19712):my_user@my_db:[16495]:FATAL: > > 2018-09-12 06:37:01 > > UTC:localhost(31368):rdsadmin@rdsadmin:[16488]:FATAL: the database > > system is shutting down > > > > Once I start seeing these messages, I start manually shutting > down all > > of our applications that are connected to the db.  I'm not sure if > > shutting down the apps fixes it or if there's some timeout on the > RDS > > side, but it seems like once I start doing this, the database > finally > > shuts down. > > > > When it takes this long to shut down, it ends up causing a lot more > > downtime than I would like.  I've tried asking AWS's support why it > > takes so long to shutdown sometimes, but they basically just told me > > that's "how it works" and that I should try to shut down all of my > > connections ahead of time before making database modifications. > > > > We just have a few ruby on rails applications connected to the > > database, and don't really have any long running or heavy queries > and > > the db is under very light load, so I don't understand why it > takes so > > long to shutdown.  We do have a sizeable number of connections > though > > (about 600) and there are two replicas connected to it.  I also > tried > > setting idle_in_transaction_session_timeout to 300 seconds to see if > > that would help, but it made no difference. > > > > I was wondering if anyone else had seen this behavior on their RDS > > Postgres instances or had any suggestions on how I could shorten the > > shutdown time? > > > > Thanks, > > Chris > > > > -- > Command Prompt, Inc. || http://the.postgres.company/ || @cmdpromptinc > ***  A fault and talent of mine is to tell it exactly how it is.  *** > PostgreSQL centered full stack support, consulting and development. > Advocate: @amplifypostgres || Learn: https://postgresconf.org > *****     Unless otherwise stated, opinions are my own.   ***** > -- Adrian Klaver adrian.klaver@aklaver.com