# Pg:which\_groups/0 fail

**URL:** <https://erlangforums.com/t/pg-which-groups-0-fail/1912>\
**Category:** Questions / Help\
**Tags:** pg\
**Created:** [October 6, 2022, 9:27am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912 "2022-10-06T09:27:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [October 6, 2022, 9:27am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/1 "2022-10-06T09:27:07Z")

</div>

Why does `pg:which_groups()` fail with bad\_arg when no groups exist?

Minimal example:

```erlang
Eshell V13.0 (abort with ^G)
1> pg:which_groups().
** exception error: bad argument
     in function ets:match/2
        called as ets:match(pg,{'$1','_','_'})
        *** argument 1: the table identifier does not refer to an existing ETS table
     in call from pg:which_groups/1 (pg.erl, line 186)
2> 

```

Why this call does not return `[]`? 🤔

---

<div class="post-metadata">

**Author:** ![Led](https://erlangforums.com/user_avatar/erlangforums.com/led/32/1594_2.png) [@Led](https://erlangforums.com/u/Led)\
**Post date:** [October 6, 2022, 10:36am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/2 "2022-10-06T10:36:58Z")

</div>

```erlang
1> pg:start_link().
{ok,<0.86.0>}
2> pg:which_groups().
[]
3>

```

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [October 6, 2022, 11:16am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/3 "2022-10-06T11:16:54Z")

</div>

yeah, so there aren’t any groups started by erts? What is the difference between pg groups and process groups used by erts?

---

<div class="post-metadata">

**Author:** ![Led](https://erlangforums.com/user_avatar/erlangforums.com/led/32/1594_2.png) [@Led](https://erlangforums.com/u/Led)\
**Post date:** [October 6, 2022, 11:18am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/4 "2022-10-06T11:18:26Z")

</div>

```erlang
start_link() -> {ok, pid()} | {error, any()}

Starts the default pg scope within supervision tree. Kernel may be configured to do it automatically, see kernel(6) configuration manual.

```

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [October 6, 2022, 11:23am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/5 "2022-10-06T11:23:08Z")

</div>

I know that I must start pg scope, but I’m asking why… I’m asking for a difference between pg groups and groups used by erts because that confuses me… Even if pg is not started, you can ask for group\_leader for your process which handles your IO. So what is the difference between those groups and is there any documentation on this subject?

---

<div class="post-metadata">

**Author:** ![max-au](https://erlangforums.com/user_avatar/erlangforums.com/max-au/32/1627_2.png) [@max-au](https://erlangforums.com/u/max-au)\
**Post date:** [October 7, 2022, 5:46am UTC](https://erlangforums.com/t/pg-which-groups-0-fail/1912/6 "2022-10-07T05:46:35Z")

</div>

There is no specific reason, it’s just my oversight.  
I agree that the error makes no sense, essentially leaking internal implementation (ETS used to speed up/make more concurrent access). Correct error should be something like “scope is not started”. Thanks for reporting, let me some time to fix it.
