doctrine:database:create command bug with sharding #5690

Closed
opened 2026-01-22 15:14:36 +01:00 by admin · 1 comment
Owner

Originally created by @gibgibik on GitHub (Sep 5, 2017).

I have two shards. In my tests, I create databases with follow commands:

doctrine:database:create --if-not-exists --shard=1
doctrine:database:create --if-not-exists --shard=2

It looks like this command ignores shard option. It throws the following exception:

An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused 	Is the server running on host "localhost" (127.0.0.1) and accepting 	TCP/IP connections on port 5432? could not connect to server: Address not available Is the server running on host "localhost" (::1) and accepting 	TCP/IP connections on port 5432?

Here is my doctrine config:

doctrine:
    dbal:
        mapping_types:
            _subscribe_type: string
            enum: string
            bit: integer
        shard_choser: "AppBundle\\Service\\CustomShardChooser"
        charset:  UTF8
        logging: false
        profiling: false
        server_version: "9.5"
        driver:   "%database_driver%"
        shards:
          master1:
              id: 1
              dbname: "%database_name1%"
              host: "%database_host1%"
              port: "%database_port1%"
              user: "%database_user1%"
              password: "%database_password1%"
          master2:
              id: 2
              dbname: "%database_name2%"
              host: "%database_host2%"
              port: "%database_port2%"
              user: "%database_user2%"
              password: "%database_password2%"
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
#        metadata_cache_driver: apcu
#        result_cache_driver: apcu
#        query_cache_driver: apcu

Another command (doctrine:migrations:migrate --shard=1) works correctly. I resolve this problem temporary, by copying CreateDatabaseDoctrineCommand and changing following lines:

$tmpConnection = DriverManager::getConnection($params);
$tmpConnection->connect($input->getOption('shard'));
Originally created by @gibgibik on GitHub (Sep 5, 2017). I have two shards. In my tests, I create databases with follow commands: ``` doctrine:database:create --if-not-exists --shard=1 doctrine:database:create --if-not-exists --shard=2 ``` It looks like this command ignores shard option. It throws the following exception: ``` An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? could not connect to server: Address not available Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? ``` Here is my doctrine config: ``` doctrine: dbal: mapping_types: _subscribe_type: string enum: string bit: integer shard_choser: "AppBundle\\Service\\CustomShardChooser" charset: UTF8 logging: false profiling: false server_version: "9.5" driver: "%database_driver%" shards: master1: id: 1 dbname: "%database_name1%" host: "%database_host1%" port: "%database_port1%" user: "%database_user1%" password: "%database_password1%" master2: id: 2 dbname: "%database_name2%" host: "%database_host2%" port: "%database_port2%" user: "%database_user2%" password: "%database_password2%" orm: auto_generate_proxy_classes: "%kernel.debug%" naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true # metadata_cache_driver: apcu # result_cache_driver: apcu # query_cache_driver: apcu ``` Another command (doctrine:migrations:migrate --shard=1) works correctly. I resolve this problem temporary, by copying CreateDatabaseDoctrineCommand and changing following lines: ``` $tmpConnection = DriverManager::getConnection($params); $tmpConnection->connect($input->getOption('shard')); ```
admin closed this issue 2026-01-22 15:14:36 +01:00
Author
Owner

@beberlei commented on GitHub (Sep 16, 2017):

Fixed in 1aa2acd933

@beberlei commented on GitHub (Sep 16, 2017): Fixed in https://github.com/doctrine/DoctrineBundle/commit/1aa2acd933720be3cf62e8c5b61497d22a8a2201
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5690