Old WAL files under pg_xlog not getting delete

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
Hi,

I am trying to understand why postgresql not removing WAL logs under pg_xlog in 9.6, below are my settings

max_wal_size= 1GB
wal_keep_segments=500

pg_xlog/|wc -l
506

pg_xlog]# du -sh .
7.9G .

and i have files from last year Nov

ls -ltr |head
total 8257540
-rw------- 1 postgres postgres 16777216 Nov 21 16:32 0000000100000003000000BD
-rw------- 1 postgres postgres 16777216 Nov 21 16:32 0000000100000001000000C6
-rw------- 1 postgres postgres 16777216 Nov 21 16:33 0000000100000001000000C7
-rw------- 1 postgres postgres 16777216 Nov 21 16:33 0000000100000001000000C8
-rw------- 1 postgres postgres 16777216 Nov 21 16:34 0000000100000001000000C9
-rw------- 1 postgres postgres 16777216 Nov 21 16:34 0000000100000001000000CA
-rw------- 1 postgres postgres 16777216 Nov 21 16:35 0000000100000001000000CB
-rw------- 1 postgres postgres 16777216 Nov 21 16:35 0000000100000001000000CC
-rw------- 1 postgres postgres 16777216 Nov 21 16:36 0000000100000001000000CD

Here is my controldata output


pg_control version number:            960
Catalog version number:               201608131
Database system identifier:           6620833305040850458
Database cluster state:               in production
pg_control last modified:             Wed 30 Jan 2019 05:49:44 PM EST
Latest checkpoint location:           3/BC000098
Prior checkpoint location:            3/BA000220
Latest checkpoint's REDO location:    3/BC000060
Latest checkpoint's REDO WAL file:    0000000100000003000000BC

and i dont see postgresql using any of the other files.

 sudo lsof |grep pg_xlog
bash      28969                root  cwd       DIR            202,112      32768    4063264 /opt/pgdata/pg_xlog
postgres  29571              postgres    3u      REG            202,112   16777216    4068479 /opt/pgdata/pg_xlog/0000000100000003000000BC
postgres  29573              postgres    3u      REG            202,112   16777216    4068479 /opt/pgdata/pg_xlog/0000000100000003000000BC

Any idea why those old files are not getting removed? How can i recycle them?

Thanks,
Ram


Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

David G Johnston
On Wed, Jan 30, 2019 at 3:58 PM rammohan ganapavarapu
<[hidden email]> wrote:
> I am trying to understand why postgresql not removing WAL logs under pg_xlog in 9.6, below are my settings
>
> wal_keep_segments=500
>
> pg_xlog/|wc -l
> 506

You told PostgreSQL to keep 500 files and it has (the number kept
apparently fluctuates a little bit).

https://www.postgresql.org/docs/11/wal-configuration.html

David J.

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Ron-2


On 1/30/19 5:10 PM, David G. Johnston wrote:

> On Wed, Jan 30, 2019 at 3:58 PM rammohan ganapavarapu
> <[hidden email]> wrote:
>> I am trying to understand why postgresql not removing WAL logs under pg_xlog in 9.6, below are my settings
>>
>> wal_keep_segments=500
>>
>> pg_xlog/|wc -l
>> 506
> You told PostgreSQL to keep 500 files and it has (the number kept
> apparently fluctuates a little bit).
>
> https://www.postgresql.org/docs/11/wal-configuration.html

Plus the ".", ".." and archive_status directories, and lost+found if pg_xlog
is it's own partition.  That's four of the unknown six.  Add a .backup file
or two and all 506 files are accounted for.

--
Angular momentum makes the world go 'round.

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Alvaro Herrera-9
On 2019-Jan-30, Ron wrote:

> Plus the ".", ".." and archive_status directories, and lost+found if pg_xlog
> is it's own partition.  That's four of the unknown six.  Add a .backup file
> or two and all 506 files are accounted for.

Hmm ... I would recommend to keep the xlog files in a subdir, not the
root of the filesystem.  So the lost+found would be, at the most, a
sibling of pg_xlog, not inside it.  Otherwise, it seems too easy to get
in trouble if for whatever reason the filesystem is not mounted, your
database starts writing files in it, and the filesystem is mounted
later.  Whatever files got written before mounting would be misteriously
"missing", and few people think to unmount the FS to see if they are in
the underlying filesystem.

Then again, if you read this advice then you're safe because next time
this happens to you, you'll remember to unmount to check, so you can
safely ignore me.  Go figure.

--
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

David G Johnston
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
Thank you all, but irrespective of count i have why is it keeping old files? and how is it using those files? Is there any processes that can flush or remove those files?

On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Ron-2
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Scott Ribe-2
In reply to this post by rammohan ganapavarapu
> On Jan 30, 2019, at 8:09 PM, rammohan ganapavarapu <[hidden email]> wrote:
>
> why is it keeping old files?

Because you configured it to:

wal_keep_segments=500


Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
Got it thank you, so it is depends on wal_keep_seg irrespective to age of the file.

On Wed, Jan 30, 2019, 7:19 PM Scott Ribe <[hidden email] wrote:
> On Jan 30, 2019, at 8:09 PM, rammohan ganapavarapu <[hidden email]> wrote:
>
> why is it keeping old files?

Because you configured it to:

wal_keep_segments=500

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

David G Johnston
In reply to this post by rammohan ganapavarapu
On Wed, Jan 30, 2019 at 8:09 PM rammohan ganapavarapu
<[hidden email]> wrote:
> Thank you all, but irrespective of count i have why is it keeping old files? and how is it using those files? Is there any processes that can flush or remove those files?

Others are answering these questions but I have one of my own.  Is
this database being backed up?

David J.

Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
Nope, it's non prod db. 

On Wed, Jan 30, 2019, 7:44 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 8:09 PM rammohan ganapavarapu
<[hidden email]> wrote:
> Thank you all, but irrespective of count i have why is it keeping old files? and how is it using those files? Is there any processes that can flush or remove those files?

Others are answering these questions but I have one of my own.  Is
this database being backed up?

David J.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
In reply to this post by Ron-2
Ron,

I have changed the wal_keep_segments=100 and restarted the postgresql processes but i still see 500+ files under pg_xlog, i had to run checkpoint manually to clean.

Ram

On Wed, Jan 30, 2019 at 7:19 PM Ron <[hidden email]> wrote:
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Jay at Verizon
Ram,

Remember that keep_wal_segments is a minimum setting, not a maximum one. It’s telling the database to maintain at least that many segments. Plus, check how you’ve set the archive_command. If that’s not correct, nothing will remove the WAL files.
Jay

Sent from my iPhone

On Jan 31, 2019, at 11:22 AM, rammohan ganapavarapu <[hidden email]> wrote:

Ron,

I have changed the wal_keep_segments=100 and restarted the postgresql processes but i still see 500+ files under pg_xlog, i had to run checkpoint manually to clean.

Ram

On Wed, Jan 30, 2019 at 7:19 PM Ron <[hidden email]> wrote:
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Ron-2
In reply to this post by rammohan ganapavarapu
"i had to run checkpoint manually to clean."

I see no problem with that.  Postgres would have checkpointed sooner or later.

On 1/31/19 10:22 AM, rammohan ganapavarapu wrote:
Ron,

I have changed the wal_keep_segments=100 and restarted the postgresql processes but i still see 500+ files under pg_xlog, i had to run checkpoint manually to clean.

Ram

On Wed, Jan 30, 2019 at 7:19 PM Ron <[hidden email]> wrote:
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

rammohan ganapavarapu
In reply to this post by Jay at Verizon
Jay,

If there is no max limit on how many files can be on FS at some point it will fill up disk space right? so you are saying if we dont have correct archive_command , postgres will do nothing? in my case i did not set archive_command. But from postgres documentation "The number of WAL segment files in pg_xlog directory depends on min_wal_sizemax_wal_size and the amount of WAL generated in previous checkpoint cycles. When old log segment files are no longer needed, they are removed or recycled (that is, renamed to become future segments in the numbered sequence)."  This statement is little confusing me with what you have said: "If that’s not correct, nothing will remove the WAL files.".

Sorry if i am asking silly questions :(

Thanks,
Ram

On Thu, Jan 31, 2019 at 8:37 AM John Scalia <[hidden email]> wrote:
Ram,

Remember that keep_wal_segments is a minimum setting, not a maximum one. It’s telling the database to maintain at least that many segments. Plus, check how you’ve set the archive_command. If that’s not correct, nothing will remove the WAL files.
Jay

Sent from my iPhone

On Jan 31, 2019, at 11:22 AM, rammohan ganapavarapu <[hidden email]> wrote:

Ron,

I have changed the wal_keep_segments=100 and restarted the postgresql processes but i still see 500+ files under pg_xlog, i had to run checkpoint manually to clean.

Ram

On Wed, Jan 30, 2019 at 7:19 PM Ron <[hidden email]> wrote:
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

Keith
The archive_command is only for making secondary copies of the WAL files and doesn't control the files in the pg_xlogs folder itself (pg_wal in PG10+). Secondary uses could be backups or non-streaming replicas that just replay the WAL instead of connecting back to the primary.

What they were saying is that if you  do have an archive_command set and it fails to run, postgresql will not remove the WAL files in pg_xlog until the archive_command successfully runs or is removed. It does this so that your backups or replicas don't lose WAL files in the time period that the archive_command is failing.

Keith


On Thu, Jan 31, 2019 at 1:52 PM rammohan ganapavarapu <[hidden email]> wrote:
Jay,

If there is no max limit on how many files can be on FS at some point it will fill up disk space right? so you are saying if we dont have correct archive_command , postgres will do nothing? in my case i did not set archive_command. But from postgres documentation "The number of WAL segment files in pg_xlog directory depends on min_wal_sizemax_wal_size and the amount of WAL generated in previous checkpoint cycles. When old log segment files are no longer needed, they are removed or recycled (that is, renamed to become future segments in the numbered sequence)."  This statement is little confusing me with what you have said: "If that’s not correct, nothing will remove the WAL files.".

Sorry if i am asking silly questions :(

Thanks,
Ram

On Thu, Jan 31, 2019 at 8:37 AM John Scalia <[hidden email]> wrote:
Ram,

Remember that keep_wal_segments is a minimum setting, not a maximum one. It’s telling the database to maintain at least that many segments. Plus, check how you’ve set the archive_command. If that’s not correct, nothing will remove the WAL files.
Jay

Sent from my iPhone

On Jan 31, 2019, at 11:22 AM, rammohan ganapavarapu <[hidden email]> wrote:

Ron,

I have changed the wal_keep_segments=100 and restarted the postgresql processes but i still see 500+ files under pg_xlog, i had to run checkpoint manually to clean.

Ram

On Wed, Jan 30, 2019 at 7:19 PM Ron <[hidden email]> wrote:
On 1/30/19 9:09 PM, rammohan ganapavarapu wrote:
Thank you all, but irrespective of count i have why is it keeping old files?

Because you're telling it to!!

max_wal_size= 1GB
wal_keep_segments=500

and how is it using those files? Is there any processes that can flush or remove those files?

Change the parameter and restart the server...


On Wed, Jan 30, 2019, 4:11 PM David G. Johnston <[hidden email] wrote:
On Wed, Jan 30, 2019 at 5:00 PM Alvaro Herrera <[hidden email]> wrote:
> Hmm ... I would recommend to keep the xlog files in a subdir, not the
> root of the filesystem.

They are in a subdir (under /opt/pgdata), and the OP seems likely to
have omitted the self/parent hidden directories during his check as
well.  Plus per the docs we actually expect 501 so there isn't a need
to account for 6 extra, just 5.

Dave


--
Angular momentum makes the world go 'round.
Reply | Threaded
Open this post in threaded view
|

Re: Old WAL files under pg_xlog not getting delete

David G Johnston
In reply to this post by rammohan ganapavarapu
On Thu, Jan 31, 2019 at 11:52 AM rammohan ganapavarapu
<[hidden email]> wrote:
> But from postgres documentation "The number of WAL segment files in pg_xlog directory depends on min_wal_size, max_wal_size and the amount of WAL generated in previous checkpoint cycles.

You are quoting from the v10+ documentation but using 9.6

You also need to read about archiving[1] since when it is enabled the
rules for WAL retention are modified to meet the needs of archiving,
specifically WAL cannot be removed from the host system until the
host's archiving system knows that the same file exists in the
archive.

[1] https://www.postgresql.org/docs/9.6/continuous-archiving.html#BACKUP-ARCHIVING-WAL

David J.