Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb4tP-0000uq-JT for pgsql-admin@arkaria.postgresql.org; Thu, 26 Mar 2015 10:20:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yb4tP-00066F-1v for pgsql-admin@arkaria.postgresql.org; Thu, 26 Mar 2015 10:20:03 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yb4tN-000663-Kj for pgsql-admin@postgresql.org; Thu, 26 Mar 2015 10:20:01 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yb4tE-0005cc-Tw for pgsql-admin@postgresql.org; Thu, 26 Mar 2015 10:19:59 +0000 Received: from [192.168.43.202] ([213.209.123.92]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0MdFJL-1Yrmf13hyd-00IY13; Thu, 26 Mar 2015 11:19:48 +0100 Content-Type: multipart/signed; boundary="Apple-Mail=_535A14E9-8F03-4080-9726-0BB88A112899"; protocol="application/pgp-signature"; micalg=pgp-sha512 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: pg_xlog-files not deleted on a standby after accidental server crash From: Paul Dunkler In-Reply-To: Date: Thu, 26 Mar 2015 11:19:47 +0100 Cc: pgsql-admin@postgresql.org Message-Id: <5B4FA413-7B14-410B-A258-FEC290F35C96@xyrality.com> References: <18708694-CA4D-4047-ACE6-AFCDFD68B9CA@xyrality.com> <1606435B-21AB-418C-91DE-994966EA70A6@xyrality.com> To: naveen kumar X-Mailer: Apple Mail (2.1878.6) X-Provags-ID: V03:K0:Hg4ZtpnizzbquBDKmr8ts/WywdlhqCFr7C54UylWQ6iRuDnYndD sraKfm6EsFMYnlebEBxSB3YXgZDY/ZWwteVqTmRIbsQEH6D1j8C1uj1iLg1xd5YVvriI49a rFY8FE1nDv4h2xdYOkMRgahpiY4bOpOtQYGC3w1sEHN2rvh1JKyB+QEfB1WctKjfwbFO5Fu akYl+BK2WlX5aU/fgnMfg== X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org --Apple-Mail=_535A14E9-8F03-4080-9726-0BB88A112899 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 Hi there, > archive_cleanup_command =3D 'pg_archivecleanup %r' >=20 > Refer this, it will help you. > http://www.postgresql.org/docs/9.3/static/pgarchivecleanup.html No that can=B4t help me - sorry than it seems you didn't got my problem. The "data/pg_xlog" folder is filling up and not getting deleted on the = slave. I don't have any problem with the "archive" on slave. I don't = even have an "archive" on the slave... By the way, my restore-command on the slave is configured to get the = xlog_archives via rsync from the master=B4s xlog_archive if it needs so. = But thats only needed for startup recovery time after creating the slave = from a base backup - and that works like expected... > Thanks & Regards, > M Naveen Kuamr, > PostgreSQL Database Administrator,=20 > Mobile Number: +91 7755929449.=20 >=20 > On Wed, Mar 25, 2015 at 3:40 PM, Paul Dunkler = wrote: > Hi there, >=20 > thanks for your answer. We already have some "replay delay" checks = implemented in nagios, which is showing fine for this instance. >=20 > Anyway, i have tested all your commands (thanks, i didn't knew some of = them), but the result is still the same. Replication is fine and is not = lagging... But pg_xlog content is growing and growing and growing. >=20 > [root@ct-db1b pg_xlog]# ls -la | wc -l > 1479 >=20 >=20 > > I might be wrong, because Im one of the growing up guy in the = PostgreSQL world. But you can try this. > > > > I guess your salve is running properly, I think applying all WALs is = taking time. > > > > Bellow commands are use full check replication status. > > > > 1. pg_stat_replication view on master/primary server. > > > > postgres=3D# select * from pg_stat_replication ; >=20 > postgres=3D# select * from pg_stat_replication; > pid | usesysid | usename | application_name | client_addr | = client_hostname | client_port | backend_start | = backend_xmin | state | sent_location | write_location | = flush_location | replay_location | sync_priority | sync_state > = -------+----------+----------+------------------+-------------+-----------= ------+-------------+------------------------------+--------------+-------= ----+---------------+----------------+----------------+-----------------+-= --------------+------------ > 15919 | 10 | postgres | walreceiver | 172.16.0.2 | = | 50495 | 2015-03-24 09:46:12.59108+00 | | = streaming | CA/CB1345F8 | CA/CB1345F8 | CA/CB1345F8 | = CA/CB1345B8 | 0 | async > (1 row) >=20 > > 2. pg_is_in_recovery() : Function which tells whether standby is = still in recovery mode or not. > > > > postgres=3D# select pg_is_in_recovery(); >=20 > postgres=3D# select pg_is_in_recovery(); > pg_is_in_recovery > ------------------- > t > (1 row) >=20 > > 3. pg_last_xlog_receive_location: Function which tells location of = last transaction log which was streamed by Standby and also written on = standby disk. > > > > postgres=3D# select pg_last_xlog_receive_location(); > > 4. pg_last_xlog_replay_location: Function which tells last = transaction replayed during recovery process. > > > > postgres=3D# select pg_last_xlog_replay_location(); > > > > 5. pg_last_xact_replay_timestamp: This function tells about the time = stamp of last transaction which was replayed during recovery. Below is = an example: > > > > postgres=3D# select pg_last_xact_replay_timestamp(); >=20 > postgres=3D# select pg_last_xlog_receive_location(); select = pg_last_xlog_replay_location(); select pg_last_xact_replay_timestamp(); > pg_last_xlog_receive_location > ------------------------------- > CA/CAF27218 > (1 row) >=20 > pg_last_xlog_replay_location > ------------------------------ > CA/CAF27218 > (1 row) >=20 > pg_last_xact_replay_timestamp > ------------------------------- > 2015-03-25 09:54:54.766285+00 > (1 row) >=20 >=20 > > 6. Lags in Bytes: For calculating lags in bytes, users can use the = pg_stat_replication view on the master with the function = pg_xlog_location_diff function. > > > > postgres=3D# select = pg_xlog_location_diff(pg_stat_replication.sent_location, = pg_stat_replication.replay_location); >=20 > postgres=3D# SELECT client_hostname, client_addr, = pg_xlog_location_diff(pg_stat_replication.sent_location, = pg_stat_replication.replay_location) AS byte_lag FROM = pg_stat_replication; > client_hostname | client_addr | byte_lag > -----------------+-------------+---------- > | 172.16.0.2 | 13024 > (1 row) >=20 > > 7.Calculating lags in Seconds. The following is SQL, which most = people uses to find the lag in seconds: > > > > SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location()THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) > > END AS log_delay; >=20 > postgres=3D# SELECT CASE WHEN pg_last_xlog_receive_location() =3D = pg_last_xlog_replay_location()THEN 0 ELSE EXTRACT (EPOCH FROM now() - = pg_last_xact_replay_timestamp()) > END AS log_delay; > log_delay > ----------- > 0 > (1 row) >=20 > > 8.If the slave is up in hot standby mode, you can tell the time in = seconds the delay of transactions applied on the slave with this query: > > > > postgres=3D# select now() - pg_last_xact_replay_timestamp() AS = replication_delay; >=20 > postgres=3D# select now() - pg_last_xact_replay_timestamp() AS = replication_delay; > replication_delay > ------------------- > 00:00:00.296506 > (1 row) >=20 > > And please verify archive_cleanup_command in recovery.conf on slave. >=20 > I don't use this command on any slaves... >=20 > > > > > > Thanks & Regards, > > M Naveen Kuamr, > > PostgreSQL Database Administrator, > > Mobile Number: +91 7755929449. > > > > On Tue, Mar 24, 2015 at 9:47 PM, Paul Dunkler = wrote: > > Hi there, > > > > i am currently encountering a weird problem: > > > > 3 Days ago we had an accidental server crash on one of our database = servers (system just restarted). > > After it was up again, i restarted databases (we are running 4 = instances of postgres on a 512GB / 64 Processor server). All databases = came up fine again. > > Afterwards i restarted the slave postgres instances (running on = another physical server) and they could recover correctly and went ahead = with receiving WAL via streaming replication. All fine so far. > > > > Then i realized that only on 1 of the 4 slave instances, the = WAL-File count under data/pg_xlog was raising and raising, seems like = WAL files are not reused / deleted by postgres. > > Afterwards i tried different things: > > 1. Restarted the slave multiple times without any effect on the xlog = behaviour > > 2. Setting up the slave again from a fresh base backup of the master = instance > > 3. Checking file permissions, even tried manually deleting a = WAL-File under data/pg_xlog (which worked) > > > > Now i'm running out of ideas why these files are not reused/deleted = anymore. > > I don't see any errors in the logfiles (not on slave, not on = master). > > > > Slave is only showing normal "restartpoint" logs: > >> Mar 24 10:51:10 ct-db1b ct-db1-1[65432]: [3-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 10:53:42 ct-db1b ct-db1-1[65432]: [4-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 21264 buffers (0.4%); 0 = transaction log file(s) added, 0 removed, 16 recycled; write=3D149.345 = s, sync=3D2.217 s, total=3D151.682 s; sync files=3D1156, longest=3D0.213 = s, average=3D0.001 s > >> Mar 24 10:53:42 ct-db1b ct-db1-1[65432]: [5-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/E9AD3258 > >> Mar 24 10:53:42 ct-db1b ct-db1-1[65432]: [5-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 09:53:42.247769+00 > >> Mar 24 10:56:10 ct-db1b ct-db1-1[65432]: [6-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 10:58:41 ct-db1b ct-db1-1[65432]: [7-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 6402 buffers (0.1%); 0 = transaction log file(s) added, 0 removed, 3 recycled; write=3D149.516 s, = sync=3D1.101 s, total=3D150.757 s; sync files=3D729, longest=3D0.160 s, = average=3D0.001 s > >> Mar 24 10:58:41 ct-db1b ct-db1-1[65432]: [8-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/EDA836D8 > >> Mar 24 10:58:41 ct-db1b ct-db1-1[65432]: [8-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 09:58:40.611415+00 > >> Mar 24 11:01:10 ct-db1b ct-db1-1[65432]: [9-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 11:03:41 ct-db1b ct-db1-1[65432]: [10-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 11746 buffers (0.2%); 0 = transaction log file(s) added, 0 removed, 5 recycled; write=3D149.652 s, = sync=3D0.936 s, total=3D150.725 s; sync files=3D672, longest=3D0.147 s, = average=3D0.001 s > >> Mar 24 11:03:41 ct-db1b ct-db1-1[65432]: [11-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/F046DA18 > >> Mar 24 11:03:41 ct-db1b ct-db1-1[65432]: [11-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 10:03:40.914148+00 > >> Mar 24 11:06:10 ct-db1b ct-db1-1[65432]: [12-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 11:08:41 ct-db1b ct-db1-1[65432]: [13-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 11155 buffers (0.2%); 0 = transaction log file(s) added, 0 removed, 4 recycled; write=3D149.780 s, = sync=3D1.184 s, total=3D151.080 s; sync files=3D758, longest=3D0.184 s, = average=3D0.001 s > >> Mar 24 11:08:41 ct-db1b ct-db1-1[65432]: [14-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/F3C51B40 > >> Mar 24 11:08:41 ct-db1b ct-db1-1[65432]: [14-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 10:08:41.087379+00 > >> Mar 24 11:11:10 ct-db1b ct-db1-1[65432]: [15-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 11:13:41 ct-db1b ct-db1-1[65432]: [16-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 12602 buffers (0.2%); 0 = transaction log file(s) added, 0 removed, 2 recycled; write=3D149.632 s, = sync=3D1.309 s, total=3D151.067 s; sync files=3D728, longest=3D0.203 s, = average=3D0.001 s > >> Mar 24 11:13:41 ct-db1b ct-db1-1[65432]: [17-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/F93AC8F0 > >> Mar 24 11:13:41 ct-db1b ct-db1-1[65432]: [17-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 10:13:41.168975+00 > >> Mar 24 11:16:10 ct-db1b ct-db1-1[65432]: [18-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 11:18:41 ct-db1b ct-db1-1[65432]: [19-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 10234 buffers (0.2%); 0 = transaction log file(s) added, 0 removed, 0 recycled; write=3D149.411 s, = sync=3D1.175 s, total=3D150.703 s; sync files=3D821, longest=3D0.142 s, = average=3D0.001 s > >> Mar 24 11:18:41 ct-db1b ct-db1-1[65432]: [20-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C3/FDD61320 > >> Mar 24 11:18:41 ct-db1b ct-db1-1[65432]: [20-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 10:18:41.052593+00 > >> Mar 24 11:21:10 ct-db1b ct-db1-1[65432]: [21-1] db=3D, user=3D, = host=3D LOG: restartpoint starting: time > >> Mar 24 11:23:40 ct-db1b ct-db1-1[65432]: [22-1] db=3D, user=3D, = host=3D LOG: restartpoint complete: wrote 9105 buffers (0.2%); 0 = transaction log file(s) added, 0 removed, 0 recycled; write=3D149.598 s, = sync=3D0.842 s, total=3D150.579 s; sync files=3D687, longest=3D0.061 s, = average=3D0.001 s > >> Mar 24 11:23:40 ct-db1b ct-db1-1[65432]: [23-1] db=3D, user=3D, = host=3D LOG: recovery restart point at C4/290A078 > >> Mar 24 11:23:40 ct-db1b ct-db1-1[65432]: [23-2] db=3D, user=3D, = host=3D DETAIL: last completed transaction was at log time 2015-03-24 = 10:23:40.446308+00 > > > > Postgres-Version: > > > >> postgres=3D# select version(); > >> version > >> = --------------------------------------------------------------------------= ------------------------------------ > >> PostgreSQL 9.4.1 on x86_64-unknown-linux-gnu, compiled by gcc = (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4), 64-bit > >> (1 row) > > > > I would really appreciate somebodies advice on this. > > > > Thanks in advance. -- Mit freundlichen Gr=FC=DFen / Kind regards Paul Dunkler --Apple-Mail=_535A14E9-8F03-4080-9726-0BB88A112899 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQEcBAEBCgAGBQJVE91DAAoJEFOUBEe3kXcabuwH/2lO6NDLR65tNojC9vz/+4do aFXKmBRLVgxjQMCsosCSZ4bzOd/TTe2jGE8qclj6A5Ui+c1cRI2kGWFFMCx1s8Uv h6A8RngAF0TJrB/dNyc2NwNxqslM3bwAjO+6oqKdlmCZVfB5Gy+GD/HiNfeePpCS iduRWl3hXEHGPy+iULqutdRH+U4ThRLqMMVVj9nR2w/DuRpVlR/msBkRhgKAo8cZ jiqffK0UHNoqBMK4UCwt9yjBpfNs55LVCPMuAjVjjE4HaT2umPyVH1mBpKTnN8By +POI7Eo6HiB0g9ULrl4L/od94rSlU/gJBO1LE8v6WqtM0hEADhB6YFAKt7GRdmA= =Yxoe -----END PGP SIGNATURE----- --Apple-Mail=_535A14E9-8F03-4080-9726-0BB88A112899--