Connect to external db from Listener

I have setup a doctrine dbal connection in my config.yml.

it lets me access a remote db using this in my controller:

        /** @var Connection $pgsql */
        $pgsql = $this->getDoctrine()->getConnection('pgsql');

But this doesn’t work inside a listener. How do I connect to my remote db from inside my listener. I found and tried

        $container = \Pimcore::getContainer();
        $db = \Pimcore::getContainer()->get('doctrine.dbal.pgsql_connection');

but it does not work. It shows ‘doctrine.dbal.pgsql_connection’ as a missing service.

Thank you

Ok, i got it to work. I used

        $container = \Pimcore::getContainer();
        $doc = $container->get('doctrine');
        $pgsql = $doc->getConnection('pgsql');

Question: getContainer is marked as @internal. Is there a better way to make this work?