(Solved) PostgreSQL Knex Migration Connection Error

wusixuan0TRIAL

a year ago

Encountering connection error while running PostgreSQL Knex migration, despite successful connection to Railway instance using the Database URL.

this is my connection configuration in the Knex file.

production: {
client: 'pg',
connection: DATABASEURL, pool: { min: 2, max: 10 }, migrations: { tableName: 'knexmigrations'
}
}

6 Replies

a year ago

Please provide the error message.


wusixuan0TRIAL

a year ago

Hi brody! Thanks for the reply. here's the error message:
Unable to acquire a connection
Error: Unable to acquire a connection
at ClientPG.acquireConnection (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/client.js:311:13)
at Runner.ensureConnection (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/execution/runner.js:305:46) at Runner.run (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/execution/runner.js:30:30)
at Target.then (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/builder-interface-augmenter.js:24:43) at ensureTable (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/migrations/migrate/table-creator.js:12:6)
at listCompleted (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/migrations/migrate/migration-list-resolver.js:12:9) at Object.listAllAndCompleted (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/migrations/migrate/migration-list-resolver.js:25:5)
at Migrator.latest (/Users/sixuan/Desktop/postgresql-practice/nodemodules/knex/lib/migrations/migrate/Migrator.js:63:57) at Command. (/usr/local/lib/nodemodules/knex/bin/cli.js:248:55)
s


wusixuan0TRIAL

a year ago

I found the cause. I stored the Database URL in environment variable. When I put the url directly in the knexfile.js, it worked when I run migration. I guess my environment variable didn't work in production environment.


hamishmacewanHOBBY

a year ago

I appear to have a similar problem which only began recently after nearly 6months of happy operation:

https://railway.app/project/7ea5a48b-676a-4364-8700-7e4ce363caea/logs?filter=%40deployment%3A83bd42ab-5f6d-425c-a552-b55f1659f8ab+-%40replica%3A42b5f82e-5119-487b-985b-5bfd3b259e5d&context=2024-05-30T05%3A34%3A47.897122000Z

11 [build 6/8] RUN npm run db:migrate

11 0.965

11 0.965 > nostream@1.25.2 db:migrate

11 0.965 > knex migrate:latest

11 0.965

11 31.32 Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

11 31.32 KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

11 31.32 at ClientPG.acquireConnection (/build/nodemodules/knex/lib/client.js:312:26)

11 31.32 at async Runner.ensureConnection (/build/node_modules/knex/lib/execution/runner.js:287:28)

11 31.32 at async Runner.run (/build/node_modules/knex/lib/execution/runner.js:30:19)

11 31.32 at async listCompleted (/build/node_modules/knex/lib/migrations/migrate/migration-list-resolver.js:12:3)

11 31.32 at async Promise.all (index 1)

11 31.32 at async Migrator.latest (/build/node_modules/knex/lib/migrations/migrate/Migrator.js:63:29)

11 31.32 at async Command. (/build/node_modules/knex/bin/cli.js:248:32)

11 ERROR: process "/bin/sh -c npm run db:migrate" did not complete successfully: exit code: 1

Knex problems lead to an attempt to redeploy (after a restart didn't resolve the issue) and the redeployment failed, all on these issues with the postgres task:

2024-05-24 02:35:28.879 UTC [3088] LOG: invalid length of startup packet
2024-05-24 05:12:42.114 UTC [28] LOG: checkpoint starting: time
2024-05-24 05:12:43.728 UTC [28] LOG: checkpoint complete: wrote 17 buffers (0.1%); 0 WAL file(s) added, 0 removed, 0 recycled; write=1.604 s, sync=0.004 s, total=1.614 s; sync files=13, longest=0.003 s, average=0.001 s; distance=57 kB, estimate=57 kB; lsn=0/1FC7AC8, redo lsn=0/1FC7A90

2024-05-25 02:53:08.686 UTC [28] LOG: checkpoint starting: time
2024-05-28 02:59:35.918 UTC [28] LOG: checkpoint starting: time
2024-05-28 20:11:34.877 UTC [8936] LOG: could not receive data from client: Connection reset by peer
2024-05-28 20:37:47.741 UTC [8867] LOG: could not receive data from client: Connection reset by peer
2024-05-28 20:40:25.434 UTC [8882] LOG: could not receive data from client: Connection timed out
2024-05-28 20:57:54.010 UTC [8962] LOG: could not receive data from client: Connection timed out
2024-05-28 21:12:44.890 UTC [8874] LOG: could not receive data from client: Connection reset by peer
2024-05-28 23:15:01.060 UTC [28] LOG: checkpoint complete: wrote 15 buffers (0.1%); 0 WAL file(s) added, 0 removed, 0 recycled; write=1.405 s, sync=0.005 s, total=1.415 s; sync files=13, longest=0.003 s, average=0.001 s; distance=40 kB, estimate=102 kB; lsn=0/20449E8, redo lsn=0/20449B0

Very naive user of Railway and Docker. Any assistance gratefully recieved.


a year ago

Are your environment (service) variables highlighted as blue?


hamishmacewanHOBBY

a year ago

Not in the Postgres service, per attached, nor as far as I can see, either of the other two.

Attachments