# Forest-cli database introspection very slow on pg14

**URL:** <https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418>\
**Category:** Help me!\
**Created:** [October 20, 2022, 10:09am UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418 "2022-10-20T10:09:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 20, 2022, 10:09am UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/1 "2022-10-20T10:09:10Z")

</div>

## Feature(s) impacted

forest projects:create  
forest schema:update

## Observed behavior

On pg11, above commands take around 10 seconds  
On pg14, above commands take around 3 minutes

This was measured on the same code+data, just by upgrading/rollbacking pg version.

## Expected behavior

On pg11, above commands take around 10 seconds  
On pg14, above commands take around 10 seconds

## Context

- Project name: see support email

- Team name: see support email

- Environment name: development

- Agent type & version:

- Recent changes made on your end if any: postgres upgrade

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 20, 2022, 12:33pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/3 "2022-10-20T12:33:34Z")

</div>

Hey @louisl, and welcome to our community 👋

Just did a quick test on my end, and I’m sadly not able to reproduce your Observed Behavior.

Could you provide an estimated number or tables/records you have in total so I can put myself in a similar state to yours ?

Thanks in advance 🙏

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 20, 2022, 1:37pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/4 "2022-10-20T13:37:45Z")

</div>

Hello @anon39848301, thanks for testing this.

My postgres database “lives” in a Docker container FYI.

`SELECT SUM(reltuples) AS estimate FROM pg_class where reltuples != -1` returns 290809.

Table count 123  
`select count(*) from information_schema.tables where table_schema='public' and table_name not ilike 'pg_%';`

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 20, 2022, 1:41pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/5 "2022-10-20T13:41:21Z")

</div>

> My postgres database “lives” in a Docker container FYI.

Same on my end (Tested with both 14 & 14.1)

I’ll do a quick sample database with multiple thousand of records to check if that’s related 👍  
I’ll update this response if I’m able to find something.

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 20, 2022, 2:42pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/6 "2022-10-20T14:42:30Z")

</div>

Oh, I’m on postgres 14.2, maybe this?

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 21, 2022, 7:27am UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/7 "2022-10-21T07:27:26Z")

</div>

Still, unable to reproduce the issue ☹

Could you share with me your current version of `pg`?

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 21, 2022, 12:55pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/8 "2022-10-21T12:55:30Z")

</div>

14.2 (Debian 14.2-1.pgdg110+1)

docker-compose.yml

```javascript
version: '3.5'

services:
  database:
    container_name: project-database
    image: postgres:14.2
    shm_size: 512m
    networks:
      - dbnet
    ports:
      - 5432:5432
    environment:
      - POSTGRES_HOST=database
      - POSTGRES_DB=db
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=password

networks:
  dbnet:
    name: database-network

```

I will test on a database outside of Docker to see if the issue lies here

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 21, 2022, 1:45pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/9 "2022-10-21T13:45:55Z")

</div>

Ok so I used Postgres.app for easy reproduction

psql (14.4, server 11.17) =\> OK  
psql (14.4, server 12.12) =\> KO  
psql (14.4, server 13.8) =\> KO  
psql (14.4, server 14.5) =\> KO  
psql (14.4, server 15.0) =\> KO

So apparently even an upgrade to pg12 makes this very slow.  
This is not linked to Docker too.  
And I deleted all data from tables. Still KO with pg12+.  
Deleted the schema, created a new schema with a dummy table, and here it is OK (🥵).

So the database introspection with pg12+ doesn’t like something in our schema.

Would you like to have a dump of our schema? I can send it to your professional FA e-mail (there is no data inside)

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 24, 2022, 9:08am UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/10 "2022-10-24T09:08:27Z")

</div>

Ok, so after importing your dump in 12.12, I’m getting ~3mn to generate all the models.

However, importing the same dump in 11.17 gives me … 4mn to generate all the models.

It seems like [the SQL query needed to retrieve your database constraints](https://github.com/ForestAdmin/toolbelt/blob/main/src/services/schema/update/analyzer/sequelize-table-constraints-getter.js#L11) (PK, unique indexes, etc) is very slow, but I’m still not sure why.

Running this SQL query on any table of any version of pg of your dump gives me ~700ms/table.  
Running this SQL query on another database on pg@12 I have on my end gives me ~10ms/table.

I’m still digging the differences, but I guess this could also be interesting to share.

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 25, 2022, 9:43am UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/11 "2022-10-25T09:43:24Z")

</div>

Hey @louisl 👋

I finally manage to reproduce the issue, and the fix is on it’s way. It should be released today.

Be sure we’ll ping you once it is available 👍

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 25, 2022, 1:36pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/12 "2022-10-25T13:36:02Z")

</div>

Hello @anon39848301, good news thanks a lot!

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [October 25, 2022, 2:11pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/13 "2022-10-25T14:11:42Z")

</div>

Hey @louisl,

The fix is released and included in the new `forest-cli@3.0.2`.

`npm install -g forest-cli@latest` should do the trick.

Let me know if your issue is fixed with this new version 🙏

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [October 25, 2022, 2:37pm UTC](https://community.forestadmin.com/t/forest-cli-database-introspection-very-slow-on-pg14/5418/14 "2022-10-25T14:37:16Z")

</div>

It works great, thanks! (nice one-line fix by the way 👌🏻)
