Last active
September 22, 2023 19:14
-
-
Save maksimr/05202e307406a2f3685da63d04c656bc to your computer and use it in GitHub Desktop.
typeorm postgres settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typeorm from 'typeorm'; | |
async function main() { | |
const dataSource = new typeorm.DataSource({ | |
type: 'postgres', | |
host: '127.0.0.1', | |
username: 'username', | |
password: 'password', | |
database: 'test', | |
extra: /**@type {import('pg').PoolConfig}*/({ | |
max: 50, | |
allowExitOnIdle: true, | |
statement_timeout: 60000, // Максимальное время выполнения запроса в миллисекундах | |
lock_timeout: 10000, // Максимальное время ожидания блокировки в миллисекундах | |
idle_in_transaction_session_timeout: 60000, // Максимальное время жизни транзакции в миллисекундах | |
idleTimeoutMillis: 5000, // Максимальное время жизни не используемого соединения | |
maxLifetimeSeconds: 60000 // Максимальное время жизни соединения | |
}) | |
}); | |
await dataSource.initialize(); | |
await Promise.all([ | |
sleep(1), | |
sleep(1), | |
sleep(1) | |
]); | |
async function sleep(sleep = 1) { | |
try { | |
await dataSource.manager.query('SELECT pg_sleep($1);', [sleep]); | |
console.log('Ok!'); | |
} catch (error) { | |
console.log('Failed!', sleep); | |
} | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment