Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Michael88's avatar

Support postgresql multiple hosts

Hello, I need to support this postgresql feature in laravel https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS but not sure if it is possible out of the box. Maybe someone could help? I would really appreciate it thanks!

0 likes
2 replies
Jsanwo64's avatar
Level 11

Sure, PostgreSQL's multiple hosts connection string format is supported in Laravel via the url or host configuration option in your config/database.php file when using the pgsql driver.

Postgres Format

host=host1,host2,host3 port=5432 user=foo password=bar dbname=mydb target_session_attrs=read-write

Laravel Support via DATABASE_URL

DATABASE_URL="pgsql://user:password@host1,host2,host3:5432/dbname?target_session_attrs=read-write"

Or via config/database.php

'pgsql' => [
    'driver' => 'pgsql',
    'url' => env('DATABASE_URL'),
    'host' => env('DB_HOST', 'host1,host2,host3'),
    'port' => env('DB_PORT', '5432'),
    'database' => env('DB_DATABASE', 'your_database'),
    'username' => env('DB_USERNAME', 'your_username'),
    'password' => env('DB_PASSWORD', 'your_password'),
    'options' => [
        'target_session_attrs' => 'read-write',
    ],
],
1 like

Please or to participate in this conversation.