Very Slow Performance for a small database and basic queries
I have a Postgres instance setup on Digital Ocean with 1GB of RAM for development purposes. I am writing a REST API on my local development machine (Windows 10) and connect to the remote database so that my entire team can access the same data. However the performance is pathetic and basic queries like 'SELECT * FROM table' takes over 30 seconds and sometimes does not even execute. However when I run queries through PgAdmin 4 from my development machine it does not seem to have this problem.
My project structure is based on the recommended structure mentioned with a central db file as follows:
`const pg = require('pg') const { Pool } = pg
const pool = new Pool({ ...global.config.postgres })
console.log('Postgres setup complete')
module.exports = { query: async (text, params) => await pool.query(text, params), getClient: async () => { return await pool.connect() } }`
Sometimes the queries start working pretty quick but then again go back to executing late/not executing. Here is my configuration file:
postgres: {
user: "postgres",
host: "167.xx.xx.207",
database: "xyz",
password: "password",
port: 5432,
},
All my queries are independent and do not require transactions and hence I use the pool to send queries. What is the reason for this?
I'm gonna need a lot more info here about your setup and self-contained steps to reprodce. PG is used in a lot of software & while I have some plans within the next few months to make it significantly faster, it is by no means pathetically slow.
It's almost certainly a problem w/ your configuration, application code, or network - particularly since sometimes queries don't execute, etc. Are you sure you're releasing clients when you're done using them? A full stall can indicate the pool is leaking client.s
check out the "check out, use, and return" section of the docs i'm guessing that's what's causing you issues!