3
Nest] 10504  - 20/01/2023, 15:47:27   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)...
QueryFailedError: tables can have at most 1600 columns
    at PostgresQueryRunner.query (C:\Users\Public\Backend\src\driver\postgres\PostgresQueryRunner.ts:299:19)  
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at PostgresQueryRunner.executeQueries (C:\Users\Public\Backend\src\query-runner\BaseQueryRunner.ts:609:13)
    at PostgresQueryRunner.addColumn (C:\Users\Public\Backend\src\driver\postgres\PostgresQueryRunner.ts:1039:9)
    at PostgresQueryRunner.addColumns (C:\Users\Public\Backend\src\driver\postgres\PostgresQueryRunner.ts:1053:13)
    at RdbmsSchemaBuilder.addNewColumns (C:\Users\Public\Backend\src\schema-builder\RdbmsSchemaBuilder.ts:737:13)
    at RdbmsSchemaBuilder.executeSchemaSyncOperationsInProperOrder (C:\Users\Public\Backend\src\schema-builder\RdbmsSchemaBuilder.ts:213:9)
    at RdbmsSchemaBuilder.build (C:\Users\Public\Backend\src\schema-builder\RdbmsSchemaBuilder.ts:92:13)
    at DataSource.synchronize (C:\Users\Public\Backend\src\data-source\DataSource.ts:317:9)
    at DataSource.initialize (C:\Users\Public\Backend\src\data-source\DataSource.ts:255:43)

I'm thinking because an item was inserted wrong, or I don't know.

Hulubina
  • 141
  • 1
  • 11
  • If you dropped and added a lot of columns to a single table, you might run into this. See [here](https://stackoverflow.com/questions/29387569) for different workarounds/solutions. –  Jan 20 '23 at 14:51
  • Another solution which makes this quite easy is e.g. [pg_squeeze](https://www.cybertec-postgresql.com/en/products/pg_squeeze/) or [pg_repack](https://github.com/reorg/pg_repack) because they create a new empty table in the background. –  Jan 20 '23 at 15:03

1 Answers1

1

The error message is "tables can have at most 1600 columns", and the stack trace indicates that you encountered it while calling addColumn -- so the first thing to check is whether you've run this code enough times that you've accidentally made a 1600-column table.

If you have other code that deletes those columns, you may need to rebuild the table; according to this, deleted columns may still count towards that limitation. The suggested workaround is to back up your data, drop the table, and restore it from backup.

Daniel Beck
  • 20,653
  • 5
  • 38
  • 53
  • There is no Postgres version 15.9.3.1 (never was and never will be). But yes frequent `drop column` and `add column` might cause this. The only workaround is to create the table from scratch. –  Jan 20 '23 at 14:42
  • @a_horse_with_no_name The page linked in my answer says "Fixed in Release 15.9.3 Patch #1 (15.9.3.1)" -- I'm honestly not a Postgres user so I don't know if you're mistaken or they are (or I'm misreading, just to cover all bases :) – Daniel Beck Jan 20 '23 at 14:46
  • That page is referring to a product named "Clarity PPM SaaS" (which apparently uses Postgres in the background). –  Jan 20 '23 at 14:47
  • My mistake, thank you! I'll correct that in the answer. – Daniel Beck Jan 20 '23 at 14:47