We have a freshly minted Postgres DB running on AlloyDB. When deploying new code the DB seems to hang. It is getting worse. There are only 2000 rows in the table, but when I check the query insights there is an ALTER TABLE payments query taking minutes. There is also what I assume is a typeORM table scan happening which is also hanging. You can see that only one column has a foreign key and it's on a primary key. You can also see that the query is being called multiple times per day as we've only had the system in place 8 weeks and we have less than 100 deployments. I'm not sure why it would get called without a change in schema. Two other tables are also listed similarly and have near-zero execution time including the purchases table.
import { Column, Entity, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Purchase } from './purchase.entity';
@Entity('payments')
export class Payment {
@PrimaryGeneratedColumn({
type: 'bigint',
name: 'id',
})
id: number;
@Column({
nullable: false,
type: 'bigint'
})
purchase_id: number;
@ManyToOne(() => Purchase, purchase => purchase.payments, { lazy: true })
@JoinColumn({ name: 'purchase_id' })
purchase: Promise<Purchase>;
@Column({
name: 'payment_date',
type: 'date',
nullable: false,
default: new Date(),
})
payment_date: Date;
@Column({
nullable: false,
default: 0
})
payment_amount: number;
@Column({
type: 'varchar',
default: "pending"
})
attempts: string;
@Column({
type: 'varchar',
nullable: true
})
payment_intent_id: string;
@Column({
name: 'last_attempted_date',
type: 'date',
nullable: true,
default: null,
})
last_attempted_date : Date;
@Column({
type: 'varchar',
nullable: true
})
error_response: string;
@CreateDateColumn()
created_at: Date;
@UpdateDateColumn()
updated_at: Date;
}
