'Export connections in pgadmin4

How can I export connections in pgadmin4?

I intend to us pgadmin in docker and I want to map the servers.json as suggested. So I thought to simply export my connections in a local pgadmin4 and map them.

I found an explanation to export servers. Unfortunately this does not work. I tried ubuntu 18.04 LTS and Windows 10 Pro but I always end up with error messages. Here is the message I retrieve in ubuntu:

$ python3 /usr/share/pgadmin4/web/setup.py --dump-servers output_file.json
Traceback (most recent call last):
  File "/usr/share/pgadmin4/web/setup.py", line 406, in <module>
    dump_servers(args)
  File "/usr/share/pgadmin4/web/setup.py", line 63, in dump_servers
    app = create_app()
  File "/usr/share/pgadmin4/web/pgadmin/__init__.py", line 229, in create_app
    create_app_data_directory(config)
  File "/usr/share/pgadmin4/web/pgadmin/setup/data_directory.py", line 29, in create_app_data_directory
    _create_directory_if_not_exists(config.SESSION_DB_PATH)
  File "/usr/share/pgadmin4/web/pgadmin/setup/data_directory.py", line 15, in _create_directory_if_not_exists
    os.mkdir(_path)
FileNotFoundError: [Errno 2] No such file or directory: '/var/cache/pgadmin/sessions'

This seems logical, since there is no such file. But how can I export my server settings and share them via servers.json?



Solution 1:[1]

JSON format is specified in pgAdmin docs here.

I have pgAdmin running in docker container so following steps helped me to obtain correct server list in JSON format from it. But first I started image with pgAdmin and created all connections via pgAdmin GUI normally.

To export servers.json from docker image.

  1. Get running container id with command:

docker ps

  1. Generate servers.json file with needed servers. As I have not used default user then I needed to specify user too like docker exec -it 3a1adbf57bd9 /venv/bin/python setup.py --dump-servers /tmp/servers.json --user admin.

docker exec -it <container id> /venv/bin/python setup.py --dump-servers /tmp/servers.json

  1. Copy generated file to local disk:

docker cp <container id>:/tmp/servers.json c:\myFolder

Solution 2:[2]

You need to map the path for the output_file.json file to your,

For example, To preload the server pre-loaded from /tmp/servers.json on the host:

docker pull dpage/pgadmin4
docker run -p 443:443 \
    -v "/private/var/lib/pgadmin:/var/lib/pgadmin" \
    -v "/tmp/servers.json:/servers.json" \
    -e "[email protected]" \
    -e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" \
    -d dpage/pgadmin4

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 adrock20
Solution 2 Murtuza Z