sp-sathish
sp-sathish

Reputation: 51

Failed to connect to the database error: invalid page in block 22 of relation base/12971/2674

I am trying to run in-memory Postgres using pgmock, the connection is getting established but getting this error while running any query.

Failed to connect to the database error: invalid page in block 22 of relation base/12971/2674

code for your reference:

const { Client } = require('pg');
const { PostgresMock } = require('pgmock');
const client = new Client({
    user: "postgres",
    host: "localhost",
    database: "postgres",
    password: "pgmock",
    port: "5432",
});
async function connectToDatabase() {
    try {
        const mock = await PostgresMock.create();
        const connectionString = await mock.listen(5432);
        console.log("connectionString" + connectionString);
        await client.connect();
        console.debug("Connected to the postgres database named: " + "postgres");
        await client.query(`CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
)`);
        console.log("Table created successfully");
    } catch (err) {
        console.error("Failed to connect to the database", err);
        throw err;
    }}
connectToDatabase();

I have tried to refer to the documentation but there is not much detail.

Upvotes: 0

Views: 41

Answers (0)

Related Questions