Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7LEi-0001p7-5R for pgsql-general@arkaria.postgresql.org; Fri, 22 Mar 2019 14:33:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h7LEg-0007Br-LE for pgsql-general@arkaria.postgresql.org; Fri, 22 Mar 2019 14:33:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7LEg-00073c-5n for pgsql-general@lists.postgresql.org; Fri, 22 Mar 2019 14:33:30 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7LEd-0007Hz-DZ for pgsql-general@postgresql.org; Fri, 22 Mar 2019 14:33:28 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id A5DA6247F8; Fri, 22 Mar 2019 10:33:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Mar 2019 10:33:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=q 3d+sa4riczg0Blm1MiljzpqSPeM3FV+c6ykZ21WeHI=; b=Cvu8gmh9fSkUGRv4C 6W5oPEKe7WfWKln/LUcmiXv3/M9zbn//Z8PbIfAKIQO5NOqKiDvQ0WitjRKu+BJF tXy6bFXyqZ3UcQm2UZ7jF44eQ4LGArrIF5tzUI5W1tYqAu5OdmM0k6JQY5rMqeS5 wH8LXIqYBqzIqGfMhtsz90gve4TXwLpDNZ8jYkOkhy4liEnEKZSyNEPoVWQA8HQc ne5iOkcIpsVeohc0nbLcQX0x8UFb4+V4GuAhzzA8f7LY4vHbgndteyBzUwqQIoth uQmYX8Eht5ujgoF/DRK+rBmJC1cFQgfTtcogdrDC4JjdxY33DeSUyhuFdLbmaiZd JdHcA== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=q3d+sa4riczg0Blm1MiljzpqSPeM3FV+c6ykZ21We HI=; b=NJXfxfvcydtNyI54EVXawT8Kb8q7iiu3T44oqAwqDjRXz0RiCxRYfQ8iy 7ih+Eliqh+MDrQ7NWArg5f/+b8GAvS+K4ncNV8R4MAYL/asKvU8o/WeTeLktvOni V6bhN3k/C6aFqBNuylEwCAms+u5DmfuU8+QuzOupwdJSO8ftFCtAG/PCAF4vaB6r OtbpqaxiBKcosRZqxZyjJpMtkQzmDZTmQi5IqBGtHTU8iR5oMr5kbaWesRCEJsKW Zz/YuMh2WjvGOiq1ICOvDCRm7WVncAvSRWEhT7G+SDVrEIkj9GGFntkxjMkBm0Kl oYRacJLqjLLCzd6D3TpCYTyQg9t+Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrjedugdeikecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepuffvfhfhkffffgggjggtgfesthekre dttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmqeenucffohhmrghinhepughighhithgrlhhotg gvrghnrdgtohhmpdhpohhsthhgrhgvshhqlhdrohhrghdpshhtrggtkhhovhgvrhhflhho fidrtghomhenucfkphepjedurddvuddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgrih hlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehl uhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 900D5E40FF; Fri, 22 Mar 2019 10:33:25 -0400 (EDT) Subject: Re: WAL Archive Cleanup? To: Foo Bar , pgsql-general@postgresql.org References: From: Adrian Klaver Message-ID: Date: Fri, 22 Mar 2019 07:33:24 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 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 3/21/19 11:51 AM, Foo Bar wrote: > Hello, > > We're evaluating PostgreSQL for use with Artifactory in our > environment.  PostgreSQL seems like the obvious choice because it > provides hot-standby replication.  I've followed several guides I've > found by googling "postgres replication how to" (i.e.: this one from > DigitalOcean > , > though I did it on Ubuntu 18 and CentOS 7), was able to make some test > inserts, and everything seemed to be working well. Postgres version? > > Fast forward two weeks, this cluster has been running but not seeing any > traffic.  And my master server has filled its archive directory.  I It's the standby that has not seen any traffic? > found an older thread > > that seemed to indicate that the wal_keep_segments is what was causing > psql to keep so many WAL files...  However, mine is set to 8, but there FYI, psql is the Postgres client program, Postgres(ql) is the server. > were thousands of log files... You also have max_replication_slots = 5 also. See: https://www.postgresql.org/docs/11/warm-standby.html#STREAMING-REPLICATION-SLOTS "Replication slots provide an automated way to ensure that the master does not remove WAL segments until they have been received by all standbys, and that the master does not remove rows which could cause a recovery conflict even when the standby is disconnected. In lieu of using replication slots, it is possible to prevent the removal of old WAL segments using wal_keep_segments, or by storing the segments in an archive using archive_command. However, these methods often result in retaining more WAL segments than required, whereas replication slots retain only the number of segments known to be needed. An advantage of these methods is that they bound the space requirement for pg_wal; there is currently no way to do this using replication slots." Looks like the slots take precedence. > > I was able to delete everything in the archive/ directory, start the > database back up, and there was no data loss... which is fine in the > lab, but if we're going to roll this out to production, I'm concerned > that we'll be continually running into this issue every couple weeks... > > There seems to be a pg_archivecleanup > command, > which I could run as a cron job, but something tells me that isn't the > recommended way as no literature I've found recommends this... Slots will clean up after themselves once the segments are no longer needed. The catch is that the segments need to be consumed by the standby. What needs to be determined here is why the standby never consumed the WAL's from the master? Do you still have the logs from the standby and do they show anything relevant? > > This SO thread > > seems to indicate that archive_cleanup_command can be run every "restart > point", but googling "psql restart point" brings me to this page > which a > ^F indicates does not mention a "restart point"...  So this /feels/ like > the configuration setting I want, but I can't find the documentation > that confirms it for me... > > So at this point I'm kinda stumped.  I could definitely add more space, > but if those WAL files are never cleaned up, even adding a 1TB Store for > the archive is just delaying the inevitable. > > Thanks! > -QBR > > These are my configs: > > postgresql.local.conf  - > > effective_cache_size=1500MB > shared_buffers=500MB > maintenance_work_mem=125MB > work_mem=5MB > temp_buffers=5MB > > postgresql.conf - > > listen_addresses = '0.0.0.0' > port = 5432 > max_connections = 100 > external_pid_file = '/hab/svc/postgresql/var/postgresql.pid' > authentication_timeout = 1min > max_files_per_process = 1000 > max_locks_per_transaction = 64 > logging_collector = on > log_directory = '/hab/svc/postgresql/var/pg_log' > log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' > log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,client=%h %r (%x:%e)' > log_min_messages = ERROR > datestyle = 'iso, mdy' > default_text_search_config = 'pg_catalog.english' > data_directory = '/hab/svc/postgresql/data/pgdata' > hba_file = '/hab/svc/postgresql/config/pg_hba.conf' > wal_level = hot_standby > wal_log_hints = 'on' > hot_standby = 'on' > hot_standby_feedback = true > max_wal_senders = 5 > max_replication_slots = 5 > checkpoint_completion_target = 0.9 > max_wal_size = 1GB > min_wal_size = 128MB > wal_keep_segments = 8 > log_checkpoints = on > log_lock_waits = on > log_temp_files = 0 > log_autovacuum_min_duration = 0 > track_activity_query_size = 2048 > track_io_timing=on > dynamic_shared_memory_type = 'none' > archive_mode = 'on' > archive_command = 'cp %p  /hab/svc/postgresql/data/archive/%f' > archive_timeout = '10min' > max_standby_archive_delay = '30s' > synchronous_commit = local > include '/hab/svc/postgresql/config/postgresql.local.conf' -- Adrian Klaver adrian.klaver@aklaver.com