Skip to content

Commit 1966175

Browse files
Merge pull request #1700 from guilherme-aguilar/guilheme_aguilar/develop
feat(database): add pgbouncer support and optimize postgres config
2 parents 6da71f5 + e92961e commit 1966175

File tree

7 files changed

+810
-14
lines changed

7 files changed

+810
-14
lines changed

.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ EVENT_EMITTER_MAX_LISTENERS=50
2727
# If you don't even want an expiration, enter the value false
2828
DEL_INSTANCE=false
2929

30-
# Provider: postgresql | mysql
30+
# Provider: postgresql | mysql | psql_bouncer
3131
DATABASE_PROVIDER=postgresql
32-
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:5432/evolution?schema=public'
32+
DATABASE_CONNECTION_URI='postgresql://user:pass@postgres:5432/evolution_db?schema=evolution_api'
3333
# Client name for the database connection
3434
# It is used to separate an API installation from another that uses the same database.
3535
DATABASE_CONNECTION_CLIENT_NAME=evolution_exchange
3636

37+
# Bouncer connection: used only when the database provider is set to 'psql_bouncer'.
38+
# Defines the PostgreSQL URL with pgbouncer enabled (pgbouncer=true).
39+
# DATABASE_BOUNCER_CONNECTION_URI=postgresql://user:pass@pgbouncer:5432/evolution_db?pgbouncer=true&schema=evolution_api
40+
3741
# Choose the data you want to save in the application's database
3842
DATABASE_SAVE_DATA_INSTANCE=true
3943
DATABASE_SAVE_DATA_NEW_MESSAGE=true

Docker/scripts/deploy_database.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
66
export_env_vars
77
fi
88

9-
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
9+
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
1010
export DATABASE_URL
1111
echo "Deploying migrations for $DATABASE_PROVIDER"
1212
echo "Database URL: $DATABASE_URL"

Docker/scripts/generate_database.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [ "$DOCKER_ENV" != "true" ]; then
66
export_env_vars
77
fi
88

9-
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]; then
9+
if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" || "$DATABASE_PROVIDER" == "psql_bouncer" ]]; then
1010
export DATABASE_URL
1111
echo "Generating database for $DATABASE_PROVIDER"
1212
echo "Database URL: $DATABASE_URL"
@@ -20,4 +20,4 @@ if [[ "$DATABASE_PROVIDER" == "postgresql" || "$DATABASE_PROVIDER" == "mysql" ]]
2020
else
2121
echo "Error: Database provider $DATABASE_PROVIDER invalid."
2222
exit 1
23-
fi
23+
fi

docker-compose.yaml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
services:
2+
23
api:
34
container_name: evolution_api
45
image: evoapicloud/evolution-api:latest
@@ -34,19 +35,41 @@ services:
3435
image: postgres:15
3536
networks:
3637
- evolution-net
37-
command: ["postgres", "-c", "max_connections=1000", "-c", "listen_addresses=*"]
38+
command: [
39+
"postgres",
40+
"-c", "max_connections=200",
41+
"-c", "listen_addresses=*",
42+
"-c", "shared_buffers=256MB",
43+
"-c", "effective_cache_size=1GB",
44+
"-c", "work_mem=4MB"
45+
]
3846
restart: always
3947
ports:
4048
- 5432:5432
4149
environment:
4250
- POSTGRES_USER=user
4351
- POSTGRES_PASSWORD=pass
44-
- POSTGRES_DB=evolution
52+
- POSTGRES_DB=evolution_db
4553
- POSTGRES_HOST_AUTH_METHOD=trust
4654
volumes:
47-
- postgres_data:/var/lib/postgresql/data
48-
expose:
49-
- 5432
55+
- postgres_data:/var/lib/postgresql/data
56+
57+
# pgbouncer:
58+
# image: edoburu/pgbouncer:latest
59+
# environment:
60+
# DB_HOST: postgres
61+
# DB_USER: user
62+
# DB_PASSWORD: pass
63+
# POOL_MODE: transaction
64+
# AUTH_TYPE: trust
65+
# MAX_CLIENT_CONN: 1000
66+
# DEFAULT_POOL_SIZE: 25
67+
# depends_on:
68+
# - postgres
69+
# ports:
70+
# - "6543:5432"
71+
# networks:
72+
# - evolution-net
5073

5174
volumes:
5275
evolution_instances:

prisma/postgresql-schema.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ model TypebotSetting {
376376
debounceTime Int? @db.Integer
377377
typebotIdFallback String? @db.VarChar(100)
378378
ignoreJids Json?
379-
splitMessages Boolean? @default(false) @db.Boolean
380-
timePerChar Int? @default(50) @db.Integer
379+
splitMessages Boolean? @default(false) @db.Boolean
380+
timePerChar Int? @default(50) @db.Integer
381381
createdAt DateTime? @default(now()) @db.Timestamp
382382
updatedAt DateTime @updatedAt @db.Timestamp
383383
Fallback Typebot? @relation(fields: [typebotIdFallback], references: [id])
@@ -748,4 +748,4 @@ model EvoaiSetting {
748748
evoaiIdFallback String? @db.VarChar(100)
749749
Instance Instance @relation(fields: [instanceId], references: [id], onDelete: Cascade)
750750
instanceId String @unique
751-
}
751+
}

0 commit comments

Comments
 (0)