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

Michael88's avatar

Michael88 wrote a reply+100 XP

1w ago

Connect to postgres cluster

When automatic failover swithces traffic from primary to replica I need connection in laravel to switch as well

Michael88's avatar

Michael88 wrote a reply+100 XP

1w ago

Connect to postgres cluster

So shoud it be like this?

'options' => [
	'target_session_attrs' => 'read',
],
Michael88's avatar

Michael88 wrote a reply+100 XP

1w ago

Connect to postgres cluster

Hello @jussimannisto thank you so much for your reply

It fails in the moment of automatic failover

Michael88's avatar

Michael88 started a new conversation+100 XP

2w ago

Connect to postgres cluster

Hello Could anyone please help me with pgsql cluster issue

I used this config

'pgsql' => [
        'driver' => 'pgsql',
        'host' => [
            env('DB_HOST_1', '10.0.0.1'),
            env('DB_HOST_2', '10.0.0.2'),
        ],
        'port' => env('DB_PORT', '5432'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'options' => [
            'target_session_attrs' => 'read-write',
        ],
        'read' => [
            'host' => [
                env('DB_HOST_1', '10.0.0.1'),
                env('DB_HOST_2', '10.0.0.2'),
            ],
        ],
        'write' => [
            'host' => env('DB_HOST_MASTER_WRITE', '10.0.0.1'),
        ],
        'sticky' => true,
        'charset' => 'utf8',
        'prefix' => '',
        'schema' => 'public',
        'sslmode' => 'prefer',
    ]

But as soon as master switches to replica it fails What can I do here?

Thank you so much in advance