pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
why select count(*) consumes wal logs
15+ messages / 8 participants
[nested] [flat]

* why select count(*) consumes wal logs
@ 2018-11-06 17:04 Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:12 ` Re: why select count(*) consumes wal logs Michael Nolan <htfoot@gmail.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 15+ messages in thread

From: Ravi Krishna @ 2018-11-06 17:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

PG 10.5

I loaded 133 million rows to a wide table (more than 100 cols) via COPY. The table has
no index at this time. Since I am the only user I don't see any other activity.
Now when I run select count(*) on the table where I just loaded data, it runs for ever, 
more than 10min and still running. Intrigued, I checked locks and saw nothing.  Then I noticed something
strange.  When select count(*) runs, PG is writing to wal_logs, and that too a large amount. Why?  
I suspect vaccum is getting triggered, but this is a brand new table with no updates. So it should not.

Is there a SQL to peek into what PG is doing to write so much to WAL logs ?





^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
@ 2018-11-06 17:12 ` Michael Nolan <htfoot@gmail.com>
  2018-11-06 17:19   ` Re: why select count(*) consumes wal logs Ron <ronljohnsonjr@gmail.com>
  1 sibling, 1 reply; 15+ messages in thread

From: Michael Nolan @ 2018-11-06 17:12 UTC (permalink / raw)
  To: srkrishna1@aol.com; +Cc: pgsql-general@lists.postgresql.org

On Tue, Nov 6, 2018 at 11:08 AM Ravi Krishna <srkrishna1@aol.com> wrote:

> PG 10.5
>
> I loaded 133 million rows to a wide table (more than 100 cols) via COPY.
>

It's always a good idea after doing a large scale data load to do a vacuum
analyze on the table (or the entire database.)
--
Mike Nolan

^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:12 ` Re: why select count(*) consumes wal logs Michael Nolan <htfoot@gmail.com>
@ 2018-11-06 17:19   ` Ron <ronljohnsonjr@gmail.com>
  2018-11-06 17:38     ` RE: why select count(*) consumes wal logs Kumar, Virendra <Virendra.Kumar@guycarp.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Ron @ 2018-11-06 17:19 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 11/06/2018 11:12 AM, Michael Nolan wrote:
> On Tue, Nov 6, 2018 at 11:08 AM Ravi Krishna <srkrishna1@aol.com 
> <mailto:srkrishna1@aol.com>> wrote:
>
>     PG 10.5
>
>     I loaded 133 million rows to a wide table (more than 100 cols) via COPY.
>
>
> It's always a good idea after doing a large scale data load to do a vacuum 
> analyze on the table (or the entire database.)
>

I understand the need to ANALYZE (populate the histograms needed by the 
dynamic optimizer), but why VACUUM (which is recommended after updates and 
deletes).

Thanks

-- 
Angular momentum makes the world go 'round.

^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* RE: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:12 ` Re: why select count(*) consumes wal logs Michael Nolan <htfoot@gmail.com>
  2018-11-06 17:19   ` Re: why select count(*) consumes wal logs Ron <ronljohnsonjr@gmail.com>
@ 2018-11-06 17:38     ` Kumar, Virendra <Virendra.Kumar@guycarp.com>
  0 siblings, 0 replies; 15+ messages in thread

From: Kumar, Virendra @ 2018-11-06 17:38 UTC (permalink / raw)
  To: Ron <ronljohnsonjr@gmail.com>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

I concord.
Why VACUUM when there is no update or deletes.

Regards,
Virendra

From: Ron [mailto:ronljohnsonjr@gmail.com]
Sent: Tuesday, November 06, 2018 12:20 PM
To: pgsql-general@lists.postgresql.org
Subject: Re: why select count(*) consumes wal logs

On 11/06/2018 11:12 AM, Michael Nolan wrote:

On Tue, Nov 6, 2018 at 11:08 AM Ravi Krishna <srkrishna1@aol.com<mailto:srkrishna1@aol.com>> wrote:
PG 10.5

I loaded 133 million rows to a wide table (more than 100 cols) via COPY.

It's always a good idea after doing a large scale data load to do a vacuum analyze on the table (or the entire database.)


I understand the need to ANALYZE (populate the histograms needed by the dynamic optimizer), but why VACUUM (which is recommended after updates and deletes).

Thanks
--
Angular momentum makes the world go 'round.

________________________________

This message is intended only for the use of the addressee and may contain
information that is PRIVILEGED AND CONFIDENTIAL.

If you are not the intended recipient, you are hereby notified that any
dissemination of this communication is strictly prohibited. If you have
received this communication in error, please erase all copies of the message
and its attachments and notify the sender immediately. Thank you.


^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
@ 2018-11-06 17:40 ` Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 18:27   ` Re: why select count(*) consumes wal logs Michael Nolan <htfoot@gmail.com>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
  1 sibling, 2 replies; 15+ messages in thread

From: Tom Lane @ 2018-11-06 17:40 UTC (permalink / raw)
  To: Ravi Krishna <srkrishna1@aol.com>; +Cc: pgsql-general@lists.postgresql.org

Ravi Krishna <srkrishna1@aol.com> writes:
> I loaded 133 million rows to a wide table (more than 100 cols) via COPY. The table has
> no index at this time. Since I am the only user I don't see any other activity.
> Now when I run select count(*) on the table where I just loaded data, it runs for ever, 
> more than 10min and still running. Intrigued, I checked locks and saw nothing.  Then I noticed something
> strange.  When select count(*) runs, PG is writing to wal_logs, and that too a large amount. Why?  

That represents setting the yes-this-row-is-committed hint bits on the
newly loaded rows.  The first access to any such row will set that bit,
whether it's a select or a VACUUM or whatever.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-11-06 18:27   ` Michael Nolan <htfoot@gmail.com>
  2018-11-06 18:41     ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 15+ messages in thread

From: Michael Nolan @ 2018-11-06 18:27 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: srkrishna1@aol.com; pgsql-general@lists.postgresql.org

On Tue, Nov 6, 2018 at 11:40 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

>
> That represents setting the yes-this-row-is-committed hint bits on the
> newly loaded rows.  The first access to any such row will set that bit,
> whether it's a select or a VACUUM or whatever.
>
> Tom, does that include ANALYZE?
--
Mike Nolan

^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 18:27   ` Re: why select count(*) consumes wal logs Michael Nolan <htfoot@gmail.com>
@ 2018-11-06 18:41     ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 15+ messages in thread

From: Tom Lane @ 2018-11-06 18:41 UTC (permalink / raw)
  To: Michael Nolan <htfoot@gmail.com>; +Cc: srkrishna1@aol.com; pgsql-general@lists.postgresql.org

Michael Nolan <htfoot@gmail.com> writes:
> On Tue, Nov 6, 2018 at 11:40 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> That represents setting the yes-this-row-is-committed hint bits on the
>> newly loaded rows.  The first access to any such row will set that bit,
>> whether it's a select or a VACUUM or whatever.

> Tom, does that include ANALYZE?

Yes, but remember that ANALYZE doesn't scan the whole table; it'll only
set the bit on rows it visits.

(I forget at the moment if it's guaranteed to set the bit on all rows
in each page it examines, or only on the rows it selects to sample.
But in any case it will not examine every page in the table.)

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
@ 2018-11-06 21:31   ` Bruno Lavoie <bl@brunol.com>
  2018-11-07 08:16     ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  1 sibling, 1 reply; 15+ messages in thread

From: Bruno Lavoie @ 2018-11-06 21:31 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Ravi Krishna <srkrishna1@aol.com>; pgsql-general@lists.postgresql.org

Le mar. 6 nov. 2018 12:40 PM, Tom Lane <tgl@sss.pgh.pa.us> a écrit :

> Ravi Krishna <srkrishna1@aol.com> writes:
> > I loaded 133 million rows to a wide table (more than 100 cols) via COPY.
> The table has
> > no index at this time. Since I am the only user I don't see any other
> activity.
> > Now when I run select count(*) on the table where I just loaded data, it
> runs for ever,
> > more than 10min and still running. Intrigued, I checked locks and saw
> nothing.  Then I noticed something
> > strange.  When select count(*) runs, PG is writing to wal_logs, and that
> too a large amount. Why?
>
> That represents setting the yes-this-row-is-committed hint bits on the
> newly loaded rows.  The first access to any such row will set that bit,
> whether it's a select or a VACUUM or whatever.
>
>                         regards, tom lane
>


And IIRC, it can generate a high WAL traffic since the first page change
after a checkpoint is done with full page write. And you said that it's
happening on a big table with wide rows....

>

^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* RE: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
@ 2018-11-07 08:16     ` Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 11:54       ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Steven Winfield @ 2018-11-07 08:16 UTC (permalink / raw)
  To: Ravi Krishna <srkrishna1@aol.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

As long as you don’t have page checksums turned on, you can prevent this by turning off wal_log_hints.

Steve.



This email is confidential. If you are not the intended recipient, please advise us immediately and delete this message. 
The registered name of Cantab- part of GAM Systematic is Cantab Capital Partners LLP. 
See - http://www.gam.com/en/Legal/Email+disclosures+EU for further information on confidentiality, the risks of non-secure electronic communication, and certain disclosures which we are required to make in accordance with applicable legislation and regulations. 
If you cannot access this link, please notify us by reply message and we will send the contents to you.

GAM Holding AG and its subsidiaries (Cantab – GAM Systematic) will collect and use information about you in the course of your interactions with us. 
Full details about the data types we collect and what we use this for and your related rights is set out in our online privacy policy at https://www.gam.com/en/legal/privacy-policy. 
Please familiarise yourself with this policy and check it from time to time for updates as it supplements this notice.


^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
  2018-11-07 08:16     ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
@ 2018-11-07 11:54       ` Ravi Krishna <srkrishna1@aol.com>
  2018-11-07 12:38         ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Ravi Krishna @ 2018-11-07 11:54 UTC (permalink / raw)
  To: Steven.Winfield@cantabcapital.com; +Cc: pgsql-general@lists.postgresql.org

> As long as you don’t have page checksums turned on, 
> you can prevent this by turning off wal_log_hints.
 
  


I did not run initdb. How to find out which parameter were used with initdb. For page checksums 
to be on, it must have been run with -k option.

Our wal_log_hints is left at default which means off.

thanks




^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* RE: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
  2018-11-07 08:16     ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 11:54       ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
@ 2018-11-07 12:38         ` Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 14:10           ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  0 siblings, 1 reply; 15+ messages in thread

From: Steven Winfield @ 2018-11-07 12:38 UTC (permalink / raw)
  To: Ravi Krishna <srkrishna1@aol.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

> How to find out which parameter were used with initdb

pg_controldata -D <datadir> | grep sum
...should give you something like:
Data page checksum version:           0
...and 0 means off.

Similarly, from SQL:
select data_page_checksum_version from pg_control_init()

Steve.



This email is confidential. If you are not the intended recipient, please advise us immediately and delete this message. 
The registered name of Cantab- part of GAM Systematic is Cantab Capital Partners LLP. 
See - http://www.gam.com/en/Legal/Email+disclosures+EU for further information on confidentiality, the risks of non-secure electronic communication, and certain disclosures which we are required to make in accordance with applicable legislation and regulations. 
If you cannot access this link, please notify us by reply message and we will send the contents to you.

GAM Holding AG and its subsidiaries (Cantab – GAM Systematic) will collect and use information about you in the course of your interactions with us. 
Full details about the data types we collect and what we use this for and your related rights is set out in our online privacy policy at https://www.gam.com/en/legal/privacy-policy. 
Please familiarise yourself with this policy and check it from time to time for updates as it supplements this notice.


^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
  2018-11-07 08:16     ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 11:54       ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-07 12:38         ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
@ 2018-11-07 14:10           ` Ravi Krishna <srkrishna1@aol.com>
  2018-11-07 14:43             ` Re: why select count(*) consumes wal logs Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 1 reply; 15+ messages in thread

From: Ravi Krishna @ 2018-11-07 14:10 UTC (permalink / raw)
  To: Steven.Winfield@cantabcapital.com; +Cc: pgsql-general@lists.postgresql.org


> select data_page_checksum_version from pg_control_init()

returned 1.  So we have page_checksum turned on, and wal_log_hints off.




^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
  2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-06 17:40 ` Re: why select count(*) consumes wal logs Tom Lane <tgl@sss.pgh.pa.us>
  2018-11-06 21:31   ` Re: why select count(*) consumes wal logs Bruno Lavoie <bl@brunol.com>
  2018-11-07 08:16     ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 11:54       ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
  2018-11-07 12:38         ` RE: why select count(*) consumes wal logs Steven Winfield <Steven.Winfield@cantabcapital.com>
  2018-11-07 14:10           ` Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
@ 2018-11-07 14:43             ` Thomas Kellerer <spam_eater@gmx.net>
  0 siblings, 0 replies; 15+ messages in thread

From: Thomas Kellerer @ 2018-11-07 14:43 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Ravi Krishna schrieb am 07.11.2018 um 15:10:
> 
>> select data_page_checksum_version from pg_control_init()
> 
> returned 1.  So we have page_checksum turned on, and wal_log_hints off.

If page_checksum is enabled, then wal_log_hints is ignored (or actually always assumed "on")


 





^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
@ 2018-11-06 17:05 Ravi Krishna <srkrishna1@aol.com>
  0 siblings, 0 replies; 15+ messages in thread

From: Ravi Krishna @ 2018-11-06 17:05 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Must be something to do with Vaccum as the second time I ran the SQL, it did not consume WAL logs.




^ permalink  raw  reply  [nested|flat] 15+ messages in thread

* Re: why select count(*) consumes wal logs
@ 2018-11-06 17:57 Ravi Krishna <srkrishna1@aol.com>
  0 siblings, 0 replies; 15+ messages in thread

From: Ravi Krishna @ 2018-11-06 17:57 UTC (permalink / raw)
  To: tgl@sss.pgh.pa.us; +Cc: pgsql-general@lists.postgresql.org

>That represents setting the yes-this-row-is-committed hint bits on the
>newly loaded rows.  The first access to any such row will set that bit,
>whether it's a select or a VACUUM or whatever.

yes now I recollect reading this in a blog.  Thanks Tom.




^ permalink  raw  reply  [nested|flat] 15+ messages in thread


end of thread, other threads:[~2018-11-07 14:43 UTC | newest]

Thread overview: 15+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-06 17:04 why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
2018-11-06 17:12 ` Michael Nolan <htfoot@gmail.com>
2018-11-06 17:19   ` Ron <ronljohnsonjr@gmail.com>
2018-11-06 17:38     ` Kumar, Virendra <Virendra.Kumar@guycarp.com>
2018-11-06 17:40 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-11-06 18:27   ` Michael Nolan <htfoot@gmail.com>
2018-11-06 18:41     ` Tom Lane <tgl@sss.pgh.pa.us>
2018-11-06 21:31   ` Bruno Lavoie <bl@brunol.com>
2018-11-07 08:16     ` Steven Winfield <Steven.Winfield@cantabcapital.com>
2018-11-07 11:54       ` Ravi Krishna <srkrishna1@aol.com>
2018-11-07 12:38         ` Steven Winfield <Steven.Winfield@cantabcapital.com>
2018-11-07 14:10           ` Ravi Krishna <srkrishna1@aol.com>
2018-11-07 14:43             ` Thomas Kellerer <spam_eater@gmx.net>
2018-11-06 17:05 Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>
2018-11-06 17:57 Re: why select count(*) consumes wal logs Ravi Krishna <srkrishna1@aol.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox