pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedERROR: too many dynamic shared memory segments
35+ messages / 10 participants
[nested] [flat]
Commits from this thread:
2018-02-02 957ff087c8 34653bc983 Be more wary about shm_toc_lookup failure.
2017-11-28 445dbd82a3 dba6e75c11 Fix ReinitializeParallelDSM to tolerate finding no error queues.
2017-11-28 c6755e233b ec7629dfb9 Teach bitmap heap scan to cope with absence of a DSA.
* ERROR: too many dynamic shared memory segments
@ 2017-11-27 09:54 Jakub Glapa <jakub.glapa@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Jakub Glapa @ 2017-11-27 09:54 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
Hi,
I started seeing those errors on Postgresql 10.1 running on Ubuntu 16.04.3
(64GB/8CPU) server.
The DB enters recovery mode after that.
2017-11-23 07:20:39 CET::@:[24823]: ERROR: could not attach to dynamic
shared area
2017-11-23 07:20:39 CET::@:[24822]: ERROR: could not map dynamic shared
memory segment
2017-11-23 07:20:40 CET:192.168.xx,xx(33974):u(at)db:[24209]: ERROR: too
many
dynamic shared memory segments
The errors happen when the parallel execution is enabled and multiple
queries are executed simultaneously.
If I set the max_parallel_workers_per_gather = 0 the error doesn't occur.
The queries are rather big, each executes over 10sec.
I see the error when 4 or more queries are started at the same time.
my postgresql.conf:
max_connections = 100
shared_buffers = 12GB
effective_cache_size = 51GB
work_mem = 83886kB
maintenance_work_mem = 2GB
max_wal_size = 8GB
min_wal_size = 4GB
checkpoint_completion_target = 0.9
wal_buffers = 32MB
default_statistics_target = 1000
max_locks_per_transaction = 128
#max_parallel_workers_per_gather = 0
PS. I've posted this question on pgsql-admin distro but didn't get any
feedback.
--
regards,
Jakub Glapa
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 10:47 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Jakub Glapa <jakub.glapa@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2017-11-27 10:47 UTC (permalink / raw)
To: Jakub Glapa <jakub.glapa@gmail.com>; +Cc: pgsql-general@lists.postgresql.org
On Mon, Nov 27, 2017 at 10:54 PM, Jakub Glapa <jakub.glapa@gmail.com> wrote:
> The DB enters recovery mode after that.
That's not good. So it actually crashes? Can you please show the
full error messages?
> 2017-11-23 07:20:39 CET::@:[24823]: ERROR: could not attach to dynamic
> shared area
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 12:13 Jakub Glapa <jakub.glapa@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 1 reply; 35+ messages in thread
From: Jakub Glapa @ 2017-11-27 12:13 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-general@lists.postgresql.org
Hi Thomas,
log excerpt:
...
2017-11-27 12:21:14 CET:192.168.10.83(33424):user@db:[27291]: ERROR: too
many dynamic shared memory segments
2017-11-27 12:21:14 CET:192.168.10.83(33424):user@db:[27291]: STATEMENT:
SELECT << REMOVED>>
2017-11-27 12:21:14 CET:192.168.10.83(35182):user@db:[28281]: ERROR: too
many dynamic shared memory segments
2017-11-27 12:21:14 CET:192.168.10.83(35182):user@db:[28281]: STATEMENT:
SELECT <<REMOVED>
2017-11-27 12:21:14 CET::@:[28618]: ERROR: could not map dynamic shared
memory segment
2017-11-27 12:21:14 CET::@:[28619]: ERROR: could not map dynamic shared
memory segment
2017-11-27 12:21:14 CET::@:[25645]: LOG: worker process: parallel worker
for PID 27291 (PID 28618) exited with exit code 1
2017-11-27 12:21:14 CET::@:[25645]: LOG: worker process: parallel worker
for PID 27291 (PID 28619) exited with exit code 1
...
this time the db didn't crash but the queries failed to execute.
The queries are somehow special.
We are still using the old style partitioning (list type) but we abuse it a
bit when querying.
When querying a set of partitions instead of doing it via parent table we
stitch together the required tables with UNION ALL (this requires less
locking) and was more performant in our benchmark (the new native
partitioning might improve this but we didn't research that yet).
The queries are in form of
SELECT col1,col2,col3 FROM
(SELECT *
FROM par1
WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
'2017-11-26 23:59:59.999'
UNION ALL SELECT *
FROM par2
WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
'2017-11-26 23:59:59.999'
UNION ALL SELECT *
FROM par2
WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
'2017-11-26 23:59:59.999'
WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
'2017-11-26 23:59:59.999'
UNION ALL
...
) unionalias
WHERE ....
and indeed the query planner shows the usage of Bitmap Heap Scan
....
-> Subquery Scan on "*SELECT* 2"
(cost=3068.58..19793.94 rows=1 width=1284)
-> Gather (cost=3068.58..19793.93
rows=1 width=5014)
Workers Planned: 2
-> Parallel Bitmap Heap Scan
on par_6 (cost=2068.58..18793.83 rows=1 width=5014)
Recheck Cond:
<<CONDITION>>
Filter: <<CONDITION>>
-> BitmapAnd
(cost=2068.58..2068.58 rows=30955 width=0)
-> BitmapOr
(cost=999.30..999.30 rows=42989 width=0)
-> Bitmap
Index Scan on par_6_datasource (cost=0.00..990.21 rows=42922 width=0)
Index
Cond: ((datasource)::text = 'one'::text)
-> Bitmap
Index Scan on par_6_datasource (cost=0.00..4.30 rows=1 width=0)
Index
Cond: ((datasource)::text = 'two'::text)
-> Bitmap
Index Scan on par_6_datasource (cost=0.00..4.79 rows=67 width=0)
Index
Cond: ((datasource)::text = 'three'::text)
-> Bitmap Index
Scan on par_6_rangestart (cost=0.00..1069.02 rows=47564 width=0)
Index Cond:
(rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
-> Subquery Scan on "*SELECT* 3"
(cost=761.33..7944.99 rows=1 width=1086)
-> Bitmap Heap Scan on par_7
(cost=761.33..7944.98 rows=1 width=4816)
Recheck Cond:
<<CONDITION>>
Filter: <<CONDITION>>
-> BitmapAnd
(cost=761.33..761.33 rows=7045 width=0)
-> Bitmap Index Scan on
par_7_rangestart (cost=0.00..380.35 rows=14942 width=0)
Index Cond:
(rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
-> BitmapOr
(cost=380.72..380.72 rows=12248 width=0)
-> Bitmap Index
Scan on par_7_datasource (cost=0.00..372.00 rows=12228 width=0)
Index Cond:
((datasource)::text = 'one'::text)
-> Bitmap Index
Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
Index Cond:
((datasource)::text = 'two'::text)
-> Bitmap Index
Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
Index Cond:
((datasource)::text = 'three'::text)
....
In this particular query there were over _100_ partitions connected with
the UNION ALL operator.
--
regards,
pozdrawiam,
Jakub Glapa
On Mon, Nov 27, 2017 at 11:47 AM, Thomas Munro <
thomas.munro@enterprisedb.com> wrote:
> On Mon, Nov 27, 2017 at 10:54 PM, Jakub Glapa <jakub.glapa@gmail.com>
> wrote:
> > The DB enters recovery mode after that.
>
> That's not good. So it actually crashes? Can you please show the
> full error messages?
>
> > 2017-11-23 07:20:39 CET::@:[24823]: ERROR: could not attach to dynamic
> > shared area
>
> From src/backend/utils/mmgr/dsa.c. The same message is used for
> dsa_attach() and for attach_internal(), but in this case it must be
> the latter because we use in-place DSA areas for parallel query. This
> means that when the worker tried to attach it found that
> control->refcnt == 0, meaning 'too late, every other backend including
> the leader has already detached'.
>
> > 2017-11-23 07:20:39 CET::@:[24822]: ERROR: could not map dynamic shared
> > memory segment
>
> From src/backend/access/transam/parallel.c when dsm_attach returns
> null. I think this also means 'too late'.
>
> So those are both workers that have started up and found that the
> leader has abandoned the parallel query already, but they discovered
> it at different stages. PID 24823 didn't manage to attach to the DSM
> segment, while PID 24822 did but found that the other(s) had already
> detached from the per-query DSA area inside it.
>
> > 2017-11-23 07:20:40 CET:192.168.xx,xx(33974):u(at)db:[24209]: ERROR:
> too
> > many
> > dynamic shared memory segments
> >
> > The errors happen when the parallel execution is enabled and multiple
> > queries are executed simultaneously.
> > If I set the max_parallel_workers_per_gather = 0 the error doesn't
> occur.
> > The queries are rather big, each executes over 10sec.
> > I see the error when 4 or more queries are started at the same time.
> >
> > my postgresql.conf:
> >
> > max_connections = 100
>
> So the two questions we need to figure out are: (1) how do we manage
> to use up all 64 + 2 * 100 DSM slots (or somehow corrupt things so it
> looks that way) by running only 4 queries, and (2) why would be be
> crashing rather than failing and reporting an error? I'm not able to
> reproduce the problem from your description running lots of parallel
> queries running at the same time. Can you provide reproduction steps?
> Does your query plan happen to include a Parallel Bitmap Heap Scan?
>
> --
> Thomas Munro
> http://www.enterprisedb.com
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 18:53 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Jakub Glapa <jakub.glapa@gmail.com>
0 siblings, 2 replies; 35+ messages in thread
From: Thomas Munro @ 2017-11-27 18:53 UTC (permalink / raw)
To: Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general
On Tue, Nov 28, 2017 at 1:13 AM, Jakub Glapa <jakub.glapa@gmail.com> wrote:
> The queries are somehow special.
> We are still using the old style partitioning (list type) but we abuse it a
> bit when querying.
> When querying a set of partitions instead of doing it via parent table we
> stitch together the required tables with UNION ALL (this requires less
> locking) and was more performant in our benchmark (the new native
> partitioning might improve this but we didn't research that yet).
>
> The queries are in form of
> SELECT col1,col2,col3 FROM
> (SELECT *
> FROM par1
> WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> '2017-11-26 23:59:59.999'
> UNION ALL SELECT *
> FROM par2
> WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> '2017-11-26 23:59:59.999'
> UNION ALL SELECT *
> FROM par2
> WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> '2017-11-26 23:59:59.999'
>
> WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> '2017-11-26 23:59:59.999'
>
> UNION ALL
> ...
> ) unionalias
> WHERE ....
>
>
>
> and indeed the query planner shows the usage of Bitmap Heap Scan
> ....
> -> Subquery Scan on "*SELECT* 2"
> (cost=3068.58..19793.94 rows=1 width=1284)
> -> Gather (cost=3068.58..19793.93
> rows=1 width=5014)
> Workers Planned: 2
> -> Parallel Bitmap Heap Scan
> on par_6 (cost=2068.58..18793.83 rows=1 width=5014)
> Recheck Cond:
> <<CONDITION>>
> Filter: <<CONDITION>>
> -> BitmapAnd
> (cost=2068.58..2068.58 rows=30955 width=0)
> -> BitmapOr
> (cost=999.30..999.30 rows=42989 width=0)
> -> Bitmap
> Index Scan on par_6_datasource (cost=0.00..990.21 rows=42922 width=0)
> Index
> Cond: ((datasource)::text = 'one'::text)
> -> Bitmap
> Index Scan on par_6_datasource (cost=0.00..4.30 rows=1 width=0)
> Index
> Cond: ((datasource)::text = 'two'::text)
> -> Bitmap
> Index Scan on par_6_datasource (cost=0.00..4.79 rows=67 width=0)
> Index
> Cond: ((datasource)::text = 'three'::text)
> -> Bitmap Index
> Scan on par_6_rangestart (cost=0.00..1069.02 rows=47564 width=0)
> Index Cond:
> (rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
> -> Subquery Scan on "*SELECT* 3"
> (cost=761.33..7944.99 rows=1 width=1086)
> -> Bitmap Heap Scan on par_7
> (cost=761.33..7944.98 rows=1 width=4816)
> Recheck Cond:
> <<CONDITION>>
> Filter: <<CONDITION>>
> -> BitmapAnd
> (cost=761.33..761.33 rows=7045 width=0)
> -> Bitmap Index Scan on
> par_7_rangestart (cost=0.00..380.35 rows=14942 width=0)
> Index Cond:
> (rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
> -> BitmapOr
> (cost=380.72..380.72 rows=12248 width=0)
> -> Bitmap Index
> Scan on par_7_datasource (cost=0.00..372.00 rows=12228 width=0)
> Index Cond:
> ((datasource)::text = 'one'::text)
> -> Bitmap Index
> Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
> Index Cond:
> ((datasource)::text = 'two'::text)
> -> Bitmap Index
> Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
> Index Cond:
> ((datasource)::text = 'three'::text)
>
> ....
>
>
> In this particular query there were over _100_ partitions connected with the
> UNION ALL operator.
Ah, so you have many Gather nodes under Append? That's one way to eat
arbitrarily many DSM slots. We allow for 64 + 2 * max_backends. Does
it help if you increase max_connections? I am concerned about the
crash failure mode you mentioned in the first email though: we should
always be able to handle that condition gracefully.
--
Thomas Munro
http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 19:16 Tom Lane <tgl@sss.pgh.pa.us>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 0 replies; 35+ messages in thread
From: Tom Lane @ 2017-11-27 19:16 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general
Thomas Munro <thomas.munro@enterprisedb.com> writes:
> Ah, so you have many Gather nodes under Append? That's one way to eat
> arbitrarily many DSM slots. We allow for 64 + 2 * max_backends. Does
> it help if you increase max_connections? I am concerned about the
> crash failure mode you mentioned in the first email though: we should
> always be able to handle that condition gracefully.
I suspect this is an instance of the issue I complained about before [1]
that parallel query is unable to cope with worker start failure.
regards, tom lane
[1] https://www.postgresql.org/message-id/4905.1492813727@sss.pgh.pa.us
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 21:05 Jakub Glapa <jakub.glapa@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 1 reply; 35+ messages in thread
From: Jakub Glapa @ 2017-11-27 21:05 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-general
Hi Thomas,
doubling the max_connection has the problem gone away for now! Yay!
As for the crash. I dug up the initial log and it looks like a segmentation
fault...
2017-11-23 07:26:53 CET:192.168.10.83(35238):user@db:[30003]: ERROR: too
many dynamic shared memory segments
2017-11-23 07:26:53 CET:192.168.10.83(35238):user@db:[30003]: STATEMENT:
SELECT ....
2017-11-23 07:26:55 CET::@:[29398]: LOG: server process (PID 26992) was
terminated by signal 11: Segmentation fault
2017-11-23 07:26:55 CET::@:[29398]: DETAIL: Failed process was running:
SELECT .....
2017-11-23 07:26:55 CET::@:[29398]: LOG: terminating any other active
server processes
2017-11-23 07:26:55 CET:192.168.10.83(35242):user@db:[30009]: WARNING:
terminating connection because of crash of another server process
2017-11-23 07:26:55 CET:192.168.10.83(35242):user@db:[30009]: DETAIL: The
postmaster has commanded this server process to roll back the current
transaction and exit, because another server process exited abnormally and
possibly corrupted shared memory.
2017-11-23 07:26:55 CET:192.168.10.83(35242):user@db:[30009]: HINT: In a
moment you should be able to reconnect to the database and repeat your
command.
2017-11-23 07:26:55 CET:192.168.10.83(35268):user@db:[30097]: WARNING:
terminating connection because of crash of another server process
2017-11-23 07:26:55 CET:192.168.10.83(35268):user@db:[30097]: DETAIL: The
postmaster has commanded this server process to roll back the current
transaction and exit, because another server process exited abnormally and
possibly corrupted shared memory.
2017-11-23 07:26:55 CET:192.168.10.83(35268):user@db:[30097]: HINT: In a
moment you should be able to reconnect to the database and repeat your
command.
2017-11-23 07:26:55 CET:192.168.10.83(46614):user@db:[31080]: WARNING:
terminating connection because of crash of another server process
2017-11-23 07:26:55 CET:192.168.10.83(46614):user@db:[31080]: DETAIL: The
postmaster has commanded this server process to roll back the current
transaction and exit, because another server process exited abnormally and
possibly corrupted shared memory.
2017-11-23 07:26:55 CET:192.168.10.83(46614):user@db: HINT: In a moment
you should be able to reconnect to the database and repeat your command.
2017-11-23 07:26:55 CET:192.168.10.83(35238):user@db:[30003]: WARNING:
terminating connection because of crash of another server process
2017-11-23 07:26:55 CET:192.168.10.83(35238):user@db:[30003]: DETAIL: The
postmaster has commanded this server process to roll back the current
transaction and exit, because another server process exited abnormally and
possibly corrupted shared memory
2017-11-23 07:26:55 CET:192.168.10.83(35300):user@db:[30152]: FATAL: the
database system is in recovery mode
--
regards,
pozdrawiam,
Jakub Glapa
On Mon, Nov 27, 2017 at 7:53 PM, Thomas Munro <thomas.munro@enterprisedb.com
> wrote:
> On Tue, Nov 28, 2017 at 1:13 AM, Jakub Glapa <jakub.glapa@gmail.com>
> wrote:
> > The queries are somehow special.
> > We are still using the old style partitioning (list type) but we abuse
> it a
> > bit when querying.
> > When querying a set of partitions instead of doing it via parent table we
> > stitch together the required tables with UNION ALL (this requires less
> > locking) and was more performant in our benchmark (the new native
> > partitioning might improve this but we didn't research that yet).
> >
> > The queries are in form of
> > SELECT col1,col2,col3 FROM
> > (SELECT *
> > FROM par1
> > WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> > '2017-11-26 23:59:59.999'
> > UNION ALL SELECT *
> > FROM par2
> > WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend
> <=
> > '2017-11-26 23:59:59.999'
> > UNION ALL SELECT *
> > FROM par2
> > WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend
> <=
> > '2017-11-26 23:59:59.999'
> >
> > WHERE rangestart >= '2017-01-01 00:00:00.0' AND rangeend <=
> > '2017-11-26 23:59:59.999'
> >
> > UNION ALL
> > ...
> > ) unionalias
> > WHERE ....
> >
> >
> >
> > and indeed the query planner shows the usage of Bitmap Heap Scan
> > ....
> > -> Subquery Scan on "*SELECT* 2"
> > (cost=3068.58..19793.94 rows=1 width=1284)
> > -> Gather
> (cost=3068.58..19793.93
> > rows=1 width=5014)
> > Workers Planned: 2
> > -> Parallel Bitmap Heap
> Scan
> > on par_6 (cost=2068.58..18793.83 rows=1 width=5014)
> > Recheck Cond:
> > <<CONDITION>>
> > Filter: <<CONDITION>>
> > -> BitmapAnd
> > (cost=2068.58..2068.58 rows=30955 width=0)
> > -> BitmapOr
> > (cost=999.30..999.30 rows=42989 width=0)
> > -> Bitmap
> > Index Scan on par_6_datasource (cost=0.00..990.21 rows=42922 width=0)
> >
> Index
> > Cond: ((datasource)::text = 'one'::text)
> > -> Bitmap
> > Index Scan on par_6_datasource (cost=0.00..4.30 rows=1 width=0)
> >
> Index
> > Cond: ((datasource)::text = 'two'::text)
> > -> Bitmap
> > Index Scan on par_6_datasource (cost=0.00..4.79 rows=67 width=0)
> >
> Index
> > Cond: ((datasource)::text = 'three'::text)
> > -> Bitmap Index
> > Scan on par_6_rangestart (cost=0.00..1069.02 rows=47564 width=0)
> > Index
> Cond:
> > (rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
> > -> Subquery Scan on "*SELECT* 3"
> > (cost=761.33..7944.99 rows=1 width=1086)
> > -> Bitmap Heap Scan on par_7
> > (cost=761.33..7944.98 rows=1 width=4816)
> > Recheck Cond:
> > <<CONDITION>>
> > Filter: <<CONDITION>>
> > -> BitmapAnd
> > (cost=761.33..761.33 rows=7045 width=0)
> > -> Bitmap Index Scan
> on
> > par_7_rangestart (cost=0.00..380.35 rows=14942 width=0)
> > Index Cond:
> > (rangestart >= '2017-01-01 00:00:00+01'::timestamp with time zone)
> > -> BitmapOr
> > (cost=380.72..380.72 rows=12248 width=0)
> > -> Bitmap Index
> > Scan on par_7_datasource (cost=0.00..372.00 rows=12228 width=0)
> > Index
> Cond:
> > ((datasource)::text = 'one'::text)
> > -> Bitmap Index
> > Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
> > Index
> Cond:
> > ((datasource)::text = 'two'::text)
> > -> Bitmap Index
> > Scan on par_7_datasource (cost=0.00..4.36 rows=10 width=0)
> > Index
> Cond:
> > ((datasource)::text = 'three'::text)
> >
> > ....
> >
> >
> > In this particular query there were over _100_ partitions connected with
> the
> > UNION ALL operator.
>
> Ah, so you have many Gather nodes under Append? That's one way to eat
> arbitrarily many DSM slots. We allow for 64 + 2 * max_backends. Does
> it help if you increase max_connections? I am concerned about the
> crash failure mode you mentioned in the first email though: we should
> always be able to handle that condition gracefully.
>
> --
> Thomas Munro
> http://www.enterprisedb.com
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-27 22:48 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Jakub Glapa <jakub.glapa@gmail.com>
0 siblings, 2 replies; 35+ messages in thread
From: Thomas Munro @ 2017-11-27 22:48 UTC (permalink / raw)
To: Jakub Glapa <jakub.glapa@gmail.com>; +Cc: pgsql-general; Robert Haas <robertmhaas@gmail.com>; Dilip Kumar <dilipbalaut@gmail.com>
On Tue, Nov 28, 2017 at 10:05 AM, Jakub Glapa <jakub.glapa@gmail.com> wrote:
> As for the crash. I dug up the initial log and it looks like a segmentation
> fault...
>
> 2017-11-23 07:26:53 CET:192.168.10.83(35238):user@db:[30003]: ERROR: too
> many dynamic shared memory segments
Hmm. Well this error can only occur in dsm_create() called without
DSM_CREATE_NULL_IF_MAXSEGMENTS. parallel.c calls it with that flag
and dsa.c doesn't (perhaps it should, not sure, but that'd just change
the error message), so that means this the error arose from dsa.c
trying to get more segments. That would be when Parallel Bitmap Heap
Scan tried to allocate memory.
I hacked my copy of PostgreSQL so that it allows only 5 DSM slots and
managed to reproduce a segv crash by trying to run concurrent Parallel
Bitmap Heap Scans. The stack looks like this:
* frame #0: 0x00000001083ace29
postgres`alloc_object(area=0x0000000000000000, size_class=10) + 25 at
dsa.c:1433
frame #1: 0x00000001083acd14
postgres`dsa_allocate_extended(area=0x0000000000000000, size=72,
flags=4) + 1076 at dsa.c:785
frame #2: 0x0000000108059c33
postgres`tbm_prepare_shared_iterate(tbm=0x00007f9743027660) + 67 at
tidbitmap.c:780
frame #3: 0x0000000108000d57
postgres`BitmapHeapNext(node=0x00007f9743019c88) + 503 at
nodeBitmapHeapscan.c:156
frame #4: 0x0000000107fefc5b
postgres`ExecScanFetch(node=0x00007f9743019c88,
accessMtd=(postgres`BitmapHeapNext at nodeBitmapHeapscan.c:77),
recheckMtd=(postgres`BitmapHeapRecheck at nodeBitmapHeapscan.c:710)) +
459 at execScan.c:95
frame #5: 0x0000000107fef983
postgres`ExecScan(node=0x00007f9743019c88,
accessMtd=(postgres`BitmapHeapNext at nodeBitmapHeapscan.c:77),
recheckMtd=(postgres`BitmapHeapRecheck at nodeBitmapHeapscan.c:710)) +
147 at execScan.c:162
frame #6: 0x00000001080008d1
postgres`ExecBitmapHeapScan(pstate=0x00007f9743019c88) + 49 at
nodeBitmapHeapscan.c:735
(lldb) f 3
frame #3: 0x0000000108000d57
postgres`BitmapHeapNext(node=0x00007f9743019c88) + 503 at
nodeBitmapHeapscan.c:156
153 * dsa_pointer of the iterator state which will be used by
154 * multiple processes to iterate jointly.
155 */
-> 156 pstate->tbmiterator = tbm_prepare_shared_iterate(tbm);
157 #ifdef USE_PREFETCH
158 if (node->prefetch_maximum > 0)
159
(lldb) print tbm->dsa
(dsa_area *) $3 = 0x0000000000000000
(lldb) print node->ss.ps.state->es_query_dsa
(dsa_area *) $5 = 0x0000000000000000
(lldb) f 17
frame #17: 0x000000010800363b
postgres`ExecGather(pstate=0x00007f9743019320) + 635 at
nodeGather.c:220
217 * Get next tuple, either from one of our workers, or by running the plan
218 * ourselves.
219 */
-> 220 slot = gather_getnext(node);
221 if (TupIsNull(slot))
222 return NULL;
223
(lldb) print *node->pei
(ParallelExecutorInfo) $8 = {
planstate = 0x00007f9743019640
pcxt = 0x00007f97450001b8
buffer_usage = 0x0000000108b7e218
instrumentation = 0x0000000108b7da38
area = 0x0000000000000000
param_exec = 0
finished = '\0'
tqueue = 0x0000000000000000
reader = 0x0000000000000000
}
(lldb) print *node->pei->pcxt
warning: could not load any Objective-C class information. This will
significantly reduce the quality of type information available.
(ParallelContext) $9 = {
node = {
prev = 0x000000010855fb60
next = 0x000000010855fb60
}
subid = 1
nworkers = 0
nworkers_launched = 0
library_name = 0x00007f9745000248 "postgres"
function_name = 0x00007f9745000268 "ParallelQueryMain"
error_context_stack = 0x0000000000000000
estimator = (space_for_chunks = 180352, number_of_keys = 19)
seg = 0x0000000000000000
private_memory = 0x0000000108b53038
toc = 0x0000000108b53038
worker = 0x0000000000000000
}
I think there are two failure modes: one of your sessions showed the
"too many ..." error (that's good, ran out of slots and said so and
our error machinery worked as it should), and another crashed with a
segfault, because it tried to use a NULL "area" pointer (bad). I
think this is a degenerate case where we completely failed to launch
parallel query, but we ran the parallel query plan anyway and this
code thinks that the DSA is available. Oops.
--
Thomas Munro
http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-28 07:32 Dilip Kumar <dilipbalaut@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 1 reply; 35+ messages in thread
From: Dilip Kumar @ 2017-11-28 07:32 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general; Robert Haas <robertmhaas@gmail.com>; pgsql-hackers <pgsql-hackers@postgresql.org>
On Tue, Nov 28, 2017 at 4:18 AM, Thomas Munro <thomas.munro@enterprisedb.com
> wrote:
> On Tue, Nov 28, 2017 at 10:05 AM, Jakub Glapa <jakub.glapa@gmail.com>
> wrote:
> > As for the crash. I dug up the initial log and it looks like a
> segmentation
> > fault...
> >
> > 2017-11-23 07:26:53 CET:192.168.10.83(35238):user@db:[30003]: ERROR:
> too
> > many dynamic shared memory segments
>
> I think there are two failure modes: one of your sessions showed the
> "too many ..." error (that's good, ran out of slots and said so and
> our error machinery worked as it should), and another crashed with a
> segfault, because it tried to use a NULL "area" pointer (bad). I
> think this is a degenerate case where we completely failed to launch
> parallel query, but we ran the parallel query plan anyway and this
> code thinks that the DSA is available. Oops.
>
I think BitmapHeapScan check whether dsa is valid or not if DSA is not
valid then it should assume it's non-parallel plan.
Attached patch should fix the issue.
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
Attachments:
bug_fix_in_pbhs_when_dsa_not_initialized.patch (application/octet-stream, 679B) download
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index b885f2a..b03e44e 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -83,9 +83,13 @@ BitmapHeapNext(BitmapHeapScanState *node)
TBMIterateResult *tbmres;
OffsetNumber targoffset;
TupleTableSlot *slot;
- ParallelBitmapHeapState *pstate = node->pstate;
+ ParallelBitmapHeapState *pstate = NULL;
dsa_area *dsa = node->ss.ps.state->es_query_dsa;
+ /* if DSA is NULL then go for non-parallel mode */
+ if (dsa != NULL)
+ pstate = node->pstate;
+
/*
* extract necessary information from index scan node
*/
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-28 13:43 Robert Haas <robertmhaas@gmail.com>
parent: Dilip Kumar <dilipbalaut@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Robert Haas @ 2017-11-28 13:43 UTC (permalink / raw)
To: Dilip Kumar <dilipbalaut@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general; pgsql-hackers <pgsql-hackers@postgresql.org>
On Tue, Nov 28, 2017 at 2:32 AM, Dilip Kumar <dilipbalaut@gmail.com> wrote:
> I think BitmapHeapScan check whether dsa is valid or not if DSA is not
> valid then it should assume it's non-parallel plan.
>
> Attached patch should fix the issue.
So, create the pstate and then pretend we didn't? Why not just avoid
creating it in the first place, like this?
I haven't checked whether this fixes the bug, but if it does, we can
avoid introducing an extra branch in BitmapHeapNext.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
no-pstate.patch (application/octet-stream, 1.2K) download
diff --git a/src/backend/executor/nodeBitmapHeapscan.c b/src/backend/executor/nodeBitmapHeapscan.c
index 221391908c..eb5bbb57ef 100644
--- a/src/backend/executor/nodeBitmapHeapscan.c
+++ b/src/backend/executor/nodeBitmapHeapscan.c
@@ -1051,6 +1051,11 @@ ExecBitmapHeapInitializeDSM(BitmapHeapScanState *node,
{
ParallelBitmapHeapState *pstate;
EState *estate = node->ss.ps.state;
+ dsa_area *dsa = node->ss.ps.state->es_query_dsa;
+
+ /* If there's no DSA, there are no workers; initialize nothing. */
+ if (dsa == NULL)
+ return;
pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
@@ -1083,6 +1088,10 @@ ExecBitmapHeapReInitializeDSM(BitmapHeapScanState *node,
ParallelBitmapHeapState *pstate = node->pstate;
dsa_area *dsa = node->ss.ps.state->es_query_dsa;
+ /* If there's no DSA, there are no workers; do nothing. */
+ if (dsa == NULL)
+ return;
+
pstate->state = BM_INITIAL;
if (DsaPointerIsValid(pstate->tbmiterator))
@@ -1108,6 +1117,8 @@ ExecBitmapHeapInitializeWorker(BitmapHeapScanState *node,
ParallelBitmapHeapState *pstate;
Snapshot snapshot;
+ Assert(node->ss.ps.state->es_query_dsa != NULL);
+
pstate = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
node->pstate = pstate;
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-28 14:45 Dilip Kumar <dilipbalaut@gmail.com>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Dilip Kumar @ 2017-11-28 14:45 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general; pgsql-hackers <pgsql-hackers@postgresql.org>
On Tue, Nov 28, 2017 at 7:13 PM, Robert Haas <robertmhaas@gmail.com> wrote:
> On Tue, Nov 28, 2017 at 2:32 AM, Dilip Kumar <dilipbalaut@gmail.com>
> wrote:
> > I think BitmapHeapScan check whether dsa is valid or not if DSA is not
> > valid then it should assume it's non-parallel plan.
> >
> > Attached patch should fix the issue.
>
> So, create the pstate and then pretend we didn't? Why not just avoid
> creating it in the first place, like this?
>
This is better way to fix it.
>
> I haven't checked whether this fixes the bug, but if it does, we can
> avoid introducing an extra branch in BitmapHeapNext.
With my test it's fixing the problem.
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-11-28 16:58 Robert Haas <robertmhaas@gmail.com>
parent: Dilip Kumar <dilipbalaut@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Robert Haas @ 2017-11-28 16:58 UTC (permalink / raw)
To: Dilip Kumar <dilipbalaut@gmail.com>; +Cc: Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-general; pgsql-hackers <pgsql-hackers@postgresql.org>
On Tue, Nov 28, 2017 at 9:45 AM, Dilip Kumar <dilipbalaut@gmail.com> wrote:
>> I haven't checked whether this fixes the bug, but if it does, we can
>> avoid introducing an extra branch in BitmapHeapNext.
>
> With my test it's fixing the problem.
I tested it some more and found that, for me, it PARTIALLY fixes the
problem. I tested like this:
inline patch 1: src/backend/access/transam/parallel.c (+1/-1 lines) download inline-1.patch
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -279,7 +279,7 @@ InitializeParallelDSM(ParallelContext *pcxt)
* parallelism than to fail outright.
*/
segsize = shm_toc_estimate(&pcxt->estimator);
- if (pcxt->nworkers > 0)
+ if (pcxt->nworkers > 0 && false)
pcxt->seg = dsm_create(segsize, DSM_CREATE_NULL_IF_MAXSEGMENTS);
if (pcxt->seg != NULL)
pcxt->toc = shm_toc_create(PARALLEL_MAGIC,
That turned out to produce more than one problem. I find that the
select_parallel test then fails like this:
ERROR: could not find key 18446744073709486082 in shm TOC at 0x10be98040
The fix for that problem seems to be:
inline patch 2: src/backend/access/transam/parallel.c (+2/-1 lines) download inline-2.patch
--- a/src/backend/access/transam/parallel.c
+++ b/src/backend/access/transam/parallel.c
@@ -430,7 +430,8 @@ ReinitializeParallelDSM(ParallelContext *pcxt)
/* Recreate error queues. */
error_queue_space =
- shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, false);
+ shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, true);
+ Assert(pcxt->nworkers == 0 || error_queue_space != NULL);
for (i = 0; i < pcxt->nworkers; ++i)
{
char *start;
With that fix in place, I then hit a crash in parallel bitmap heap
scan. After applying no-pstate.patch, which I just committed and
back-patched to v10, then things look OK. I'm going to apply the fix
for the error_queue_space problem also.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Patches: download all (2 files, .tar.gz)
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-12-04 12:18 Jakub Glapa <jakub.glapa@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
1 sibling, 1 reply; 35+ messages in thread
From: Jakub Glapa @ 2017-12-04 12:18 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-general
I see that the segfault is under active discussion but just wanted to ask
if increasing the max_connections to mitigate the DSM slots shortage is the
way to go?
--
regards,
Jakub Glapa
On Mon, Nov 27, 2017 at 11:48 PM, Thomas Munro <
thomas.munro@enterprisedb.com> wrote:
> On Tue, Nov 28, 2017 at 10:05 AM, Jakub Glapa <jakub.glapa@gmail.com>
> wrote:
> > As for the crash. I dug up the initial log and it looks like a
> segmentation
> > fault...
> >
> > 2017-11-23 07:26:53 CET:192.168.10.83(35238):user@db:[30003]: ERROR:
> too
> > many dynamic shared memory segments
>
> Hmm. Well this error can only occur in dsm_create() called without
> DSM_CREATE_NULL_IF_MAXSEGMENTS. parallel.c calls it with that flag
> and dsa.c doesn't (perhaps it should, not sure, but that'd just change
> the error message), so that means this the error arose from dsa.c
> trying to get more segments. That would be when Parallel Bitmap Heap
> Scan tried to allocate memory.
>
> I hacked my copy of PostgreSQL so that it allows only 5 DSM slots and
> managed to reproduce a segv crash by trying to run concurrent Parallel
> Bitmap Heap Scans. The stack looks like this:
>
> * frame #0: 0x00000001083ace29
> postgres`alloc_object(area=0x0000000000000000, size_class=10) + 25 at
> dsa.c:1433
> frame #1: 0x00000001083acd14
> postgres`dsa_allocate_extended(area=0x0000000000000000, size=72,
> flags=4) + 1076 at dsa.c:785
> frame #2: 0x0000000108059c33
> postgres`tbm_prepare_shared_iterate(tbm=0x00007f9743027660) + 67 at
> tidbitmap.c:780
> frame #3: 0x0000000108000d57
> postgres`BitmapHeapNext(node=0x00007f9743019c88) + 503 at
> nodeBitmapHeapscan.c:156
> frame #4: 0x0000000107fefc5b
> postgres`ExecScanFetch(node=0x00007f9743019c88,
> accessMtd=(postgres`BitmapHeapNext at nodeBitmapHeapscan.c:77),
> recheckMtd=(postgres`BitmapHeapRecheck at nodeBitmapHeapscan.c:710)) +
> 459 at execScan.c:95
> frame #5: 0x0000000107fef983
> postgres`ExecScan(node=0x00007f9743019c88,
> accessMtd=(postgres`BitmapHeapNext at nodeBitmapHeapscan.c:77),
> recheckMtd=(postgres`BitmapHeapRecheck at nodeBitmapHeapscan.c:710)) +
> 147 at execScan.c:162
> frame #6: 0x00000001080008d1
> postgres`ExecBitmapHeapScan(pstate=0x00007f9743019c88) + 49 at
> nodeBitmapHeapscan.c:735
>
> (lldb) f 3
> frame #3: 0x0000000108000d57
> postgres`BitmapHeapNext(node=0x00007f9743019c88) + 503 at
> nodeBitmapHeapscan.c:156
> 153 * dsa_pointer of the iterator state which will be used by
> 154 * multiple processes to iterate jointly.
> 155 */
> -> 156 pstate->tbmiterator = tbm_prepare_shared_iterate(tbm);
> 157 #ifdef USE_PREFETCH
> 158 if (node->prefetch_maximum > 0)
> 159
> (lldb) print tbm->dsa
> (dsa_area *) $3 = 0x0000000000000000
> (lldb) print node->ss.ps.state->es_query_dsa
> (dsa_area *) $5 = 0x0000000000000000
> (lldb) f 17
> frame #17: 0x000000010800363b
> postgres`ExecGather(pstate=0x00007f9743019320) + 635 at
> nodeGather.c:220
> 217 * Get next tuple, either from one of our workers, or by running the
> plan
> 218 * ourselves.
> 219 */
> -> 220 slot = gather_getnext(node);
> 221 if (TupIsNull(slot))
> 222 return NULL;
> 223
> (lldb) print *node->pei
> (ParallelExecutorInfo) $8 = {
> planstate = 0x00007f9743019640
> pcxt = 0x00007f97450001b8
> buffer_usage = 0x0000000108b7e218
> instrumentation = 0x0000000108b7da38
> area = 0x0000000000000000
> param_exec = 0
> finished = '\0'
> tqueue = 0x0000000000000000
> reader = 0x0000000000000000
> }
> (lldb) print *node->pei->pcxt
> warning: could not load any Objective-C class information. This will
> significantly reduce the quality of type information available.
> (ParallelContext) $9 = {
> node = {
> prev = 0x000000010855fb60
> next = 0x000000010855fb60
> }
> subid = 1
> nworkers = 0
> nworkers_launched = 0
> library_name = 0x00007f9745000248 "postgres"
> function_name = 0x00007f9745000268 "ParallelQueryMain"
> error_context_stack = 0x0000000000000000
> estimator = (space_for_chunks = 180352, number_of_keys = 19)
> seg = 0x0000000000000000
> private_memory = 0x0000000108b53038
> toc = 0x0000000108b53038
> worker = 0x0000000000000000
> }
>
> I think there are two failure modes: one of your sessions showed the
> "too many ..." error (that's good, ran out of slots and said so and
> our error machinery worked as it should), and another crashed with a
> segfault, because it tried to use a NULL "area" pointer (bad). I
> think this is a degenerate case where we completely failed to launch
> parallel query, but we ran the parallel query plan anyway and this
> code thinks that the DSA is available. Oops.
>
> --
> Thomas Munro
> http://www.enterprisedb.com
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-12-07 21:30 Thomas Munro <thomas.munro@enterprisedb.com>
parent: Jakub Glapa <jakub.glapa@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2017-12-07 21:30 UTC (permalink / raw)
To: Jakub Glapa <jakub.glapa@gmail.com>; +Cc: pgsql-general
On Tue, Dec 5, 2017 at 1:18 AM, Jakub Glapa <jakub.glapa@gmail.com> wrote:
> I see that the segfault is under active discussion but just wanted to ask if
> increasing the max_connections to mitigate the DSM slots shortage is the way
> to go?
Hi Jakub,
Yes. In future releases this situation will improve (maybe we'll
figure out how to use one DSM segment for all the gather nodes in your
query plan, and maybe it'll be moot anyway because maybe we'll be able
to use a Parallel Append for queries like yours so that it uses the
same set of workers over all the child plans instead of the
fork()-fest you're presumably seeing). For now your only choice, if
you want that plan to run, is to crank up max_connections so that the
total number of concurrently executing Gather nodes is less than about
64 + 2 * max_connections. There is also a crash bug right now in the
out-of-slots case as discussed, fixed in the next point release, but
even with that fix in place you'll still need a high enough
max_connections setting to be sure to be able to complete the query
without an error.
Thanks for the report!
--
Thomas Munro
http://www.enterprisedb.com
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2017-12-08 07:59 Jakub Glapa <jakub.glapa@gmail.com>
parent: Thomas Munro <thomas.munro@enterprisedb.com>
0 siblings, 0 replies; 35+ messages in thread
From: Jakub Glapa @ 2017-12-08 07:59 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@enterprisedb.com>; +Cc: pgsql-general
Thank You Thomas!
--
regards,
Jakub Glapa
On Thu, Dec 7, 2017 at 10:30 PM, Thomas Munro <thomas.munro@enterprisedb.com
> wrote:
> On Tue, Dec 5, 2017 at 1:18 AM, Jakub Glapa <jakub.glapa@gmail.com> wrote:
> > I see that the segfault is under active discussion but just wanted to
> ask if
> > increasing the max_connections to mitigate the DSM slots shortage is the
> way
> > to go?
>
> Hi Jakub,
>
> Yes. In future releases this situation will improve (maybe we'll
> figure out how to use one DSM segment for all the gather nodes in your
> query plan, and maybe it'll be moot anyway because maybe we'll be able
> to use a Parallel Append for queries like yours so that it uses the
> same set of workers over all the child plans instead of the
> fork()-fest you're presumably seeing). For now your only choice, if
> you want that plan to run, is to crank up max_connections so that the
> total number of concurrently executing Gather nodes is less than about
> 64 + 2 * max_connections. There is also a crash bug right now in the
> out-of-slots case as discussed, fixed in the next point release, but
> even with that fix in place you'll still need a high enough
> max_connections setting to be sure to be able to complete the query
> without an error.
>
> Thanks for the report!
>
> --
> Thomas Munro
> http://www.enterprisedb.com
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2018-02-02 20:01 Tom Lane <tgl@sss.pgh.pa.us>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Tom Lane @ 2018-02-02 20:01 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Dilip Kumar <dilipbalaut@gmail.com>; Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-hackers <pgsql-hackers@postgresql.org>
Robert Haas <robertmhaas@gmail.com> writes:
> That turned out to produce more than one problem. I find that the
> select_parallel test then fails like this:
> ERROR: could not find key 18446744073709486082 in shm TOC at 0x10be98040
> The fix for that problem seems to be:
> /* Recreate error queues. */
> error_queue_space =
> - shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, false);
> + shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, true);
> + Assert(pcxt->nworkers == 0 || error_queue_space != NULL);
I happened across this patch while preparing the release notes, and
I'm quite distressed by it, because it completely breaks the point
of what I'd done in commit d46633506 (to wit, to not just blindly
assume, nor just Assert, that shm_toc_lookup always succeeds).
Do you mind if I change that Assert to a run-time test?
regards, tom lane
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2018-02-02 20:19 Robert Haas <robertmhaas@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 35+ messages in thread
From: Robert Haas @ 2018-02-02 20:19 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Dilip Kumar <dilipbalaut@gmail.com>; Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-hackers <pgsql-hackers@postgresql.org>
On Fri, Feb 2, 2018 at 3:01 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Robert Haas <robertmhaas@gmail.com> writes:
>> That turned out to produce more than one problem. I find that the
>> select_parallel test then fails like this:
>> ERROR: could not find key 18446744073709486082 in shm TOC at 0x10be98040
>> The fix for that problem seems to be:
>
>> /* Recreate error queues. */
>> error_queue_space =
>> - shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, false);
>> + shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, true);
>> + Assert(pcxt->nworkers == 0 || error_queue_space != NULL);
>
> I happened across this patch while preparing the release notes, and
> I'm quite distressed by it, because it completely breaks the point
> of what I'd done in commit d46633506 (to wit, to not just blindly
> assume, nor just Assert, that shm_toc_lookup always succeeds).
> Do you mind if I change that Assert to a run-time test?
Hrm, I guess I could have done something like
shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, (pcxt->nworkers ==
0)).
I don't mind much if you change it, but I will note that for the
record, before d46633506, we had a theoretical source of bugs, whereas
after that commit, we had a bug. 445dbd82a fixed that; if you change
this around again, please take care not to make it buggy again.
Otherwise, I'll be the one who is quite distressed. :-)
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2018-02-02 20:56 Tom Lane <tgl@sss.pgh.pa.us>
parent: Robert Haas <robertmhaas@gmail.com>
0 siblings, 0 replies; 35+ messages in thread
From: Tom Lane @ 2018-02-02 20:56 UTC (permalink / raw)
To: Robert Haas <robertmhaas@gmail.com>; +Cc: Dilip Kumar <dilipbalaut@gmail.com>; Thomas Munro <thomas.munro@enterprisedb.com>; Jakub Glapa <jakub.glapa@gmail.com>; pgsql-hackers <pgsql-hackers@postgresql.org>
Robert Haas <robertmhaas@gmail.com> writes:
> On Fri, Feb 2, 2018 at 3:01 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Do you mind if I change that Assert to a run-time test?
> Hrm, I guess I could have done something like
> shm_toc_lookup(pcxt->toc, PARALLEL_KEY_ERROR_QUEUE, (pcxt->nworkers ==
> 0)).
OK, that'd work too. I'll make it so.
regards, tom lane
^ permalink raw reply [nested|flat] 35+ messages in thread
* ERROR: too many dynamic shared memory segments
@ 2019-09-11 07:47 Nicola Contu <nicola.contu@gmail.com>
0 siblings, 2 replies; 35+ messages in thread
From: Nicola Contu @ 2019-09-11 07:47 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; +Cc: Alessandro Aste <Alessandro.aste@gtt.net>
Hello,
We are running postgres 11.5 and in the last two weeks we did :
- upgrade of postgres to 11.5 from 11.4
- increased shared_buffer to 1/3 of the memory
- increased effective_cache_size = 160GB from 120
- increased checkpoint_completion_target = 0.9 from 0.7
- increased checkpoint_timeout = 1h
- increased work_mem = 2GB (this can be set up to 4GB) from 600MB
Since that, in the last two weeks we saw an increment of this error :
ERROR: too many dynamic shared memory segments
Is there any relation between these parameters or the pgsql 11.5 version?
Any help can be appreciated.
Thank you,
Nicola
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2019-09-11 08:09 Pavel Stehule <pavel.stehule@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
1 sibling, 1 reply; 35+ messages in thread
From: Pavel Stehule @ 2019-09-11 08:09 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hi
st 11. 9. 2019 v 9:48 odesÃlatel Nicola Contu <nicola.contu@gmail.com>
napsal:
> Hello,
> We are running postgres 11.5 and in the last two weeks we did :
>
> - upgrade of postgres to 11.5 from 11.4
> - increased shared_buffer to 1/3 of the memory
> - increased effective_cache_size = 160GB from 120
> - increased checkpoint_completion_target = 0.9 from 0.7
> - increased checkpoint_timeout = 1h
> - increased work_mem = 2GB (this can be set up to 4GB) from 600MB
>
> Since that, in the last two weeks we saw an increment of this error :
>
> ERROR: too many dynamic shared memory segments
>
> Is there any relation between these parameters or the pgsql 11.5 version?
>
I expect it can be related to increasing work_mem - maybe parallel hash
join was used
Regards
Pavel
>
> Any help can be appreciated.
>
> Thank you,
> Nicola
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2019-09-11 08:19 Nicola Contu <nicola.contu@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
1 sibling, 0 replies; 35+ messages in thread
From: Nicola Contu @ 2019-09-11 08:19 UTC (permalink / raw)
To: Mickael Franc (mickaelf) <mickaelf@cisco.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hello,
We did not see any error in the logs, just that one.
Unfortunately we had problems installing updates in this machine and we are
not installing updates since a few months.
Do you think that can be the issue? We are running Centos 7.
I will look into those parameters as well.
Thanks for your feedback
Il giorno mer 11 set 2019 alle ore 09:56 Mickael Franc (mickaelf) <
mickaelf@cisco.com> ha scritto:
> Hello,
>
> Maybe a change needed in a kernel parameter such "kernel.shmmax" or
> "kernel.shmall" to allow by kernel to provide a huge shared-mem.
> Did you see any other error in logs ? Have you upgrade your kernel since
> last two weeks ?
>
> Best,
> ------------------------------
> *De :* Nicola Contu <nicola.contu@gmail.com>
> *Envoyé :* mercredi 11 septembre 2019 09:47
> *À :* pgsql-generallists.postgresql.org <
> pgsql-general@lists.postgresql.org>
> *Cc :* Alessandro Aste <Alessandro.aste@gtt.net>
> *Objet :* ERROR: too many dynamic shared memory segments
>
> Hello,
> We are running postgres 11.5 and in the last two weeks we did :
>
> - upgrade of postgres to 11.5 from 11.4
> - increased shared_buffer to 1/3 of the memory
> - increased effective_cache_size = 160GB from 120
> - increased checkpoint_completion_target = 0.9 from 0.7
> - increased checkpoint_timeout = 1h
> - increased work_mem = 2GB (this can be set up to 4GB) from 600MB
>
> Since that, in the last two weeks we saw an increment of this error :
>
> ERROR: too many dynamic shared memory segments
>
> Is there any relation between these parameters or the pgsql 11.5 version?
>
> Any help can be appreciated.
>
> Thank you,
> Nicola
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2019-09-11 08:27 Nicola Contu <nicola.contu@gmail.com>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Nicola Contu @ 2019-09-11 08:27 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
If the error persist I will try to revert the work_mem.
Thanks a lot
Il giorno mer 11 set 2019 alle ore 10:10 Pavel Stehule <
pavel.stehule@gmail.com> ha scritto:
> Hi
>
> st 11. 9. 2019 v 9:48 odesÃlatel Nicola Contu <nicola.contu@gmail.com>
> napsal:
>
>> Hello,
>> We are running postgres 11.5 and in the last two weeks we did :
>>
>> - upgrade of postgres to 11.5 from 11.4
>> - increased shared_buffer to 1/3 of the memory
>> - increased effective_cache_size = 160GB from 120
>> - increased checkpoint_completion_target = 0.9 from 0.7
>> - increased checkpoint_timeout = 1h
>> - increased work_mem = 2GB (this can be set up to 4GB) from 600MB
>>
>> Since that, in the last two weeks we saw an increment of this error :
>>
>> ERROR: too many dynamic shared memory segments
>>
>> Is there any relation between these parameters or the pgsql 11.5 version?
>>
>
> I expect it can be related to increasing work_mem - maybe parallel hash
> join was used
>
> Regards
>
> Pavel
>
>>
>> Any help can be appreciated.
>>
>> Thank you,
>> Nicola
>>
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2019-09-11 23:00 Thomas Munro <thomas.munro@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2019-09-11 23:00 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Wed, Sep 11, 2019 at 11:20 PM Nicola Contu <nicola.contu@gmail.com> wrote:
> If the error persist I will try to revert the work_mem.
> Thanks a lot
Hi Nicola,
It's hard to say exactly what the cause of the problem is in your case
and how to avoid it, without knowing what your query plans look like.
PostgreSQL allows 64 + 2 * max_connections segments to exist a time,
and it needs a number of them that depends on work_mem (in the case of
Parallel Hash Join and Parallel Bitmap Index Scan), and also depends
on the number of Gather nodes that appear in the plan, which in some
unusual cases can result from partitioning.
I've seen people reaching this error by running a lot of parallel
queries concurrently. If that's the cause, then you can definitely
get some relief by turning work_mem down, or by turning
max_connections up (even though you don't want to allow more
connections -- because it influences the formula for deciding on the
DSM segment limit). We should probably adjust some of the internal
constants to give us more slots, to avoid that problem, as discussed
here:
https://www.postgresql.org/message-id/flat/CA%2BhUKGL6H2BpGbiF7Lj6QiTjTGyTLW_vLR%3DSn2tEBeTcYXiMKw%4...
I've also seen people reaching this error by somehow coming up with
plans that had a very large number of Gather nodes in them,
corresponding to partitions; that's probably a bad plan (it'd
presumably be better to terminate parallelism higher up in the plan,
but these plans do seem to exist in the wild; I don't recall exactly
why). I think we need a bit of a redesign so that if there are
multiple Gather nodes, they share the same main DSM segment, instead
of blowing through this limit.
--
Thomas Munro
https://enterprisedb.com
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-21 15:06 Nicola Contu <nicola.contu@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Nicola Contu @ 2020-01-21 15:06 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hey Thomas,
after a few months, we started having this issue again.
So we revert the work_mem parameter to 600MB instead of 2GB.
But the issue is still there. A query went to segmentation fault, the DB
went to recovery mode and our app went to read only for a few minutes.
I understand we can increase max_connections so we can have many more
segments.
My question is : is there a way to understand the number of segments we
reached?
Currently we have 220 max_conn so as your formula is 64 + 2* 220 we have
about 500 shared segments.
We would like to increase that number to 300 or 400 but would be great to
understand if there is a way to make sure we will solve the issue as it
requires a restart of the service.
I know you were also talking about a redesign this part in PostgreSQL. Do
you know if anything has changed in any of the newer versions after 11.5?
Thanks a lot,
Nicola
Il giorno gio 12 set 2019 alle ore 01:01 Thomas Munro <
thomas.munro@gmail.com> ha scritto:
> On Wed, Sep 11, 2019 at 11:20 PM Nicola Contu <nicola.contu@gmail.com>
> wrote:
> > If the error persist I will try to revert the work_mem.
> > Thanks a lot
>
> Hi Nicola,
>
> It's hard to say exactly what the cause of the problem is in your case
> and how to avoid it, without knowing what your query plans look like.
> PostgreSQL allows 64 + 2 * max_connections segments to exist a time,
> and it needs a number of them that depends on work_mem (in the case of
> Parallel Hash Join and Parallel Bitmap Index Scan), and also depends
> on the number of Gather nodes that appear in the plan, which in some
> unusual cases can result from partitioning.
>
> I've seen people reaching this error by running a lot of parallel
> queries concurrently. If that's the cause, then you can definitely
> get some relief by turning work_mem down, or by turning
> max_connections up (even though you don't want to allow more
> connections -- because it influences the formula for deciding on the
> DSM segment limit). We should probably adjust some of the internal
> constants to give us more slots, to avoid that problem, as discussed
> here:
>
>
> https://www.postgresql.org/message-id/flat/CA%2BhUKGL6H2BpGbiF7Lj6QiTjTGyTLW_vLR%3DSn2tEBeTcYXiMKw%4...
>
> I've also seen people reaching this error by somehow coming up with
> plans that had a very large number of Gather nodes in them,
> corresponding to partitions; that's probably a bad plan (it'd
> presumably be better to terminate parallelism higher up in the plan,
> but these plans do seem to exist in the wild; I don't recall exactly
> why). I think we need a bit of a redesign so that if there are
> multiple Gather nodes, they share the same main DSM segment, instead
> of blowing through this limit.
>
> --
> Thomas Munro
> https://enterprisedb.com
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-21 16:14 Nicola Contu <nicola.contu@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Nicola Contu @ 2020-01-21 16:14 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
We also reverted this param :
cmdv3=# show max_parallel_workers_per_gather;
max_parallel_workers_per_gather
---------------------------------
2
(1 row)
It was set to 8.
Il giorno mar 21 gen 2020 alle ore 16:06 Nicola Contu <
nicola.contu@gmail.com> ha scritto:
> Hey Thomas,
> after a few months, we started having this issue again.
> So we revert the work_mem parameter to 600MB instead of 2GB.
> But the issue is still there. A query went to segmentation fault, the DB
> went to recovery mode and our app went to read only for a few minutes.
>
> I understand we can increase max_connections so we can have many more
> segments.
>
> My question is : is there a way to understand the number of segments we
> reached?
> Currently we have 220 max_conn so as your formula is 64 + 2* 220 we have
> about 500 shared segments.
> We would like to increase that number to 300 or 400 but would be great to
> understand if there is a way to make sure we will solve the issue as it
> requires a restart of the service.
>
> I know you were also talking about a redesign this part in PostgreSQL. Do
> you know if anything has changed in any of the newer versions after 11.5?
>
> Thanks a lot,
> Nicola
>
>
>
>
>
> Il giorno gio 12 set 2019 alle ore 01:01 Thomas Munro <
> thomas.munro@gmail.com> ha scritto:
>
>> On Wed, Sep 11, 2019 at 11:20 PM Nicola Contu <nicola.contu@gmail.com>
>> wrote:
>> > If the error persist I will try to revert the work_mem.
>> > Thanks a lot
>>
>> Hi Nicola,
>>
>> It's hard to say exactly what the cause of the problem is in your case
>> and how to avoid it, without knowing what your query plans look like.
>> PostgreSQL allows 64 + 2 * max_connections segments to exist a time,
>> and it needs a number of them that depends on work_mem (in the case of
>> Parallel Hash Join and Parallel Bitmap Index Scan), and also depends
>> on the number of Gather nodes that appear in the plan, which in some
>> unusual cases can result from partitioning.
>>
>> I've seen people reaching this error by running a lot of parallel
>> queries concurrently. If that's the cause, then you can definitely
>> get some relief by turning work_mem down, or by turning
>> max_connections up (even though you don't want to allow more
>> connections -- because it influences the formula for deciding on the
>> DSM segment limit). We should probably adjust some of the internal
>> constants to give us more slots, to avoid that problem, as discussed
>> here:
>>
>>
>> https://www.postgresql.org/message-id/flat/CA%2BhUKGL6H2BpGbiF7Lj6QiTjTGyTLW_vLR%3DSn2tEBeTcYXiMKw%4...
>>
>> I've also seen people reaching this error by somehow coming up with
>> plans that had a very large number of Gather nodes in them,
>> corresponding to partitions; that's probably a bad plan (it'd
>> presumably be better to terminate parallelism higher up in the plan,
>> but these plans do seem to exist in the wild; I don't recall exactly
>> why). I think we need a bit of a redesign so that if there are
>> multiple Gather nodes, they share the same main DSM segment, instead
>> of blowing through this limit.
>>
>> --
>> Thomas Munro
>> https://enterprisedb.com
>>
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 08:34 Nicola Contu <nicola.contu@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Nicola Contu @ 2020-01-29 08:34 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hello, may I ask you for a feedback?
Thanks a lot
Il giorno mar 21 gen 2020 alle ore 17:14 Nicola Contu <
nicola.contu@gmail.com> ha scritto:
> We also reverted this param :
>
> cmdv3=# show max_parallel_workers_per_gather;
> max_parallel_workers_per_gather
> ---------------------------------
> 2
> (1 row)
>
> It was set to 8.
>
>
> Il giorno mar 21 gen 2020 alle ore 16:06 Nicola Contu <
> nicola.contu@gmail.com> ha scritto:
>
>> Hey Thomas,
>> after a few months, we started having this issue again.
>> So we revert the work_mem parameter to 600MB instead of 2GB.
>> But the issue is still there. A query went to segmentation fault, the DB
>> went to recovery mode and our app went to read only for a few minutes.
>>
>> I understand we can increase max_connections so we can have many more
>> segments.
>>
>> My question is : is there a way to understand the number of segments we
>> reached?
>> Currently we have 220 max_conn so as your formula is 64 + 2* 220 we have
>> about 500 shared segments.
>> We would like to increase that number to 300 or 400 but would be great to
>> understand if there is a way to make sure we will solve the issue as it
>> requires a restart of the service.
>>
>> I know you were also talking about a redesign this part in PostgreSQL. Do
>> you know if anything has changed in any of the newer versions after 11.5?
>>
>> Thanks a lot,
>> Nicola
>>
>>
>>
>>
>>
>> Il giorno gio 12 set 2019 alle ore 01:01 Thomas Munro <
>> thomas.munro@gmail.com> ha scritto:
>>
>>> On Wed, Sep 11, 2019 at 11:20 PM Nicola Contu <nicola.contu@gmail.com>
>>> wrote:
>>> > If the error persist I will try to revert the work_mem.
>>> > Thanks a lot
>>>
>>> Hi Nicola,
>>>
>>> It's hard to say exactly what the cause of the problem is in your case
>>> and how to avoid it, without knowing what your query plans look like.
>>> PostgreSQL allows 64 + 2 * max_connections segments to exist a time,
>>> and it needs a number of them that depends on work_mem (in the case of
>>> Parallel Hash Join and Parallel Bitmap Index Scan), and also depends
>>> on the number of Gather nodes that appear in the plan, which in some
>>> unusual cases can result from partitioning.
>>>
>>> I've seen people reaching this error by running a lot of parallel
>>> queries concurrently. If that's the cause, then you can definitely
>>> get some relief by turning work_mem down, or by turning
>>> max_connections up (even though you don't want to allow more
>>> connections -- because it influences the formula for deciding on the
>>> DSM segment limit). We should probably adjust some of the internal
>>> constants to give us more slots, to avoid that problem, as discussed
>>> here:
>>>
>>>
>>> https://www.postgresql.org/message-id/flat/CA%2BhUKGL6H2BpGbiF7Lj6QiTjTGyTLW_vLR%3DSn2tEBeTcYXiMKw%4...
>>>
>>> I've also seen people reaching this error by somehow coming up with
>>> plans that had a very large number of Gather nodes in them,
>>> corresponding to partitions; that's probably a bad plan (it'd
>>> presumably be better to terminate parallelism higher up in the plan,
>>> but these plans do seem to exist in the wild; I don't recall exactly
>>> why). I think we need a bit of a redesign so that if there are
>>> multiple Gather nodes, they share the same main DSM segment, instead
>>> of blowing through this limit.
>>>
>>> --
>>> Thomas Munro
>>> https://enterprisedb.com
>>>
>>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 09:09 Thomas Munro <thomas.munro@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2020-01-29 09:09 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Wed, Jan 22, 2020 at 4:06 AM Nicola Contu <nicola.contu@gmail.com> wrote:
> after a few months, we started having this issue again.
> So we revert the work_mem parameter to 600MB instead of 2GB.
> But the issue is still there. A query went to segmentation fault, the DB went to recovery mode and our app went to read only for a few minutes.
Hi Nicola,
Hmm, a segmentation fault sounds like a different problem. Can you
please share the exact error messages from PostgreSQL and OS logs?
> I understand we can increase max_connections so we can have many more segments.
>
> My question is : is there a way to understand the number of segments we reached?
If you're on Linux, you can probably see them with "ls /dev/shm".
> Currently we have 220 max_conn so as your formula is 64 + 2* 220 we have about 500 shared segments.
> We would like to increase that number to 300 or 400 but would be great to understand if there is a way to make sure we will solve the issue as it requires a restart of the service.
>
> I know you were also talking about a redesign this part in PostgreSQL. Do you know if anything has changed in any of the newer versions after 11.5?
It's possible that we should increase a couple of constants used the
formula -- I'll look into that again. But first I'd like to see if
we're even investigating the right problem here.
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 09:37 Nicola Contu <nicola.contu@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 2 replies; 35+ messages in thread
From: Nicola Contu @ 2020-01-29 09:37 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
This is the error on postgres log of the segmentation fault :
2020-01-21 14:20:29 GMT [] [42222]: [108-1] db=,user= LOG: server process
(PID 2042) was terminated by signal 11: Segmentation fault
2020-01-21 14:20:29 GMT [] [42222]: [109-1] db=,user= DETAIL: Failed
process was running: select pid from pg_stat_activity where query ilike
'REFRESH MATERIALIZED VIEW CONCURRENTLY matview_vrs_request_stats'
2020-01-21 14:20:29 GMT [] [42222]: [110-1] db=,user= LOG: terminating any
other active server processes
2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [4-1]
db=cmdv3,user=admin WARNING: terminating connection because of crash of
another server process
2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [5-1]
db=cmdv3,user=admin DETAIL: The postmaster has commanded this server
process to roll back the current transaction and exit, because another
server process exited abnormally and possibly corrupted shared memory.
2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [6-1]
db=cmdv3,user=admin HINT: In a moment you should be able to reconnect to
the database and repeat your command.
2020-01-21 14:20:29 GMT [127.0.0.1(34026)] [2055]: [5-1]
db=cmdv3,user=admin WARNING: terminating connection because of crash of
another server process
At CentOS level :
Jan 21 14:20:29 usnyh-cmd1.gt-t.net kernel: postmaster[2042]: segfault at 0
ip 000000000048bef4 sp 00007ffdf4955bb0 error 4 in postgres[400000+6c5000]
Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905 GMT
[33727] WARNING C-0x21526e8: cmdv3/admin@10.151.2.154:39688 pooler error:
server conn crashed?
Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905 GMT
[33727] WARNING S-0x1f5ff58: cmdv3/admin@127.0.0.1:5432 got packet 'N' from
server when not linked
Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905 GMT
[33727] WARNING S-0x25097f0: cmdv3/admin@127.0.0.1:5432 got packet 'N' from
server when not linked
Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.906 GMT
[33727] WARNING S-0x2508b60: cmdv3/admin@127.0.0.1:5432 got packet 'N' from
server when not linked
Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.981 GMT
[33727] ERROR S: login failed: FATAL: the database system is in recovery
mode
> If you're on Linux, you can probably see them with "ls /dev/shm".
I see a lot of files there, and doing a cat they are empty. What can I do
with them?
Those are two different problems I guess, but they are related because
right before the Segmentation Fault I see a lot of shared segment errors in
the postgres log.
Il giorno mer 29 gen 2020 alle ore 10:09 Thomas Munro <
thomas.munro@gmail.com> ha scritto:
> On Wed, Jan 22, 2020 at 4:06 AM Nicola Contu <nicola.contu@gmail.com>
> wrote:
> > after a few months, we started having this issue again.
> > So we revert the work_mem parameter to 600MB instead of 2GB.
> > But the issue is still there. A query went to segmentation fault, the DB
> went to recovery mode and our app went to read only for a few minutes.
>
> Hi Nicola,
> Hmm, a segmentation fault sounds like a different problem. Can you
> please share the exact error messages from PostgreSQL and OS logs?
>
> > I understand we can increase max_connections so we can have many more
> segments.
> >
> > My question is : is there a way to understand the number of segments we
> reached?
>
> If you're on Linux, you can probably see them with "ls /dev/shm".
>
> > Currently we have 220 max_conn so as your formula is 64 + 2* 220 we have
> about 500 shared segments.
> > We would like to increase that number to 300 or 400 but would be great
> to understand if there is a way to make sure we will solve the issue as it
> requires a restart of the service.
> >
> > I know you were also talking about a redesign this part in PostgreSQL.
> Do you know if anything has changed in any of the newer versions after 11.5?
>
> It's possible that we should increase a couple of constants used the
> formula -- I'll look into that again. But first I'd like to see if
> we're even investigating the right problem here.
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 10:23 Julian Backes <julianbackes@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
1 sibling, 1 reply; 35+ messages in thread
From: Julian Backes @ 2020-01-29 10:23 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Thomas Munro <thomas.munro@gmail.com>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hi,
we only had the "too many shared too many dynamic shared memory segments"
error but no segmentation faults. The error started occurring after
upgrading from postgres 10 to postgres 12 (server has 24 cores / 48
threads, i.e. many parallel workers). The error itself was not that much of
a problem but /dev/shm started filling up with orphaned files which
probably (?) had not been cleaned up by postgres after the parallel workers
died. In consequence, after some time, /dev/shm was full and everything
crashed.
Unfortunately, the only "solution" we found so far was to increase max
connections from 100 to 1000. After that (about 2 months ago I think), the
error had gone.
Maybe this helps...
Julian
Am Mi., 29. Jan. 2020 um 10:37 Uhr schrieb Nicola Contu <
nicola.contu@gmail.com>:
> This is the error on postgres log of the segmentation fault :
>
> 2020-01-21 14:20:29 GMT [] [42222]: [108-1] db=,user= LOG: server process
> (PID 2042) was terminated by signal 11: Segmentation fault
> 2020-01-21 14:20:29 GMT [] [42222]: [109-1] db=,user= DETAIL: Failed
> process was running: select pid from pg_stat_activity where query ilike
> 'REFRESH MATERIALIZED VIEW CONCURRENTLY matview_vrs_request_stats'
> 2020-01-21 14:20:29 GMT [] [42222]: [110-1] db=,user= LOG: terminating
> any other active server processes
> 2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [4-1]
> db=cmdv3,user=admin WARNING: terminating connection because of crash of
> another server process
> 2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [5-1]
> db=cmdv3,user=admin DETAIL: The postmaster has commanded this server
> process to roll back the current transaction and exit, because another
> server process exited abnormally and possibly corrupted shared memory.
> 2020-01-21 14:20:29 GMT [127.0.0.1(34256)] [2724]: [6-1]
> db=cmdv3,user=admin HINT: In a moment you should be able to reconnect to
> the database and repeat your command.
> 2020-01-21 14:20:29 GMT [127.0.0.1(34026)] [2055]: [5-1]
> db=cmdv3,user=admin WARNING: terminating connection because of crash of
> another server process
>
> At CentOS level :
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net kernel: postmaster[2042]: segfault at
> 0 ip 000000000048bef4 sp 00007ffdf4955bb0 error 4 in postgres[400000+6c5000]
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905
> GMT [33727] WARNING C-0x21526e8: cmdv3/admin@10.151.2.154:39688 pooler
> error: server conn crashed?
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905
> GMT [33727] WARNING S-0x1f5ff58: cmdv3/admin@127.0.0.1:5432 got packet
> 'N' from server when not linked
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.905
> GMT [33727] WARNING S-0x25097f0: cmdv3/admin@127.0.0.1:5432 got packet
> 'N' from server when not linked
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.906
> GMT [33727] WARNING S-0x2508b60: cmdv3/admin@127.0.0.1:5432 got packet
> 'N' from server when not linked
> Jan 21 14:20:29 usnyh-cmd1.gt-t.net pgbouncer: 2020-01-21 14:20:29.981
> GMT [33727] ERROR S: login failed: FATAL: the database system is in
> recovery mode
>
>
> > If you're on Linux, you can probably see them with "ls /dev/shm".
>
> I see a lot of files there, and doing a cat they are empty. What can I do
> with them?
>
> Those are two different problems I guess, but they are related because
> right before the Segmentation Fault I see a lot of shared segment errors in
> the postgres log.
>
> Il giorno mer 29 gen 2020 alle ore 10:09 Thomas Munro <
> thomas.munro@gmail.com> ha scritto:
>
>> On Wed, Jan 22, 2020 at 4:06 AM Nicola Contu <nicola.contu@gmail.com>
>> wrote:
>> > after a few months, we started having this issue again.
>> > So we revert the work_mem parameter to 600MB instead of 2GB.
>> > But the issue is still there. A query went to segmentation fault, the
>> DB went to recovery mode and our app went to read only for a few minutes.
>>
>> Hi Nicola,
>> Hmm, a segmentation fault sounds like a different problem. Can you
>> please share the exact error messages from PostgreSQL and OS logs?
>>
>> > I understand we can increase max_connections so we can have many more
>> segments.
>> >
>> > My question is : is there a way to understand the number of segments we
>> reached?
>>
>> If you're on Linux, you can probably see them with "ls /dev/shm".
>>
>> > Currently we have 220 max_conn so as your formula is 64 + 2* 220 we
>> have about 500 shared segments.
>> > We would like to increase that number to 300 or 400 but would be great
>> to understand if there is a way to make sure we will solve the issue as it
>> requires a restart of the service.
>> >
>> > I know you were also talking about a redesign this part in PostgreSQL.
>> Do you know if anything has changed in any of the newer versions after 11.5?
>>
>> It's possible that we should increase a couple of constants used the
>> formula -- I'll look into that again. But first I'd like to see if
>> we're even investigating the right problem here.
>>
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 10:53 Thomas Munro <thomas.munro@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
1 sibling, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2020-01-29 10:53 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Wed, Jan 29, 2020 at 10:37 PM Nicola Contu <nicola.contu@gmail.com> wrote:
> This is the error on postgres log of the segmentation fault :
>
> 2020-01-21 14:20:29 GMT [] [42222]: [108-1] db=,user= LOG: server process (PID 2042) was terminated by signal 11: Segmentation fault
> 2020-01-21 14:20:29 GMT [] [42222]: [109-1] db=,user= DETAIL: Failed process was running: select pid from pg_stat_activity where query ilike 'REFRESH MATERIALIZED VIEW CONCURRENTLY matview_vrs_request_stats'
> 2020-01-21 14:20:29 GMT [] [42222]: [110-1] db=,user= LOG: terminating any other active server processes
Ok, this is a bug. Do you happen to have a core file? I don't recall
where CentOS puts them.
> > If you're on Linux, you can probably see them with "ls /dev/shm".
>
> I see a lot of files there, and doing a cat they are empty. What can I do with them?
Not much, but it tells you approximately how many 'slots' are in use
at a given time (ie because of currently running parallel queries), if
they were created since PostgreSQL started up (if they're older ones
they could have leaked from a crashed server, but we try to avoid that
by trying to clean them up when you restart).
> Those are two different problems I guess, but they are related because right before the Segmentation Fault I see a lot of shared segment errors in the postgres log.
That gave me an idea... I hacked my copy of PostgreSQL to flip a coin
to decide whether to pretend there are no slots free (see below), and
I managed to make it crash in the regression tests when doing a
parallel index build. It's late here now, but I'll look into that
tomorrow. It's possible that the parallel index code needs to learn
to cope with that.
#2 0x0000000000a096f6 in SharedFileSetInit (fileset=0x80b2fe14c,
seg=0x0) at sharedfileset.c:71
#3 0x0000000000c72440 in tuplesort_initialize_shared
(shared=0x80b2fe140, nWorkers=2, seg=0x0) at tuplesort.c:4341
#4 0x00000000005ab405 in _bt_begin_parallel
(buildstate=0x7fffffffc070, isconcurrent=false, request=1) at
nbtsort.c:1402
#5 0x00000000005aa7c7 in _bt_spools_heapscan (heap=0x801ddd7e8,
index=0x801dddc18, buildstate=0x7fffffffc070, indexInfo=0x80b2b62d0)
at nbtsort.c:396
#6 0x00000000005aa695 in btbuild (heap=0x801ddd7e8,
index=0x801dddc18, indexInfo=0x80b2b62d0) at nbtsort.c:328
#7 0x0000000000645b5c in index_build (heapRelation=0x801ddd7e8,
indexRelation=0x801dddc18, indexInfo=0x80b2b62d0, isreindex=false,
parallel=true) at index.c:2879
#8 0x0000000000643e5c in index_create (heapRelation=0x801ddd7e8,
indexRelationName=0x7fffffffc510 "pg_toast_24587_index",
indexRelationId=24603, parentIndexRelid=0,
I don't know if that's the bug that you're hitting, but it definitely
could be: REFRESH MATERIALIZED VIEW could be rebuilding an index.
===
inline patch 1: src/backend/storage/ipc/dsm.c (+7/-0 lines) download inline-1.patch
diff --git a/src/backend/storage/ipc/dsm.c b/src/backend/storage/ipc/dsm.c
index 90e0d739f8..f0b49d94ee 100644
--- a/src/backend/storage/ipc/dsm.c
+++ b/src/backend/storage/ipc/dsm.c
@@ -468,6 +468,13 @@ dsm_create(Size size, int flags)
nitems = dsm_control->nitems;
for (i = 0; i < nitems; ++i)
{
+ /* BEGIN HACK */
+ if (random() % 10 > 5)
+ {
+ nitems = dsm_control->maxitems;
+ break;
+ }
+ /* END HACK */
if (dsm_control->item[i].refcnt == 0)
{
dsm_control->item[i].handle = seg->handle;
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-29 11:26 Thomas Munro <thomas.munro@gmail.com>
parent: Julian Backes <julianbackes@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2020-01-29 11:26 UTC (permalink / raw)
To: Julian Backes <julianbackes@gmail.com>; +Cc: Nicola Contu <nicola.contu@gmail.com>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Wed, Jan 29, 2020 at 11:24 PM Julian Backes <julianbackes@gmail.com> wrote:
> we only had the "too many shared too many dynamic shared memory segments" error but no segmentation faults. The error started occurring after upgrading from postgres 10 to postgres 12 (server has 24 cores / 48 threads, i.e. many parallel workers). The error itself was not that much of a problem but /dev/shm started filling up with orphaned files which probably (?) had not been cleaned up by postgres after the parallel workers died. In consequence, after some time, /dev/shm was full and everything crashed.
Oh, thanks for the report. I think see what was happening there, and
it's a third independent problem. The code in dsm_create() does
DSM_OP_DESTROY (ie cleans up) in the DSM_CREATE_NULL_IF_MAXSEGMENTS
case, but in the case where you see "ERROR: too many dynamic shared
memory segments" it completely fails to clean up after itself. I can
reproduce that here. That's a terrible bug, and has been sitting in
the tree for 5 years.
> Unfortunately, the only "solution" we found so far was to increase max connections from 100 to 1000. After that (about 2 months ago I think), the error had gone.
I'll take that as a vote for increasing the number of slots.
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-30 22:41 Thomas Munro <thomas.munro@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2020-01-30 22:41 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Wed, Jan 29, 2020 at 11:53 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Wed, Jan 29, 2020 at 10:37 PM Nicola Contu <nicola.contu@gmail.com> wrote:
> > This is the error on postgres log of the segmentation fault :
> >
> > 2020-01-21 14:20:29 GMT [] [42222]: [108-1] db=,user= LOG: server process (PID 2042) was terminated by signal 11: Segmentation fault
> > 2020-01-21 14:20:29 GMT [] [42222]: [109-1] db=,user= DETAIL: Failed process was running: select pid from pg_stat_activity where query ilike 'REFRESH MATERIALIZED VIEW CONCURRENTLY matview_vrs_request_stats'
> > 2020-01-21 14:20:29 GMT [] [42222]: [110-1] db=,user= LOG: terminating any other active server processes
> That gave me an idea... I hacked my copy of PostgreSQL to flip a coin
> to decide whether to pretend there are no slots free (see below), and
> I managed to make it crash in the regression tests when doing a
> parallel index build. It's late here now, but I'll look into that
> tomorrow. It's possible that the parallel index code needs to learn
> to cope with that.
Hi Nicola,
Without more information I can't know if I found the same bug you
experienced, but I think it's likely. I have committed a fix for
that, which will be available in the next release (mid-February).
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=74618e77b43cfce670b4725d5b9a300a2afd1...
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-01-31 10:05 Nicola Contu <nicola.contu@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Nicola Contu @ 2020-01-31 10:05 UTC (permalink / raw)
To: Thomas Munro <thomas.munro@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
Hi Thomas,
unfortunately I can't find any core dump to help you more.
Thanks for the fix, we are in the process of installing 12.1 in production,
so we can still wait on this release and go live with 12.2
I will let you know at this point if I still get this after installing 12.2
trying to build a core dump file.
Do you still recommend to increase max_conn?
Il giorno gio 30 gen 2020 alle ore 23:41 Thomas Munro <
thomas.munro@gmail.com> ha scritto:
> On Wed, Jan 29, 2020 at 11:53 PM Thomas Munro <thomas.munro@gmail.com>
> wrote:
> > On Wed, Jan 29, 2020 at 10:37 PM Nicola Contu <nicola.contu@gmail.com>
> wrote:
> > > This is the error on postgres log of the segmentation fault :
> > >
> > > 2020-01-21 14:20:29 GMT [] [42222]: [108-1] db=,user= LOG: server
> process (PID 2042) was terminated by signal 11: Segmentation fault
> > > 2020-01-21 14:20:29 GMT [] [42222]: [109-1] db=,user= DETAIL: Failed
> process was running: select pid from pg_stat_activity where query ilike
> 'REFRESH MATERIALIZED VIEW CONCURRENTLY matview_vrs_request_stats'
> > > 2020-01-21 14:20:29 GMT [] [42222]: [110-1] db=,user= LOG:
> terminating any other active server processes
>
> > That gave me an idea... I hacked my copy of PostgreSQL to flip a coin
> > to decide whether to pretend there are no slots free (see below), and
> > I managed to make it crash in the regression tests when doing a
> > parallel index build. It's late here now, but I'll look into that
> > tomorrow. It's possible that the parallel index code needs to learn
> > to cope with that.
>
> Hi Nicola,
>
> Without more information I can't know if I found the same bug you
> experienced, but I think it's likely. I have committed a fix for
> that, which will be available in the next release (mid-February).
>
>
> https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=74618e77b43cfce670b4725d5b9a300a2afd1...
>
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-02-01 03:00 Thomas Munro <thomas.munro@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 0 replies; 35+ messages in thread
From: Thomas Munro @ 2020-02-01 03:00 UTC (permalink / raw)
To: Julian Backes <julianbackes@gmail.com>; +Cc: Nicola Contu <nicola.contu@gmail.com>; Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Thu, Jan 30, 2020 at 12:26 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> On Wed, Jan 29, 2020 at 11:24 PM Julian Backes <julianbackes@gmail.com> wrote:
> > we only had the "too many shared too many dynamic shared memory segments" error but no segmentation faults. The error started occurring after upgrading from postgres 10 to postgres 12 (server has 24 cores / 48 threads, i.e. many parallel workers). The error itself was not that much of a problem but /dev/shm started filling up with orphaned files which probably (?) had not been cleaned up by postgres after the parallel workers died. In consequence, after some time, /dev/shm was full and everything crashed.
>
> Oh, thanks for the report. I think see what was happening there, and
> it's a third independent problem. The code in dsm_create() does
> DSM_OP_DESTROY (ie cleans up) in the DSM_CREATE_NULL_IF_MAXSEGMENTS
> case, but in the case where you see "ERROR: too many dynamic shared
> memory segments" it completely fails to clean up after itself. I can
> reproduce that here. That's a terrible bug, and has been sitting in
> the tree for 5 years.
I committed a fix for that. It'll be in the new releases that due out
in a couple of weeks.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=93745f1e019543fe7b742d0c5e971aad8...
> > Unfortunately, the only "solution" we found so far was to increase max connections from 100 to 1000. After that (about 2 months ago I think), the error had gone.
>
> I'll take that as a vote for increasing the number of slots.
I committed something to do this for 13 (due out end of year), but I'm
not game to back-patch it to the release branches.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=d061ea21fc1cc1c657bb5c742f5c4a1564e82...
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-02-01 03:08 Thomas Munro <thomas.munro@gmail.com>
parent: Nicola Contu <nicola.contu@gmail.com>
0 siblings, 1 reply; 35+ messages in thread
From: Thomas Munro @ 2020-02-01 03:08 UTC (permalink / raw)
To: Nicola Contu <nicola.contu@gmail.com>; +Cc: Pavel Stehule <pavel.stehule@gmail.com>; pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>; Alessandro Aste <Alessandro.aste@gtt.net>
On Fri, Jan 31, 2020 at 11:05 PM Nicola Contu <nicola.contu@gmail.com> wrote:
> Do you still recommend to increase max_conn?
Yes, as a workaround of last resort. The best thing would be to
figure out why you are hitting the segment limit, and see if there is
something we could tune to fix that. If you EXPLAIN your queries, do
you see plans that have a lot of "Gather" nodes in them, perhaps
involving many partitions? Or are you running a lot of parallel
queries at the same time? Or are you running queries that do very,
very large parallel hash joins? Or something else?
^ permalink raw reply [nested|flat] 35+ messages in thread
* Re: ERROR: too many dynamic shared memory segments
@ 2020-02-20 09:37 dainius.b <dainius.bratkauskas@gmail.com>
parent: Thomas Munro <thomas.munro@gmail.com>
0 siblings, 0 replies; 35+ messages in thread
From: dainius.b @ 2020-02-20 09:37 UTC (permalink / raw)
To: pgsql-general
Hello,
I also get high amount of "too many dynamic shared memory segments" errors.
Upgraded Postgres version to 12.2, but that did not help.
Server has 64GB Ram/16 CPU. Postgres params:
"max_connections":500,
"shared_buffers":"16GB",
"effective_cache_size":"48GB",
"maintenance_work_mem":"2GB",
"checkpoint_completion_target":0.9,
"wal_buffers":"32MB",
"default_statistics_target":500,
"random_page_cost":1.1,
"effective_io_concurrency":200,
"work_mem":"20971kB",
"min_wal_size":"2GB",
"max_wal_size":"8GB",
"max_worker_processes":8,
"max_parallel_workers_per_gather":4,
"max_parallel_workers":8,
"log_statement":"none"
This error happens when executing many parallel queries that have quite
complex plan:
Limit (cost=163243.91..163250.02 rows=51 width=464) (actual
time=1224.817..1224.834 rows=31 loops=1)
-> Gather Merge (cost=163243.91..165477.68 rows=18656 width=464) (actual
time=1224.815..1254.031 rows=31 loops=1)
Workers Planned: 4
Workers Launched: 4
-> Sort (cost=162243.85..162255.51 rows=4664 width=464) (actual
time=1214.032..1214.032 rows=6 loops=5)
Sort Key: (...)
Sort Method: quicksort Memory: 30kB
Worker 0: Sort Method: quicksort Memory: 28kB
Worker 1: Sort Method: quicksort Memory: 27kB
Worker 2: Sort Method: quicksort Memory: 27kB
Worker 3: Sort Method: quicksort Memory: 27kB
-> Parallel Hash Semi Join (cost=41604.51..162088.25
rows=4664 width=464) (actual time=409.437..1213.922 rows=6 loops=5)
Hash Cond: (...)
-> Parallel Hash Join (cost=28073.57..148289.42
rows=17880 width=464) (actual time=234.973..1165.754 rows=36930 loops=5)
Hash Cond: (...)
-> Parallel Hash Left Join
(cost=20732.39..140901.30 rows=17880 width=445) (actual
time=187.482..1083.629 rows=36930 loops=5)
Hash Cond: (...)
-> Parallel Hash Left Join
(cost=14850.80..134972.78 rows=17880 width=435) (actual
time=148.107..1010.915 rows=36930 loops=5)
Hash Cond: (...)
-> Parallel Hash Left Join
(cost=8969.21..129044.25 rows=17880 width=425) (actual time=110.696..938.602
rows=36930 loops=5)
Hash Cond: (...)
-> Nested Loop
(cost=3087.61..123115.72 rows=17880 width=411) (actual time=70.827..861.142
rows=36930 loops=5)
-> Nested Loop
(cost=3087.19..104038.13 rows=38340 width=263) (actual time=70.742..621.262
rows=37073 loops=5)
-> Parallel Bitmap
Heap Scan on (...) (cost=3086.76..73462.00 rows=39271 width=167) (actual
time=70.653..358.576 rows=37103 loops=5)
Recheck Cond:
(...)
Filter: (...)
Rows Removed
by Filter: 42915
Heap Blocks:
exact=17872
-> Bitmap
Index Scan on (...) (cost=0.00..3047.49 rows=378465 width=0) (actual
time=52.331..52.331 rows=400144 loops=1)
Index
Cond: (...)
-> Index Scan using
(...) (cost=0.43..0.78 rows=1 width=96) (actual time=0.006..0.006 rows=1
loops=185514)
Index Cond:
(...)
Filter: (...)
Rows Removed
by Filter: 0
-> Index Scan using
(...)(cost=0.43..0.50 rows=1 width=152) (actual time=0.006..0.006 rows=1
loops=185367)
Index Cond: (...)
Filter: (...)
Rows Removed by
Filter: 0
-> Parallel Hash
(cost=3675.71..3675.71 rows=176471 width=18) (actual time=38.590..38.590
rows=60000 loops=5)
Buckets: 524288 Batches:
1 Memory Usage: 20640kB
-> Parallel Seq Scan on
(...) (cost=0.00..3675.71 rows=176471 width=18) (actual time=0.020..11.378
rows=60000 loops=5)
-> Parallel Hash
(cost=3675.71..3675.71 rows=176471 width=18) (actual time=36.769..36.770
rows=60000 loops=5)
Buckets: 524288 Batches: 1
Memory Usage: 20608kB
-> Parallel Seq Scan on (...)
(cost=0.00..3675.71 rows=176471 width=18) (actual time=0.018..11.665
rows=60000 loops=5)
-> Parallel Hash (cost=3675.71..3675.71
rows=176471 width=18) (actual time=38.415..38.415 rows=60000 loops=5)
Buckets: 524288 Batches: 1 Memory
Usage: 20640kB
-> Parallel Seq Scan on (...)
(cost=0.00..3675.71 rows=176471 width=18) (actual time=0.021..11.781
rows=60000 loops=5)
-> Parallel Hash (cost=5619.97..5619.97
rows=137697 width=27) (actual time=46.665..46.665 rows=66096 loops=5)
Buckets: 524288 Batches: 1 Memory Usage:
24544kB
-> Parallel Seq Scan on (...)
(cost=0.00..5619.97 rows=137697 width=27) (actual time=0.024..16.629
rows=66096 loops=5)
-> Parallel Hash (cost=12679.65..12679.65 rows=68103
width=4) (actual time=28.674..28.674 rows=41176 loops=5)
Buckets: 262144 Batches: 1 Memory Usage: 10176kB
-> Parallel Index Only Scan using (...)
(cost=0.57..12679.65 rows=68103 width=4) (actual time=0.048..15.443
rows=41176 loops=5)
Index Cond: ()
Heap Fetches: 205881
Planning Time: 6.941 ms
Execution Time: 1254.251 ms
So to avoid getting these errors the only solution is to decrease work_mem
or turn off paralelism? Because I hoped that in such case it would take
longer time to complete the queries but instead I get high amount of queries
just crashing.
Thomas Munro-5 wrote
> On Fri, Jan 31, 2020 at 11:05 PM Nicola Contu <
> nicola.contu@
> > wrote:
>> Do you still recommend to increase max_conn?
>
> Yes, as a workaround of last resort. The best thing would be to
> figure out why you are hitting the segment limit, and see if there is
> something we could tune to fix that. If you EXPLAIN your queries, do
> you see plans that have a lot of "Gather" nodes in them, perhaps
> involving many partitions? Or are you running a lot of parallel
> queries at the same time? Or are you running queries that do very,
> very large parallel hash joins? Or something else?
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
^ permalink raw reply [nested|flat] 35+ messages in thread
end of thread, other threads:[~2020-02-20 09:37 UTC | newest]
Thread overview: 35+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 09:54 ERROR: too many dynamic shared memory segments Jakub Glapa <jakub.glapa@gmail.com>
2017-11-27 10:47 ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-11-27 12:13 ` Jakub Glapa <jakub.glapa@gmail.com>
2017-11-27 18:53 ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-11-27 19:16 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-11-27 21:05 ` Jakub Glapa <jakub.glapa@gmail.com>
2017-11-27 22:48 ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-11-28 07:32 ` Dilip Kumar <dilipbalaut@gmail.com>
2017-11-28 13:43 ` Robert Haas <robertmhaas@gmail.com>
2017-11-28 14:45 ` Dilip Kumar <dilipbalaut@gmail.com>
2017-11-28 16:58 ` Robert Haas <robertmhaas@gmail.com>
2018-02-02 20:01 ` Tom Lane <tgl@sss.pgh.pa.us>
2018-02-02 20:19 ` Robert Haas <robertmhaas@gmail.com>
2018-02-02 20:56 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-12-04 12:18 ` Jakub Glapa <jakub.glapa@gmail.com>
2017-12-07 21:30 ` Thomas Munro <thomas.munro@enterprisedb.com>
2017-12-08 07:59 ` Jakub Glapa <jakub.glapa@gmail.com>
2019-09-11 07:47 ERROR: too many dynamic shared memory segments Nicola Contu <nicola.contu@gmail.com>
2019-09-11 08:09 ` Pavel Stehule <pavel.stehule@gmail.com>
2019-09-11 08:27 ` Nicola Contu <nicola.contu@gmail.com>
2019-09-11 23:00 ` Thomas Munro <thomas.munro@gmail.com>
2020-01-21 15:06 ` Nicola Contu <nicola.contu@gmail.com>
2020-01-21 16:14 ` Nicola Contu <nicola.contu@gmail.com>
2020-01-29 08:34 ` Nicola Contu <nicola.contu@gmail.com>
2020-01-29 09:09 ` Thomas Munro <thomas.munro@gmail.com>
2020-01-29 09:37 ` Nicola Contu <nicola.contu@gmail.com>
2020-01-29 10:23 ` Julian Backes <julianbackes@gmail.com>
2020-01-29 11:26 ` Thomas Munro <thomas.munro@gmail.com>
2020-02-01 03:00 ` Thomas Munro <thomas.munro@gmail.com>
2020-01-29 10:53 ` Thomas Munro <thomas.munro@gmail.com>
2020-01-30 22:41 ` Thomas Munro <thomas.munro@gmail.com>
2020-01-31 10:05 ` Nicola Contu <nicola.contu@gmail.com>
2020-02-01 03:08 ` Thomas Munro <thomas.munro@gmail.com>
2020-02-20 09:37 ` dainius.b <dainius.bratkauskas@gmail.com>
2019-09-11 08:19 ` Nicola Contu <nicola.contu@gmail.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