Strapi server when deployed using docker container stops with errors, even though it works great for first few hours everytime

System Information
  • Strapi Version: 4.19.1
  • Operating System: Windows
  • Database: Postgresql
  • Node Version: 18.19.0
  • NPM Version: 10.2.3

I am trying to deploy my strapi backend with psql database and docker container. The problem is the first time I deploy it works great for few hour but it starts showing this error after I leave it idle for some hours

Error shown in strapi backend logs

[2024-05-01 21:33:39.585] http: GET index.html (4 ms) 200
Connection Error: Connection ended unexpectedly
[2024-05-01 21:33:44.710] debug: ⛔️ Server wasn't able to start properly.
[2024-05-01 21:33:44.711] error: select "t0"."id" from "public"."admin_users" as "t0" limit $1 - relation "public.admin_users" does not exist
error: select "t0"."id" from "public"."admin_users" as "t0" limit $1 - relation "public.admin_users" does not exist
    at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/app/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/app/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/app/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:517:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

> spraykaro-strapi@0.1.0 start
> strapi start

DEBUG: Detected Strapi version 4.19.1 for interface building
INFO: schemas-to-ts plugin's acceptedNodeEnvs property does not include 'production' environment. Skipping conversion of schemas to Typescript.
[2024-05-01 21:33:51.551] debug: ⛔️ Server wasn't able to start properly.
[2024-05-01 21:33:51.554] error: alter table "public"."admin_permissions_role_links" add constraint "admin_permissions_role_links_fk" foreign key ("permission_id") references "public"."admin_permissions" ("id") on delete CASCADE - insert or update on table "admin_permissions_role_links" violates foreign key constraint "admin_permissions_role_links_fk"
error: alter table "public"."admin_permissions_role_links" add constraint "admin_permissions_role_links_fk" foreign key ("permission_id") references "public"."admin_permissions" ("id") on delete CASCADE - insert or update on table "admin_permissions_role_links" violates foreign key constraint "admin_permissions_role_links_fk"
    at Parser.parseErrorMessage (/app/node_modules/pg-protocol/dist/parser.js:287:98)
    at Parser.handlePacket (/app/node_modules/pg-protocol/dist/parser.js:126:29)
    at Parser.parse (/app/node_modules/pg-protocol/dist/parser.js:39:38)
    at Socket.<anonymous> (/app/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:517:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:335:12)
    at readableAddChunk (node:internal/streams/readable:308:9)
    at Readable.push (node:internal/streams/readable:245:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)

Error shown in psql database logs

2024-05-01 20:23:29.925 UTC [43727] FATAL:  unsupported frontend protocol 0.0: server supports 3.0 to 3.0
2024-05-01 20:23:30.133 UTC [43728] FATAL:  unsupported frontend protocol 255.255: server supports 3.0 to 3.0
2024-05-01 20:23:30.337 UTC [43729] FATAL:  no PostgreSQL user name specified in startup packet
2024-05-01 20:50:11.606 UTC [46291] FATAL:  unsupported frontend protocol 0.0: server supports 3.0 to 3.0
2024-05-01 20:50:12.081 UTC [46292] FATAL:  unsupported frontend protocol 255.255: server supports 3.0 to 3.0
2024-05-01 20:50:13.158 UTC [46293] FATAL:  no PostgreSQL user name specified in startup packet
2024-05-01 21:33:41.244 UTC [50461] ERROR:  syntax error at or near "-" at character 18
2024-05-01 21:33:41.244 UTC [50461] STATEMENT:  SELECT * FROM cms-analyser-results LIMIT 20;
2024-05-01 21:33:41.573 UTC [50471] FATAL:  database "template0" is not currently accepting connections
2024-05-01 21:33:41.674 UTC [35534] FATAL:  terminating connection due to administrator command
2024-05-01 21:33:41.936 UTC [50474] ERROR:  cannot drop the currently open database
2024-05-01 21:33:41.936 UTC [50474] STATEMENT:  DROP DATABASE postgres;
2024-05-01 21:33:42.072 UTC [50475] ERROR:  database "spraykaro" does not exist
2024-05-01 21:33:42.072 UTC [50475] STATEMENT:  DROP DATABASE Spraykaro;
2024-05-01 21:33:44.708 UTC [50487] ERROR:  relation "public.admin_users" does not exist at character 23
2024-05-01 21:33:44.708 UTC [50487] STATEMENT:  select "t0"."id" from "public"."admin_users" as "t0" limit $1
2024-05-01 21:33:51.539 UTC [50499] ERROR:  insert or update on table "admin_permissions_role_links" violates foreign key constraint "admin_permissions_role_links_fk"
2024-05-01 21:33:51.539 UTC [50499] DETAIL:  Key (permission_id)=(1) is not present in table "admin_permissions".
2024-05-01 21:33:51.539 UTC [50499] STATEMENT:  alter table "public"."admin_permissions_role_links" add constraint "admin_permissions_role_links_fk" foreign key ("permission_id") references "public"."admin_permissions" ("id") on delete CASCADE
2024-05-01 21:33:58.389 UTC [50520] ERROR:  insert or update on table "admin_permissions_role_links" violates foreign key constraint "admin_permissions_role_links_fk"
2024-05-01 21:33:58.389 UTC [50520] DETAIL:  Key (permission_id)=(1) is not present in table "admin_permissions".
2024-05-01 21:33:58.389 UTC [50520] STATEMENT:  alter table "public"."admin_permissions_role_links" add constraint "admin_permissions_role_links_fk" foreign key ("permission_id") references "public"."admin_permissions" ("id") on delete CASCADE
2024-05-01 21:34:06.290 UTC [50551] ERROR:  insert or update on table "admin_permissions_role_links" violates foreign key constraint "admin_permissions_role_links_fk"

And also after this I found mine multiple tables dropped or deleted as they decreased from 82 to 64.

I also followed multiple guides such as setting

      pool: {
        min: 0,
        max: env.int("DATABASE_POOL_MAX", 10),
      },

I also used import export plugin to import data into mine deployed strapi instance.

But still the problem is not resolved.

Any help is most appreciated as I am not possible to deploy my app because of this error and till now I have spent 2 days just to resolve this error.

1 Like

I have exactly the same issues! Did you manage to find a solution??

1 Like

I am getting similar issues as well…hmmm