EltonRexha's avatar

Postgres with neon not working

i generated the default migrations and when i try to migrate:

I don't know whats the problem, i mean the default migrations should be correct?

0 likes
2 replies
EltonRexha's avatar

fixed it by:

In your .env file, change from:

DB_HOST=ep-wandering-math-agv6001k-pooler.c-2.eu-central-1.aws.neon.tech

To (remove '-pooler'):

DB_HOST=ep-wandering-math-agv6001k.c-2.eu-central-1.aws.neon.tech

itsmill3rtime's avatar

I had this same issue a long time ago...

In short... it is because you are using a pooled connection.

In long... Database migrations often fail on a pooled connection because connection poolers are designed for short, stateless transactions, while migrations require long-running, stateful connections and exclusive access to the database schema. Also some connection poolers use a transaction-based pooling mode (like transaction_mode in Supavisor/PgBouncer). In this mode, a client gets a connection for the duration of a single transaction. Migrations, however, often run multiple commands in sequence that require session-level state to persist between queries, which breaks the pooler's assumptions.

My recommendation is creating a second connection in your app, and put the non-pooled connection string in it. then in your migrations put $connection = '...your second connection...' so they will utilize that while the rest of your app uses the pooled connection.

My fix was i actually hooked into the events and checked for when a migration is running and i dynamically changed the connection on the fly

1 like

Please or to participate in this conversation.