pgsql 10: hash indexes testing

Started by APalmost 9 years ago47 messageshackers
Jump to latest
#1AP
ap@zip.com.au

Hi,

As I am actively working on a big project I figured I'd give PGSQL 10 a
go, primarily because of hash indexes.

PostgreSQL 10 version in use is: 10~beta2~20170620.2224-1~491.gitd412f79.pgdg+1

Things are mostly well with hash indexes (plain, non-unique) giving me
a rather lovely saving in index size: they are roughly 1/4 to 1/2 the
size of btree. This is of use as the btree indexes can be between 25GB
and 350GB in size.

There is one index that caused an issue. Towards the end of an import
I got the following error:

out of overflow pages in hash index

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

Is this a valid error message or have I spotted a bug?

I tried to duplicate the error with a reindex of the data set that I
uploaded using btree for that index but I couldn't. The difference, as
near as I can remember, is different (quasi)random values being indexed
(still same level of duplication).

I'll see if I can get the table reloaded a-fresh to see if that's what
it takes to trigger the error. The upload is done in a single transaction
with COPY BINARY of 3-4 tables, one after the other in a loop until data
is exhausted (ie: COPY into table A, B, C and D and then back to A and
repeat - there is data processing happening and this helps keep memory
usage in check).

A single transaction can COPY millions of rows (average is about 3.7
million rows with the table in question getting 3 million). There are
33 transactions in play at any one time and they all upload to the same
tables. Last things done in a transaction are a couple of small,
single-row INSERTs into a couple of tables and then COMMIT. There is
one transaction per connection. The whole process can take 12-15 hours
and involves 1000 transactions.

Hopefully it's not a specific set of random values that generates
the error cos duplicating THAT will be outpaced by the death of the
universe. :)

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#1)
Re: pgsql 10: hash indexes testing

On Tue, Jul 4, 2017 at 4:27 PM, AP <ap@zip.com.au> wrote:

Hi,

As I am actively working on a big project I figured I'd give PGSQL 10 a
go, primarily because of hash indexes.

PostgreSQL 10 version in use is: 10~beta2~20170620.2224-1~491.gitd412f79.pgdg+1

Things are mostly well with hash indexes (plain, non-unique) giving me
a rather lovely saving in index size: they are roughly 1/4 to 1/2 the
size of btree. This is of use as the btree indexes can be between 25GB
and 350GB in size.

There is one index that caused an issue. Towards the end of an import
I got the following error:

out of overflow pages in hash index

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

Is this a valid error message or have I spotted a bug?

It is difficult to say at this stage, but I think we can figure out.
We can get such a message if we consume the maximum overflow pages
that hash index can support which is limited by a number of
bitmappages. Can you try to use pgstattuple extension and get us the
results of Select * from pgstathashindex('index_name');? If the
number of bitmappages is 128 and total overflow pages are 128 * 4096,
then that would mean that all the pages are used. Then maybe we can
try to see if all the pages are full with the help of pageinspect, but
I think we don't need to go there at this stage.

I tried to duplicate the error with a reindex of the data set that I
uploaded using btree for that index but I couldn't. The difference, as
near as I can remember, is different (quasi)random values being indexed
(still same level of duplication).

One probably theory is that in the original index where you hit the
error, there are some unused overflow pages in some of the buckets
which can be squeezed. The reason those didn't get squeezed is that
Vacuum wouldn't have been kicked off on this workload.

I'll see if I can get the table reloaded a-fresh to see if that's what
it takes to trigger the error.

Thanks. I suggest when an error occurs, don't throw away that index
because we can get some useful information from it to diagnose the
reason of error.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Jeff Janes
jeff.janes@gmail.com
In reply to: AP (#1)
Re: pgsql 10: hash indexes testing

On Tue, Jul 4, 2017 at 3:57 AM, AP <ap@zip.com.au> wrote:

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

What is the number of duplicates for the most common value?

Cheers,

Jeff

#4AP
ap@zip.com.au
In reply to: Amit Kapila (#2)
Re: pgsql 10: hash indexes testing

On Wed, Jul 05, 2017 at 08:10:10AM +0530, Amit Kapila wrote:

On Tue, Jul 4, 2017 at 4:27 PM, AP <ap@zip.com.au> wrote:

There is one index that caused an issue. Towards the end of an import
I got the following error:

out of overflow pages in hash index

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

Is this a valid error message or have I spotted a bug?

It is difficult to say at this stage, but I think we can figure out.
We can get such a message if we consume the maximum overflow pages
that hash index can support which is limited by a number of
bitmappages. Can you try to use pgstattuple extension and get us the
results of Select * from pgstathashindex('index_name');? If the
number of bitmappages is 128 and total overflow pages are 128 * 4096,
then that would mean that all the pages are used. Then maybe we can

Hmm. Unless I misunderstood that'd mean that overflow_pages/4096 should
result in a number <= 128 at the moment, right? If so then something is
amiss:

# select * from pgstathashindex('link_datum_id_hash_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

oldmdstash=# select 2131192/4096;
?column?
----------
520
(1 row)

And I do appear to have an odd percentage of free space. :)

This index was created yesterday so it has been around for maybe 18 hours.
Autovac is likely to have hit it by now.

I'll see if I can get the table reloaded a-fresh to see if that's what
it takes to trigger the error.

Thanks. I suggest when an error occurs, don't throw away that index
because we can get some useful information from it to diagnose the
reason of error.

I'll try and set this up now.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#4)
Re: pgsql 10: hash indexes testing

On Wed, Jul 5, 2017 at 9:53 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 08:10:10AM +0530, Amit Kapila wrote:

On Tue, Jul 4, 2017 at 4:27 PM, AP <ap@zip.com.au> wrote:

There is one index that caused an issue. Towards the end of an import
I got the following error:

out of overflow pages in hash index

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

Is this a valid error message or have I spotted a bug?

It is difficult to say at this stage, but I think we can figure out.
We can get such a message if we consume the maximum overflow pages
that hash index can support which is limited by a number of
bitmappages. Can you try to use pgstattuple extension and get us the
results of Select * from pgstathashindex('index_name');? If the
number of bitmappages is 128 and total overflow pages are 128 * 4096,
then that would mean that all the pages are used. Then maybe we can

Hmm. Unless I misunderstood that'd mean that overflow_pages/4096 should
result in a number <= 128 at the moment, right?

No, sorry, I think my calculation above has something missing. It
should be 128 * 4096 * 8. How we can compute this number is
no_bitmap_pages * no_bits_used_to_represent_overflow_pages.

In each bitmap page (8K), we can use 4K (to meet power of 2 criteria)
to represent overflow pages. We use one bit to represent each
overflow page. Also, you need to include bitmap pages in overflow
pages as we consider those as a subset of the overflow pages.

If so then something is
amiss:

# select * from pgstathashindex('link_datum_id_hash_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

oldmdstash=# select 2131192/4096;
?column?
----------
520
(1 row)

You need to divide 520 by 8 to get the bitmap page. Is this the index
in which you get the error or is this the one on which you have done
REINDEX?

And I do appear to have an odd percentage of free space. :)

It looks like Vacuum hasn't been triggered.

This index was created yesterday so it has been around for maybe 18 hours.
Autovac is likely to have hit it by now.

Do you have any deletes? How have you verified whether autovacuum has
been triggered or not?

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6AP
ap@zip.com.au
In reply to: Amit Kapila (#5)
Re: pgsql 10: hash indexes testing

On Wed, Jul 05, 2017 at 10:29:09AM +0530, Amit Kapila wrote:

bitmappages. Can you try to use pgstattuple extension and get us the
results of Select * from pgstathashindex('index_name');? If the
number of bitmappages is 128 and total overflow pages are 128 * 4096,
then that would mean that all the pages are used. Then maybe we can

Hmm. Unless I misunderstood that'd mean that overflow_pages/4096 should
result in a number <= 128 at the moment, right?

No, sorry, I think my calculation above has something missing. It
should be 128 * 4096 * 8. How we can compute this number is
no_bitmap_pages * no_bits_used_to_represent_overflow_pages.

AHA! Ok. Then that appears to match. I get 65.041.

If so then something is
amiss:

# select * from pgstathashindex('link_datum_id_hash_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

oldmdstash=# select 2131192/4096;
?column?
----------
520
(1 row)

You need to divide 520 by 8 to get the bitmap page. Is this the index
in which you get the error or is this the one on which you have done
REINDEX?

Post REINDEX.

And I do appear to have an odd percentage of free space. :)

It looks like Vacuum hasn't been triggered.

:(

This index was created yesterday so it has been around for maybe 18 hours.
Autovac is likely to have hit it by now.

Do you have any deletes? How have you verified whether autovacuum has

No DELETEs. Just the initial COPY, then SELECTs, then a DB rename to get it
out of the way of other testing, then the REINDEX.

been triggered or not?

I just checked pg_stat_user_tables (which I hope is the right place for
this info :)

relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | n_mod_since_analyze | last_vacuum | last_autovacuum | last_analyze | last_autoanalyze | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count
-----------+------------+---------+----------+--------------+----------+---------------+------------+-----------+-----------+---------------+------------+------------+---------------------+-------------+-----------------+-------------------------------+-------------------------------+--------------+------------------+---------------+-------------------
129311803 | public | link | 70 | 15085880072 | 5779 | 465623 | 2975444240 | 0 | 0 | 0 | 928658178 | 0 | 0 | | | | 2017-06-28 10:43:51.273241+10 | 0 | 0 | 0 | 2

So it appears not.

# show autovacuum;
autovacuum
------------
on
(1 row)

All autovacuum parameters are as per default. The autovacuum launcher process
exists.

:(

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7AP
ap@zip.com.au
In reply to: AP (#6)
Re: pgsql 10: hash indexes testing

On Wed, Jul 05, 2017 at 03:33:45PM +1000, AP wrote:

Do you have any deletes? How have you verified whether autovacuum has

No DELETEs. Just the initial COPY, then SELECTs, then a DB rename to get it
out of the way of other testing, then the REINDEX.

been triggered or not?

I just checked pg_stat_user_tables (which I hope is the right place for
this info :)

relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | n_mod_since_analyze | last_vacuum | last_autovacuum | last_analyze | last_autoanalyze | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count
-----------+------------+---------+----------+--------------+----------+---------------+------------+-----------+-----------+---------------+------------+------------+---------------------+-------------+-----------------+-------------------------------+-------------------------------+--------------+------------------+---------------+-------------------
129311803 | public | link | 70 | 15085880072 | 5779 | 465623 | 2975444240 | 0 | 0 | 0 | 928658178 | 0 | 0 | | | | 2017-06-28 10:43:51.273241+10 | 0 | 0 | 0 | 2

So it appears not.

Actually, after a bit more late-arvo thought, I take it this would be the
case as the table has not changed since creation. Thus no need to autovac.

I've newer timestamps on the live db (whose data was uploaded more recently)
for its tables so I think autovac is functioning.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#8AP
ap@zip.com.au
In reply to: Jeff Janes (#3)
Re: pgsql 10: hash indexes testing

On Tue, Jul 04, 2017 at 08:23:20PM -0700, Jeff Janes wrote:

On Tue, Jul 4, 2017 at 3:57 AM, AP <ap@zip.com.au> wrote:

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

What is the number of duplicates for the most common value?

Damn. Was going to collect this info as I was doing a fresh upload but
it fell through the cracks of my mind. It'll probably take at least
half a day to collect (a simple count(*) on the table takes 1.5-1.75
hours parallelised across 11 processes) so I'll probably have this in
around 24 hours if all goes well. (and I don't stuff up the SQL :) )

AP.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#6)
Re: pgsql 10: hash indexes testing

On Wed, Jul 5, 2017 at 11:03 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 10:29:09AM +0530, Amit Kapila wrote:

bitmappages. Can you try to use pgstattuple extension and get us the
results of Select * from pgstathashindex('index_name');? If the
number of bitmappages is 128 and total overflow pages are 128 * 4096,
then that would mean that all the pages are used. Then maybe we can

Hmm. Unless I misunderstood that'd mean that overflow_pages/4096 should
result in a number <= 128 at the moment, right?

No, sorry, I think my calculation above has something missing. It
should be 128 * 4096 * 8. How we can compute this number is
no_bitmap_pages * no_bits_used_to_represent_overflow_pages.

AHA! Ok. Then that appears to match. I get 65.041.

If so then something is
amiss:

# select * from pgstathashindex('link_datum_id_hash_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

oldmdstash=# select 2131192/4096;
?column?
----------
520
(1 row)

You need to divide 520 by 8 to get the bitmap page. Is this the index
in which you get the error or is this the one on which you have done
REINDEX?

Post REINDEX.

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major
reason to worry, because these are probably freed overflow pages which
can be used in future. In the hash index, when we free the overflow
pages, they are not returned back to OS, rather they are tracked in
the index as unused pages which will get used when required in future.

It looks like Vacuum hasn't been triggered.

Vacuum won't be triggered on insert load. I think that is one of the
reasons why in your initial copy, you might have got the error. We
had some discussion in the past to trigger Vacuum on insert heavy
workloads [1]/messages/by-id/b970f20f-f096-2d3a-6c6d-ee887bd30cfb@2ndquadrant.fr, but the patch still didn't get committed. I think if
that patch or some other form of that patch gets committed, it will
help the workload what you are trying here.

[1]: /messages/by-id/b970f20f-f096-2d3a-6c6d-ee887bd30cfb@2ndquadrant.fr

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10AP
ap@zip.com.au
In reply to: Amit Kapila (#9)
Re: pgsql 10: hash indexes testing

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

reason to worry, because these are probably freed overflow pages which
can be used in future. In the hash index, when we free the overflow
pages, they are not returned back to OS, rather they are tracked in
the index as unused pages which will get used when required in future.

It looks like Vacuum hasn't been triggered.

Vacuum won't be triggered on insert load. I think that is one of the
reasons why in your initial copy, you might have got the error. We
had some discussion in the past to trigger Vacuum on insert heavy
workloads [1], but the patch still didn't get committed. I think if
that patch or some other form of that patch gets committed, it will
help the workload what you are trying here.

Well, if this is the cause of my little issue, it might be nice. ATM
my import script bombs out on errors (that I've duplicated! :) It took
11 hours but it bombed) and it sounds like I'll need to do a manual
VACUUM before it can be run again.

The stats you were looking for before are:

# select * from pgstathashindex('link_datum_id_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 8559258 | 4194176 | 128 | 1926502 | 3591812743 | 0 | 942.873199357466
(1 row)

# select 4194176.0/128/8;
?column?
-----------------------
4095.8750000000000000
(1 row)

If you need more info or whatnot, shout. I've a problematic index to
play with now.

[1] - /messages/by-id/b970f20f-f096-2d3a-6c6d-ee887bd30cfb@2ndquadrant.fr

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#10)
Re: pgsql 10: hash indexes testing

On Thu, Jul 6, 2017 at 2:40 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

Yes, there seems to be some gotcha in free percent calculation. Is it
possible for you to debug or in some way share the test?

reason to worry, because these are probably freed overflow pages which
can be used in future. In the hash index, when we free the overflow
pages, they are not returned back to OS, rather they are tracked in
the index as unused pages which will get used when required in future.

It looks like Vacuum hasn't been triggered.

Vacuum won't be triggered on insert load. I think that is one of the
reasons why in your initial copy, you might have got the error. We
had some discussion in the past to trigger Vacuum on insert heavy
workloads [1], but the patch still didn't get committed. I think if
that patch or some other form of that patch gets committed, it will
help the workload what you are trying here.

Well, if this is the cause of my little issue, it might be nice. ATM
my import script bombs out on errors (that I've duplicated! :) It took
11 hours but it bombed) and it sounds like I'll need to do a manual
VACUUM before it can be run again.

Yeah, I think after manual vacuum you should be able to proceed.

The stats you were looking for before are:

# select * from pgstathashindex('link_datum_id_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 8559258 | 4194176 | 128 | 1926502 | 3591812743 | 0 | 942.873199357466
(1 row)

# select 4194176.0/128/8;
?column?
-----------------------
4095.8750000000000000
(1 row)

From above stats, it is clear that you have hit the maximum number of
overflow pages we can support today. Now, here one can argue that we
should increase the limit of overflow pages in hash index which we can
do, but I think you can again hit such a problem after some more time.
So at this stage, there are two possibilities for you (a) run manual
Vacuum in-between (b) create the index after bulk load. In general,
whatever I have mentioned in (b) is a better way for bulk loading.
Note here again the free_percent seems to be wrong.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12AP
ap@zip.com.au
In reply to: Amit Kapila (#11)
Re: pgsql 10: hash indexes testing

On Thu, Jul 06, 2017 at 08:52:03AM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 2:40 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

Yes, there seems to be some gotcha in free percent calculation. Is it
possible for you to debug or in some way share the test?

I can try to debug but I need to know what to look for and how. If it
requires data reloads then that's around 12-15 hours per hit.

As for sharing the test, that'd mean sharing the data. If it helps I can
provide the content of that column but you're looking at an sql dump that
is roughly (2*64+1)*2.3 billion (give or take a (few) billion) in size. :)

Well, if this is the cause of my little issue, it might be nice. ATM
my import script bombs out on errors (that I've duplicated! :) It took
11 hours but it bombed) and it sounds like I'll need to do a manual
VACUUM before it can be run again.

Yeah, I think after manual vacuum you should be able to proceed.

I don't think that'll help. I did a small check which I hope is helpful in
seeing if it will. Working off a similar db that completed (as it was
smaller and I did not want to mess with my one copy of the broken db)
I got the following results:

Pre-VACUUM:
-----------
# \di+
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+-------------------+-------+-----------+---------+---------+-------------
...
public | link_datum_id_idx | index | mdkingpin | link | 90 GB |
...

# select * from pgstathashindex('link_datum_id_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+-----------------
3 | 7611595 | 3451261 | 106 | 777013 | 3076131325 | 0 | 1512.8635780908

# vacuum VERBOSE ANALYZE link;
INFO: vacuuming "public.link"
INFO: "link": found 0 removable, 2272156152 nonremovable row versions in 120507771 out of 123729466 pages
DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 8594
There were 0 unused item pointers.
Skipped 0 pages due to buffer pins, 0 frozen pages.
0 pages are entirely empty.
CPU: user: 457.16 s, system: 755.84 s, elapsed: 4196.75 s.
INFO: vacuuming "pg_toast.pg_toast_183727891"
INFO: index "pg_toast_183727891_index" now contains 1441820 row versions in 3956 pages
DETAIL: 0 index row versions were removed.
0 index pages have been deleted, 0 are currently reusable.
CPU: user: 0.02 s, system: 0.00 s, elapsed: 0.56 s.
INFO: "pg_toast_183727891": found 0 removable, 1441820 nonremovable row versions in 332271 out of 332271 pages
DETAIL: 0 dead row versions cannot be removed yet, oldest xmin: 8594
There were 0 unused item pointers.
Skipped 0 pages due to buffer pins, 0 frozen pages.
0 pages are entirely empty.
CPU: user: 1.16 s, system: 2.26 s, elapsed: 22.80 s.
INFO: analyzing "public.link"
INFO: "link": scanned 3000000 of 123729466 pages, containing 56661337 live rows and 0 dead rows; 3000000 rows in sample, 2330296882 estimated total rows
VACUUM
Time: 7057484.079 ms (01:57:37.484)

Post-VACUUM:
------------
# \di+
Schema | Name | Type | Owner | Table | Size | Description
--------+-------------------+-------+-----------+---------+---------+-------------
public | link_datum_id_idx | index | mdkingpin | link | 90 GB |

# select * from pgstathashindex('link_datum_id_idx');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+-----------------
3 | 7611595 | 3451261 | 106 | 777013 | 3076131325 | 0 | 1512.8635780908

The end results are the same.

Then I did:
# CREATE INDEX CONCURRENTLY ON link USING hash (datum_id) WITH (fillfactor = 90);
CREATE INDEX
Time: 12545612.560 ms (03:29:05.613)
# \di+
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+--------------------+-------+-----------+---------+---------+-------------
public | link_datum_id_idx | index | mdkingpin | link | 90 GB |
public | link_datum_id_idx1 | index | mdkingpin | link | 71 GB |

# select * from pgstathashindex('link_datum_id_idx1');
version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 7340032 | 2014699 | 62 | 0 | 2336759432 | 0 | 909.757757369414

That's markedly different. At a rough estimate I should be able to double
the row count before I hit the "real" limits of a hash index.

When you refer to VACUUM do you mean VACUUM FULL? That's going to get nasty
if that's the case as the table is almost 1TB in size.

From above stats, it is clear that you have hit the maximum number of

overflow pages we can support today. Now, here one can argue that we
should increase the limit of overflow pages in hash index which we can
do, but I think you can again hit such a problem after some more time.

True, though I'm not far off hitting it "for real" at the present limits
so an increase would be of benefit in other respects (ie not needing to
have as many tables to manage because we have to bundle a set off due
to index limits).

So at this stage, there are two possibilities for you (a) run manual
Vacuum in-between (b) create the index after bulk load. In general,
whatever I have mentioned in (b) is a better way for bulk loading.
Note here again the free_percent seems to be wrong.

If you didn't mean VACUUM FULL then (a) does not appear to work and (b)
would kill usability of the db during import, which would happen daily
(though with a vastly reduced data size). It also messes with the
permission model that has been set up for the least-trusted section of
the project (at the moment that section can only INSERT).

Still, I may wind up going with (b) if a VACUUM FULL is the only other
real choice but would prefer to avoid it. The fact that the index is
around 300GB smaller (so far) than btree may well be worth the pain
all by its lonesome.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#13Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#12)
Re: pgsql 10: hash indexes testing

On Thu, Jul 6, 2017 at 9:32 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 08:52:03AM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 2:40 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

Yes, there seems to be some gotcha in free percent calculation. Is it
possible for you to debug or in some way share the test?

I can try to debug but I need to know what to look for and how.

Okay, you need to debug function pgstathashindex and have your
breakpoint at free_percent calculation, then try to get the values of
nblocks, all the values in stats struct and total_space. I think
after getting this info we can further decide what to look for.

If it
requires data reloads then that's around 12-15 hours per hit.

As for sharing the test, that'd mean sharing the data. If it helps I can
provide the content of that column but you're looking at an sql dump that
is roughly (2*64+1)*2.3 billion (give or take a (few) billion) in size. :)

This is tricky, will Ibe able to import that column values by creating
table, if so, then probably it is worth.

Well, if this is the cause of my little issue, it might be nice. ATM
my import script bombs out on errors (that I've duplicated! :) It took
11 hours but it bombed) and it sounds like I'll need to do a manual
VACUUM before it can be run again.

Yeah, I think after manual vacuum you should be able to proceed.

That's markedly different. At a rough estimate I should be able to double
the row count before I hit the "real" limits of a hash index.

When you refer to VACUUM do you mean VACUUM FULL?

Normal Vauum won't work for this case as you don't have dead tuples
(deleted rows in table).

That's going to get nasty
if that's the case as the table is almost 1TB in size.

Yeah, I think for this situation REINDEX will be a better option
because anyway Vacuum Full will rewrite the entire index and heap.

From above stats, it is clear that you have hit the maximum number of

overflow pages we can support today. Now, here one can argue that we
should increase the limit of overflow pages in hash index which we can
do, but I think you can again hit such a problem after some more time.

True, though I'm not far off hitting it "for real" at the present limits
so an increase would be of benefit in other respects (ie not needing to
have as many tables to manage because we have to bundle a set off due
to index limits).

So at this stage, there are two possibilities for you (a) run manual
Vacuum in-between (b) create the index after bulk load. In general,
whatever I have mentioned in (b) is a better way for bulk loading.
Note here again the free_percent seems to be wrong.

If you didn't mean VACUUM FULL then (a) does not appear to work and (b)
would kill usability of the db during import, which would happen daily
(though with a vastly reduced data size).

If the data size in subsequent import is very less, then you only need
to Create the index after first import and then let it continue like
that.

It also messes with the
permission model that has been set up for the least-trusted section of
the project (at the moment that section can only INSERT).

As per your permission model Vacuum Full is allowed, but not Create index?

Still, I may wind up going with (b) if a VACUUM FULL is the only other
real choice but would prefer to avoid it. The fact that the index is
around 300GB smaller (so far) than btree may well be worth the pain
all by its lonesome.

As mentioned above REINDEX might be a better option. I think for such
situation we should have some provision to allow squeeze functionality
of hash exposed to the user, this will be less costly than REINDEX and
might serve the purpose for the user. Hey, can you try some hack in
the code which can at least tell us whether squeezing hash can give us
any benefit or is the index in such a situation that only REINDEX will
help. Basically, while doing Vacuum (non-full), you need to somehow
bypass the below line in lazy_scan_heap
lazy_scan_heap
{
..
if (vacrelstats->num_dead_tuples > 0)
..
}

I am not sure it will work, but we can try once if you are okay.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#14AP
ap@zip.com.au
In reply to: Amit Kapila (#13)
Re: pgsql 10: hash indexes testing

On Thu, Jul 06, 2017 at 12:38:38PM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 9:32 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 08:52:03AM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 2:40 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

Yes, there seems to be some gotcha in free percent calculation. Is it
possible for you to debug or in some way share the test?

I can try to debug but I need to know what to look for and how.

Okay, you need to debug function pgstathashindex and have your
breakpoint at free_percent calculation, then try to get the values of
nblocks, all the values in stats struct and total_space. I think
after getting this info we can further decide what to look for.

Ok. I'll try and get to this tomorrow amidst fun with NFS. Hopefully
there'll be time.

So... I'll need

postgresql-10-dbg - debug symbols for postgresql-10

Then given https://doxygen.postgresql.org/pgstatindex_8c.html#af86e3b4c40779d4f30a73b0bfe06316f
set a breakpoint at pgstatindex.c:710 via gdb and then have fun with
print?

As for sharing the test, that'd mean sharing the data. If it helps I can
provide the content of that column but you're looking at an sql dump that
is roughly (2*64+1)*2.3 billion (give or take a (few) billion) in size. :)

This is tricky, will Ibe able to import that column values by creating
table, if so, then probably it is worth.

Should do. Thinking about it a little more, I can shrink the file down by
roughly half if I don't do a pg_dump or similar. Doing

COPY link (datum_id) TO '/tmp/moocow.copy' WITH (FORMAT BINARY)

should allow you to use COPY FROM to restore the file and produce something
a lot smaller than a dump, right?

The table is simple:

CREATE TABLE link (datum_id BYTEA);

I can't give you the rest of the table (one other column) as the stuff hidden
in there is private.

The only thing that wont give you is the manner in which the column is filled
(ie: the transactions, their size, how long they run, their concurrency etc).
Don't know if that's important.

So at this stage, there are two possibilities for you (a) run manual
Vacuum in-between (b) create the index after bulk load. In general,
whatever I have mentioned in (b) is a better way for bulk loading.
Note here again the free_percent seems to be wrong.

If you didn't mean VACUUM FULL then (a) does not appear to work and (b)
would kill usability of the db during import, which would happen daily
(though with a vastly reduced data size).

If the data size in subsequent import is very less, then you only need
to Create the index after first import and then let it continue like
that.

Managing this has suddenly gotten a lot more complex. :)

It also messes with the
permission model that has been set up for the least-trusted section of
the project (at the moment that section can only INSERT).

As per your permission model Vacuum Full is allowed, but not Create index?

Well, at the moment it's all in development (though time for that to end
is coming up). As such I can do things with enhanced permissions manually.

When it hits production, that rather stops.

As mentioned above REINDEX might be a better option. I think for such
situation we should have some provision to allow squeeze functionality
of hash exposed to the user, this will be less costly than REINDEX and
might serve the purpose for the user. Hey, can you try some hack in

Assuming it does help, would this be something one would need to guess
at? "I did a whole bunch of concurrent INSERT heavy transactions so I
guess I should do a squeeze now"?

Or could it be figured out programmatically?

the code which can at least tell us whether squeezing hash can give us
any benefit or is the index in such a situation that only REINDEX will
help. Basically, while doing Vacuum (non-full), you need to somehow
bypass the below line in lazy_scan_heap
lazy_scan_heap
{
..
if (vacrelstats->num_dead_tuples > 0)
..
}

I am not sure it will work, but we can try once if you are okay.

So this would be at L1284 of https://doxygen.postgresql.org/vacuumlazy_8c.html#a59a677fb19b0aae6a57c87ae073e081b ?

Would turning it into if (1) and recompiling be the way to go?

Not sure if I'd be able to do this before or after the weekend.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#15Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#14)
Re: pgsql 10: hash indexes testing

On Thu, Jul 6, 2017 at 5:04 PM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 12:38:38PM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 9:32 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 08:52:03AM +0530, Amit Kapila wrote:

On Thu, Jul 6, 2017 at 2:40 AM, AP <ap@zip.com.au> wrote:

On Wed, Jul 05, 2017 at 05:52:32PM +0530, Amit Kapila wrote:

version | bucket_pages | overflow_pages | bitmap_pages | unused_pages | live_items | dead_items | free_percent
---------+--------------+----------------+--------------+--------------+------------+------------+------------------
3 | 10485760 | 2131192 | 66 | 0 | 2975444240 | 0 | 1065.19942179026
(1 row)

...

And I do appear to have an odd percentage of free space. :)

Are you worried about "unused_pages"? If so, then this is not a major

Nope. "free_percent" Just a bit weird that I have it at over 1000% free. :)
Shouldn't that number be < 100?

Yes, there seems to be some gotcha in free percent calculation. Is it
possible for you to debug or in some way share the test?

I can try to debug but I need to know what to look for and how.

Okay, you need to debug function pgstathashindex and have your
breakpoint at free_percent calculation, then try to get the values of
nblocks, all the values in stats struct and total_space. I think
after getting this info we can further decide what to look for.

Ok. I'll try and get to this tomorrow amidst fun with NFS. Hopefully
there'll be time.

Cool.

So... I'll need

postgresql-10-dbg - debug symbols for postgresql-10

Then given https://doxygen.postgresql.org/pgstatindex_8c.html#af86e3b4c40779d4f30a73b0bfe06316f
set a breakpoint at pgstatindex.c:710 via gdb and then have fun with
print?

If I am reading it correctly it should be line 706 as below:
if (get_call_result_type(fcinfo, NULL, &tupleDesc) != TYPEFUNC_COMPOSITE)

As for sharing the test, that'd mean sharing the data. If it helps I can
provide the content of that column but you're looking at an sql dump that
is roughly (2*64+1)*2.3 billion (give or take a (few) billion) in size. :)

This is tricky, will Ibe able to import that column values by creating
table, if so, then probably it is worth.

Should do. Thinking about it a little more, I can shrink the file down by
roughly half if I don't do a pg_dump or similar. Doing

COPY link (datum_id) TO '/tmp/moocow.copy' WITH (FORMAT BINARY)

should allow you to use COPY FROM to restore the file and produce something
a lot smaller than a dump, right?

I think so. You can share it. I will try.

The table is simple:

CREATE TABLE link (datum_id BYTEA);

I can't give you the rest of the table (one other column) as the stuff hidden
in there is private.

No issues.

The only thing that wont give you is the manner in which the column is filled
(ie: the transactions, their size, how long they run, their concurrency etc).
Don't know if that's important.

So at this stage, there are two possibilities for you (a) run manual
Vacuum in-between (b) create the index after bulk load. In general,
whatever I have mentioned in (b) is a better way for bulk loading.
Note here again the free_percent seems to be wrong.

If you didn't mean VACUUM FULL then (a) does not appear to work and (b)
would kill usability of the db during import, which would happen daily
(though with a vastly reduced data size).

If the data size in subsequent import is very less, then you only need
to Create the index after first import and then let it continue like
that.

Managing this has suddenly gotten a lot more complex. :)

It also messes with the
permission model that has been set up for the least-trusted section of
the project (at the moment that section can only INSERT).

As per your permission model Vacuum Full is allowed, but not Create index?

Well, at the moment it's all in development (though time for that to end
is coming up). As such I can do things with enhanced permissions manually.

I think if you are under development, it is always advisable to create
indexes after initial bulk load. That way it will be faster and will
take lesser space atleast in case of hash index.

When it hits production, that rather stops.

As mentioned above REINDEX might be a better option. I think for such
situation we should have some provision to allow squeeze functionality
of hash exposed to the user, this will be less costly than REINDEX and
might serve the purpose for the user. Hey, can you try some hack in

Assuming it does help, would this be something one would need to guess
at? "I did a whole bunch of concurrent INSERT heavy transactions so I
guess I should do a squeeze now"?

Or could it be figured out programmatically?

I think one can refer free_percent and number of overflow pages to
perform such a command. It won't be 100% correct, but we can make a
guess. We can even check free space in overflow pages with page
inspect to make it more accurate.

the code which can at least tell us whether squeezing hash can give us
any benefit or is the index in such a situation that only REINDEX will
help. Basically, while doing Vacuum (non-full), you need to somehow
bypass the below line in lazy_scan_heap
lazy_scan_heap
{
..
if (vacrelstats->num_dead_tuples > 0)
..
}

I am not sure it will work, but we can try once if you are okay.

So this would be at L1284 of https://doxygen.postgresql.org/vacuumlazy_8c.html#a59a677fb19b0aae6a57c87ae073e081b ?

Would turning it into if (1) and recompiling be the way to go?

Yes.

Not sure if I'd be able to do this before or after the weekend.

No problem.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#16AP
ap@zip.com.au
In reply to: AP (#8)
Re: pgsql 10: hash indexes testing

On Wed, Jul 05, 2017 at 07:31:39PM +1000, AP wrote:

On Tue, Jul 04, 2017 at 08:23:20PM -0700, Jeff Janes wrote:

On Tue, Jul 4, 2017 at 3:57 AM, AP <ap@zip.com.au> wrote:

The data being indexed is BYTEA, (quasi)random and 64 bytes in size.
The table has over 2 billion entries. The data is not unique. There's
an average of 10 duplicates for every unique value.

What is the number of duplicates for the most common value?

Damn. Was going to collect this info as I was doing a fresh upload but
it fell through the cracks of my mind. It'll probably take at least
half a day to collect (a simple count(*) on the table takes 1.5-1.75
hours parallelised across 11 processes) so I'll probably have this in
around 24 hours if all goes well. (and I don't stuff up the SQL :) )

Well...

num_ids | count
---------+----------
1 | 91456442
2 | 56224976
4 | 14403515
16 | 13665967
3 | 12929363
17 | 12093367
15 | 10347006

So the most common is a unique value, then a dupe.

AP.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#17AP
ap@zip.com.au
In reply to: Amit Kapila (#15)
Re: pgsql 10: hash indexes testing

On Thu, Jul 06, 2017 at 05:19:59PM +0530, Amit Kapila wrote:

I think if you are under development, it is always advisable to create
indexes after initial bulk load. That way it will be faster and will
take lesser space atleast in case of hash index.

This is a bit of a pickle, actually:
* if I do have a hash index I'll wind up with a bloated one at some stage
that refused to allow more inserts until the index is re-created
* if I don't have an index then I'll wind up with a table where I cannot
create a hash index because it has too many rows for it to handle

I'm at a bit of a loss as to how to deal with this. The DB design does come
with a kind of partitioning where a bundle of tables get put off to the side
and searched seperately as needed but too many of those and the impact on
performance can be noticed so I need to minimise them.

As mentioned above REINDEX might be a better option. I think for such
situation we should have some provision to allow squeeze functionality
of hash exposed to the user, this will be less costly than REINDEX and
might serve the purpose for the user. Hey, can you try some hack in

Assuming it does help, would this be something one would need to guess
at? "I did a whole bunch of concurrent INSERT heavy transactions so I
guess I should do a squeeze now"?

Or could it be figured out programmatically?

I think one can refer free_percent and number of overflow pages to
perform such a command. It won't be 100% correct, but we can make a
guess. We can even check free space in overflow pages with page
inspect to make it more accurate.

Does this take much time? Main reason I am asking is that this looks like
something that the db ought to handle underneath (say as part of an autovac
run) and so if there are stats that the index code can maintain that can
then be used by the autovac (or something) code to trigger a cleanup this
I think would be of benefit.

Unless I am being /so/ unusual that it's not worth it. :)

I'll reply to the rest in a separate stream as I'm still poking other
work related things atm so can't do the debug testing as yet.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#18Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#17)
Re: pgsql 10: hash indexes testing

On Fri, Jul 7, 2017 at 8:22 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 05:19:59PM +0530, Amit Kapila wrote:

I think if you are under development, it is always advisable to create
indexes after initial bulk load. That way it will be faster and will
take lesser space atleast in case of hash index.

This is a bit of a pickle, actually:
* if I do have a hash index I'll wind up with a bloated one at some stage
that refused to allow more inserts until the index is re-created
* if I don't have an index then I'll wind up with a table where I cannot
create a hash index because it has too many rows for it to handle

I'm at a bit of a loss as to how to deal with this.

I can understand your concerns. To address first concern we need to
work on one or more of following work items: (a) work on vacuums that
can be triggered on insert only workload (it should perform index
vacuum as well) (b) separate utility statement/function to squeeze
hash index (c) db internally does squeezing like after each split, so
that chances of such a problem can be reduced, but that will be at the
cost of performance reduction in other workloads, so not sure if it is
advisable. Among these (b) is simplest to do but may not be
convenient for the user.

To address your second concern, we need to speed up the creation of
hash index which is a relatively big project. Having said that, I
think in your case, this is one-time operation so spending once more
time might be okay.

As mentioned above REINDEX might be a better option. I think for such
situation we should have some provision to allow squeeze functionality
of hash exposed to the user, this will be less costly than REINDEX and
might serve the purpose for the user. Hey, can you try some hack in

Assuming it does help, would this be something one would need to guess
at? "I did a whole bunch of concurrent INSERT heavy transactions so I
guess I should do a squeeze now"?

Or could it be figured out programmatically?

I think one can refer free_percent and number of overflow pages to
perform such a command. It won't be 100% correct, but we can make a
guess. We can even check free space in overflow pages with page
inspect to make it more accurate.

Does this take much time? Main reason I am asking is that this looks like
something that the db ought to handle underneath (say as part of an autovac
run) and so if there are stats that the index code can maintain that can
then be used by the autovac (or something) code to trigger a cleanup this
I think would be of benefit.

Sure, I agree that database should automatically handle bloat, but as
said above this will be a separate project and may not be straight
forward.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#19AP
ap@zip.com.au
In reply to: Amit Kapila (#18)
Re: pgsql 10: hash indexes testing

On Fri, Jul 07, 2017 at 05:58:25PM +0530, Amit Kapila wrote:

On Fri, Jul 7, 2017 at 8:22 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 05:19:59PM +0530, Amit Kapila wrote:

I think if you are under development, it is always advisable to create
indexes after initial bulk load. That way it will be faster and will
take lesser space atleast in case of hash index.

This is a bit of a pickle, actually:
* if I do have a hash index I'll wind up with a bloated one at some stage
that refused to allow more inserts until the index is re-created
* if I don't have an index then I'll wind up with a table where I cannot
create a hash index because it has too many rows for it to handle

I'm at a bit of a loss as to how to deal with this.

I can understand your concerns. To address first concern we need to
work on one or more of following work items: (a) work on vacuums that
can be triggered on insert only workload (it should perform index
vacuum as well) (b) separate utility statement/function to squeeze
hash index (c) db internally does squeezing like after each split, so
that chances of such a problem can be reduced, but that will be at the
cost of performance reduction in other workloads, so not sure if it is
advisable. Among these (b) is simplest to do but may not be
convenient for the user.

(a) seems like a good compromise on (c) if it can be done without disruption
and in time.
(b) seems analogous to the path autovcauum took. Unless I misremember, before
autovacuum we had a cronjob to do similar work. It's probably a sane path
to take as a first step on the way to (a)
(c) may not be worth the effort if it compromises general use, though perhaps
it could be used to indicate to (a) that now is a good time to handle
this bit?

To address your second concern, we need to speed up the creation of
hash index which is a relatively big project. Having said that, I
think in your case, this is one-time operation so spending once more
time might be okay.

Yup. Primarily I just wanted the idea out there that this isn't that easy
to cope with manually and to get it onto a todo list (unless it was an
easy thing to do given a bit of thought but it appears not).

Out of curiosity, and apologies if you explained it already and I missed
the signficance of the words, how does this bloat happen? There tables
obly cop COPY. There is no UPDATE or DELETE; all transactions get COMMITted
so there's no ROLLBACK undoing the COPY and yet the bloat occurs.

AP

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#20Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#19)
Re: pgsql 10: hash indexes testing

On Tue, Jul 11, 2017 at 6:51 AM, AP <ap@zip.com.au> wrote:

On Fri, Jul 07, 2017 at 05:58:25PM +0530, Amit Kapila wrote:

On Fri, Jul 7, 2017 at 8:22 AM, AP <ap@zip.com.au> wrote:

On Thu, Jul 06, 2017 at 05:19:59PM +0530, Amit Kapila wrote:

I think if you are under development, it is always advisable to create
indexes after initial bulk load. That way it will be faster and will
take lesser space atleast in case of hash index.

This is a bit of a pickle, actually:
* if I do have a hash index I'll wind up with a bloated one at some stage
that refused to allow more inserts until the index is re-created
* if I don't have an index then I'll wind up with a table where I cannot
create a hash index because it has too many rows for it to handle

I'm at a bit of a loss as to how to deal with this.

I can understand your concerns. To address first concern we need to
work on one or more of following work items: (a) work on vacuums that
can be triggered on insert only workload (it should perform index
vacuum as well) (b) separate utility statement/function to squeeze
hash index (c) db internally does squeezing like after each split, so
that chances of such a problem can be reduced, but that will be at the
cost of performance reduction in other workloads, so not sure if it is
advisable. Among these (b) is simplest to do but may not be
convenient for the user.

(a) seems like a good compromise on (c) if it can be done without disruption
and in time.
(b) seems analogous to the path autovcauum took. Unless I misremember, before
autovacuum we had a cronjob to do similar work. It's probably a sane path
to take as a first step on the way to (a)
(c) may not be worth the effort if it compromises general use, though perhaps
it could be used to indicate to (a) that now is a good time to handle
this bit?

Nice summarization! I think before doing anything of that sort we
need opinions from others as well. If some other community members
also see value in doing one or multiple of above things, then I can
write a patch.

To address your second concern, we need to speed up the creation of
hash index which is a relatively big project. Having said that, I
think in your case, this is one-time operation so spending once more
time might be okay.

Yup. Primarily I just wanted the idea out there that this isn't that easy
to cope with manually and to get it onto a todo list (unless it was an
easy thing to do given a bit of thought but it appears not).

Out of curiosity, and apologies if you explained it already and I missed
the signficance of the words, how does this bloat happen?

You might want to read src/backend/access/hash/README. During split
operation, we copy tuples from the old bucket (bucket being split) to
new bucket (bucket being populated) and once all the tuples are copied
and there is no prior scan left which has started during split on the
buckets involved in the split, we remove the tuples from the old
bucket. Now, as we might need to wait for the scans to finish, we
have preferred to perform it during vacuum or during next split from
that bucket. Till the tuples are removed from the old bucket, there
will be some bloat in the system.

--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#21Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Kapila (#20)
#22Amit Kapila
amit.kapila16@gmail.com
In reply to: Alvaro Herrera (#21)
#23Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Amit Kapila (#22)
#24Amit Kapila
amit.kapila16@gmail.com
In reply to: Alvaro Herrera (#23)
#25Robert Haas
robertmhaas@gmail.com
In reply to: Amit Kapila (#24)
#26AP
ap@zip.com.au
In reply to: Robert Haas (#25)
#27Amit Kapila
amit.kapila16@gmail.com
In reply to: Robert Haas (#25)
#28AP
ap@zip.com.au
In reply to: Amit Kapila (#27)
#29Amit Kapila
amit.kapila16@gmail.com
In reply to: Amit Kapila (#27)
#30Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#28)
#31Robert Haas
robertmhaas@gmail.com
In reply to: Amit Kapila (#29)
#32Robert Haas
robertmhaas@gmail.com
In reply to: Amit Kapila (#29)
#33Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Robert Haas (#32)
#34Amit Kapila
amit.kapila16@gmail.com
In reply to: Robert Haas (#32)
#35Amit Kapila
amit.kapila16@gmail.com
In reply to: Amit Kapila (#34)
#36Amit Kapila
amit.kapila16@gmail.com
In reply to: Robert Haas (#31)
#37Robert Haas
robertmhaas@gmail.com
In reply to: Amit Kapila (#36)
#38Robert Haas
robertmhaas@gmail.com
In reply to: Amit Kapila (#35)
#39Amit Kapila
amit.kapila16@gmail.com
In reply to: Robert Haas (#38)
#40AP
ap@zip.com.au
In reply to: Amit Kapila (#39)
#41AP
ap@zip.com.au
In reply to: AP (#40)
#42Robert Haas
robertmhaas@gmail.com
In reply to: AP (#41)
#43AP
ap@zip.com.au
In reply to: Robert Haas (#42)
#44Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#41)
#45Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#43)
#46AP
ap@zip.com.au
In reply to: Amit Kapila (#44)
#47Amit Kapila
amit.kapila16@gmail.com
In reply to: AP (#46)